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: Texture Mapping problem with Vertex Arrays !

  1. #1
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    120

    Texture Mapping problem with Vertex Arrays !

    I would like to know how to do texture mapping with Vertex Arrays? What I did is

    ------------------First Mesh-----------------------
    Gl.glEnable(Gl.GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
    Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
    Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
    Gl.glTexCoordPointer(2, Gl.GL_DOUBLE, 0, textCor);
    Gl.glNormalPointer(Gl.GL_FLOAT,0,pNorList);
    Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, vertex);
    Gl.glDrawArrays(Gl.GL_QUADS,0,bilVert);


    Gl.glDisableClientState(Gl.GL_NORMAL_ARRAY);
    Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
    // Gl.glDisableClientState(Gl.GL_COLOR_ARRAY);

    Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY) ;
    Gl.glDisable(Gl.GL_TEXTURE_2D);

    ------------------Second Mesh-----------------------
    Gl.glBindTexture(Gl.GL_TEXTURE_2D, 1);
    ... (repeat the code above for second Mesh).
    ...
    ...

    What I get is only the last defined texture is able to be showed and no matter how I change the texture id in the Gl.glBindTexture. Both of the Mesh will show the same texture.
    Can someone tell me the correct way to do it. Thanks.

  2. #2
    Advanced Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: Texture Mapping problem with Vertex Arrays !

    glActiveTexture(GL_TEXTURE_x) is probably what you want.
    Where x is the number of the texture unit you have bound the texture to.
    There are 8 - 16 or more of those on most OpenGL implementations.

    But you need to load and setup the textures correctly...
    Are you sure 0 and 1 are valid IDs for textures in glBindTexture()?

    I would say 0 certainly is not. It will give you wierd results at best, but should simply bind to nothing...

    The number should be the ID allocated to the texture when you initially load it and give it to the GPU....

  3. #3
    Intern Newbie
    Join Date
    Jan 2009
    Posts
    41

    Re: Texture Mapping problem with Vertex Arrays !

    Binding texture with 0 is the same as "unbinding" a texture, generally. But binding with 1 is allowed. I guess that the problem comes from the fact that you use a texture id 0 inside vertex arrays, with activating texture pointers and enabling texture client states. Since 0 is not a valid texture id, on the second frame and any other coming after, the texture state uses the last one, which is from the second mesh.
    So as scratt said you should generate your textures properly and bind them with correct valid ids.

    Also I think glActiveTexture is not needed here provided he uses only one texture for all the meshes.

  4. #4
    Advanced Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: Texture Mapping problem with Vertex Arrays !

    I have a (bad?) habit of avoiding using bindings as much as possible... Hence my use of glActiveTexture when on the fixed pipeline. Although I did find out recently that binding is not quite as bad on modern hardware as I thought it was.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    120

    Re: Texture Mapping problem with Vertex Arrays !

    Thanks for pointing out the mistake. You are right, the texture ID is assigned wrongly. I finally get it work. Thanks for the reply.

Posting Permissions

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