Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Textures, bitmap and screen

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    21

    Textures, bitmap and screen

    Hi folks,

    i am a newbie with opengl and i need to do the following thing. I have a opengl surface of 320x240. I have a bitmap of 320x240. I need to cover the surface with the bitmap so that when i display it on the screen, the bitmap is completely visible. I cannot use glDrawPixels.

    I know that i have to use two quad. I want to create one texture of 256x256, copy the 256x240 part of the bitmap on it, leaving the last 16 lines blank. Than i want to create a texture of 64x256, copy the other 64x240 part of the bitmap, leaving the last 16 lines blank. Than i want to use those textures to texture two quad that cover the entire surface (to make it faster, i wanto to disable perspective correction).

    I have tried all of this but i cannot show it right (actually, i am using Opengl Es on a mobile device). The application crashes...

    Someone here can help me? Some code/link would be really useful!!! :P

    Thank you,
    Luca

  2. #2
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Textures, bitmap and screen

    you need to setup orthogonal projection (glOrtho) and create textures from a bitmap before rendering the quads. if your card supports non power of two textures or texture rectangles you dont have to split the bitmap. im not familiar with ES though.

    would help to know what is not correct in your app atm.


  3. #3
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    21

    Re: Textures, bitmap and screen

    I don't know, i would like to try someone else code in order. Here it is the code. I have omitted all, i was trying to draw a simple quad but it crashes anyway
    (i have taken this code from another forum, it use only a 256x256 texture, but i tought that was a good starting point)


    //==========================================
    // BACKGROUND PLANE
    static const GLbyte bgverts[8] =
    //static const GLfloat bgverts[8] =
    {
    /*0, 0,
    1.06, 0,//1, 0,
    0, 0.8,//0, 1,
    1.06, 0.8//1, 1
    */
    0, 0,
    1, 0,
    0, 1,
    1, 1
    };

    static const GLubyte bgtex[8] =
    {
    0, 1,
    1, 1,
    0, 0,
    1, 0
    };



    void RenderTexturedBG(TUint8* aCamFrameData)
    {
    GLuint iTexturesID[10];

    /*
    // Textures are initialized in OpenGL ES API by this function.
    glGenTextures( 1, iTexturesID );
    glBindTexture( GL_TEXTURE_2D, iTexturesID[0] );
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 256, 256,
    0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)aCamFrameData );
    //glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 256, 256,
    // 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)aCamFrameData );
    glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);*/

    // Before drawing the background texture, we need to switch to ortho (2D) mode.
    // Passing 1 instead of the implicit size of screen will make OpeGL use the full size of screen (1:1)
    //OrthoMode(0, 1, 0, 1);
    // Switch to our projection matrix so that we can change it to ortho mode, not perspective.
    glMatrixMode(GL_PROJECTION);
    // Push on a new matrix so that we can just pop it off to go back to perspective mode
    glPushMatrix();

    glDisable( GL_DEPTH_TEST );
    glDisable( GL_CULL_FACE );

    // Reset the current matrix to our identify matrix
    glLoadIdentity();
    // Pass in our 2D ortho screen coordinates (left, right, bottom, top, near, far).
    //glOrthof( aLeft, aRight, aBottom, aTop, -1, 1 );
    glOrthof(0, 1, 0, 1, -1, 1);
    //glOrthof(0, 1/0.8, 0, 1/0.53, -1, 1);

    // Switch to model view so that we can render the texture
    glMatrixMode(GL_MODELVIEW);
    // Initialize the current model view matrix with the identity matrix
    glLoadIdentity();
    //glEnable(GL_TEXTURE_2D);


    //DrawBGPoly();
    //glPushMatrix();
    // Enable vertex arrays.
    //glEnableClientState( GL_VERTEX_ARRAY );
    // Set array pointers.
    glVertexPointer( 2, GL_BYTE, 0, bgverts );
    //glVertexPointer( 2, GL_FLOAT, 0, bgverts);
    // Enable texture arrays
    //glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    // Set texture coords
    //glTexCoordPointer( 2, GL_BYTE, 0, bgtex );

    //glBindTexture( GL_TEXTURE_2D, iTexturesID[0] );
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    //glDisable(GL_TEXTURE_2D);
    //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    //glDisableClientState(GL_VERTEX_ARRAY);
    //glPopMatrix();




    //PerspectiveMode();
    // Load our projection matrix
    glMatrixMode( GL_PROJECTION );
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_CULL_FACE );

    // Get rid of ortho mode which was lst pushed in the projection matrix mode
    glPopMatrix();
    // Go back to model view matrix
    glMatrixMode( GL_MODELVIEW );


    //glDeleteTextures(1, iTexturesID);
    }


  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: Textures, bitmap and screen

    Your code is quite unreadable and full of weird things, I mean, many useless things but these one should not make crash you application. Why did you comment many lines? There are useful things especially to use the vertex array that are commented, like enabling vertex array client state...

    Without wanting to offend you, you really need to restructure your code, dividing it in several functions for in initialization, rendering... That would really help you to solve your problem.

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    21

    Re: Textures, bitmap and screen

    Yes i know, that code was an experiment only. Finally i have made it! The problem was not disabling normal coordinates pointer (which was enabled for other things)...
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •