PDA

View Full Version : Multitexturing and vertex arrays



Ganymede
08-15-2002, 09:33 AM
I'm trying to implement a multitexture over my terrain. I have the terrain vertices stored in an array representing its triangles. How do you specifiy two texture pointers for use with glDrawElements so the second one is blended with the first? I have this code so far, but the second texture seems as if it doesn't reference the pointer. Instead of my grass detail texture over the first one, only a smooth green color shows up. Its as if the entire texture coordinate array is [0, 0]. The first texture is rendering correctly. Anyone have any ideas on why this is happening?

glVertexPointer(3, GL_FLOAT, 0, @pNode.Terrain);

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, @pNode.TexCoordArray);

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, @pNode.TexCoordArray);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, mtex2);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2);

glMatrixMode(GL_TEXTURE);
glLoadIdentity;
glScalef(0.01, 0.01, 1);
glMatrixMode(GL_MODELVIEW);

glNormalPointer(GL_FLOAT, 0, @pNode.NormalArray);

glActiveTextureARB (GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mtex);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glActiveTextureARB (GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, mtex2);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glLockArraysEXT(0, pNode.TriangleCount*3);
glDrawElements(GL_TRIANGLES, pNode.TriangleCount*3, GL_UNSIGNED_INT, @pNode.g_IndexArray[0]);
glUnlockArraysEXT;


[This message has been edited by Ganymede (edited 08-15-2002).]

bakery2k
08-15-2002, 09:58 AM
Are you calling glEnableClientState(GL_TEXTURE_COORD_ARRAY) for BOTH units?

i.e.
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

Ganymede
08-15-2002, 10:07 AM
Yep, that did it! Really silly oversight on my part. Thanks for helping me out.