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.glTexCoordPointer(2, Gl.GL_DOUBLE, 0, textCor);
Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, vertex);


// Gl.glDisableClientState(Gl.GL_COLOR_ARRAY);


------------------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.

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…

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.

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. :slight_smile:

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