Results 1 to 2 of 2

Thread: Change texture on an object

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    2

    Change texture on an object

    Hi,
    I'm new to OPenGL ES. I have Omap platform and GFX SDK/DDK from imagination technology which is running OK on my HW. Now I want to write a simple program which basically just display different picture on the screen when left/right arrow keys are pressed. I have preloaded the pictures to an array of texName (say photoTex[]). I used following code to map the texture to two triangles which form a rectangule (I had to use two triangles, for the SDK/DDK does not support GL_POLYGON, etc). The problem is that when the next picture is displayed, I still can see the previous pictures (looks like overlap). Can somebody help me? Is there any better way to display pictures?

    Thanks a lot.

    ==================== Code =============================

    /* Check if left/right arrow key being pressed, if yes, update m_photoIdx and set m_Nextphoto to true */
    ....

    /* if picture not changed, then just return without doing anything */
    if(!m_Nextphoto )
    return true;
    /* Now display the new picture */
    glDisable(GL_DEPTH_TEST);

    /* Disable Blending*/
    glDisable(GL_BLEND);


    glBindTexture(GL_TEXTURE_2D, photoTex[m_photoIdx]);
    m_Nextphoto = false;

    /* Lower right triangle */
    {
    VERTTYPE afVertices[] = {f2vt(-1.0f),f2vt(-1.0f),f2vt(0.0f), f2vt(1.0f), f2vt(-1.0f),f2vt(0.0f), f2vt(1.0f), f2vt(1.0f),f2vt(0.0f)};
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3,VERTTYPEENUM,0,afVertices);

    // Pass the texture coordinates data
    VERTTYPE afTexCoord[] = {f2vt(0.0f),f2vt(0.0f), f2vt(1.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f)};
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2,VERTTYPEENUM,0,afTexCoord);

    // Draws a non-indexed triangle array
    glDrawArrays(GL_TRIANGLES, 0, 3);
    }

    /* upper left triangle */
    {
    VERTTYPE afVertices[] = {f2vt(-1.0f),f2vt(-1.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f),f2vt(0.0f), f2vt(-1.0f),f2vt(1.0f),f2vt(0.0f)};
    VERTTYPE afTexCoord[] = {f2vt(0.0f),f2vt(0.0f), f2vt(1.0f),f2vt(1.0f), f2vt(0.0f),f2vt(1.0f)};

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3,VERTTYPEENUM,0,afVertices);

    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2,VERTTYPEENUM,0,afTexCoord);

    // Draws a non-indexed triangle array
    glDrawArrays(GL_TRIANGLES, 0, 3);
    }

  2. #2
    Junior Member
    Join Date
    May 2009
    Posts
    2

    Re: Change texture on an object

    OK, I figured it out. The problem was caused by
    if(!m_Nextphoto )
    return true;

    For every frame, you have to render some data I think. So if no change for this frame, I just render same texture. Then the problem was gone.

Similar Threads

  1. empty texture object
    By sajis997 in forum OpenCL
    Replies: 1
    Last Post: 03-12-2013, 01:47 AM
  2. how to change coordinates
    By smartmobili in forum OpenVG and VGU
    Replies: 3
    Last Post: 11-03-2009, 04:32 PM

Posting Permissions

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