PDA

View Full Version : multitexturing



10-23-2002, 12:11 PM
(I posted this is the linux section, but that forum looks rather dead.)

I am trying to use an indexed array to draw a multitextured scene as follows:
------------------------
// load vertices
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer (2, GL_FLOAT, v_stride, pVertices);

// load normals
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, n_stride, pNormals);

// set unit 0
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, t_stride0, pTexCoords0);
glBindTexture(GL_TEXTURE_2D, base_texture);

// set unit 1
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, t_stride1, pTexCoords0);
glBindTexture(GL_TEXTURE_2D, lightmap);

// draw it.
glDrawElements(GL_TRIANGLES, numIndexes, GL_UNSIGNED_SHORT, pIndexes);
----------------------

The problem is that the texture coordinates intended for unit 1 are actually overwriting the ones intended for unit 0, and unit 1 coordinates are never initilized. So it looks like glTexCoordPointer() is stuck on unit 0. How do I tell glTexCoordPointer that the data is intended for a texture unit other than 0?

(I've looked at a number of tutorials and examples, and I can't see anything wrong with the above code, which makes me start wondering if the NVidia opengl on linux has a bug.)

Bob
10-23-2002, 01:18 PM
I don't see anything related to vertex arrays, but I do see something related to multitexturing.



// set unit 0
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, t_stride0, pTexCoords0);
glBindTexture(GL_TEXTURE_2D, base_texture);

// set unit 1
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, t_stride1, pTexCoords0);
glBindTexture(GL_TEXTURE_2D, lightmap);

You set active texture on the client side, which is what you need to do for vertex arrays. But then you bind a texture, and the texture is bound to the active texture unit on the server side, which may have a different active texture unit than the client side. Make sure the correct texture unit is active on the server side also.

In the next part, you bind another texture, but you haven't changed active texture unit, effectively "overwriting" the previously bound texture.

10-23-2002, 02:42 PM
Leaving the glActiveTexture calls out of my sample code was a typo. I call glActiveTexture() just before each of the glClientActiveTexture in the actual code.