How to multitexture?

Started by
2 comments, last by ic0de 12 years, 4 months ago
So i'm trying to layer two textures on top of each other, when I render with one texture here is what I do.

I bind my texture.glBindTexture(GL_TEXTURE_2D, tex[0]);

And I draw my vertex arrays

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);


glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(GL_FLOAT, 0, normals);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);

glDrawArrays(GL_TRIANGLES, 0, numtriangles*3);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);


This works great with one texture.

When I want to do it using two, I think this is what I'm supposed to do:

Bind my textures

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex[0]);
glEnable(GL_TEXTURE_2D);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, tex[1]);
glEnable(GL_TEXTURE_2D);


[color=#1C2837][size=2]

And I draw my vertex arrays



glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glClientActiveTexture(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);


glClientActiveTexture(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(GL_FLOAT, 0, normals);

glDrawArrays(GL_TRIANGLES, 0, numtriangles*3);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);


As far as I know it should work but when I try I only see one texture.

What is wrong?

Advertisement
I'm not 100% on this, but perhaps it has something to do with a lack of this? Just based on what I read on the glTexCoordPointer ref page:
For OpenGL versions 1.3 and greater, or when the ARB_multitexture
extension is supported, glTexCoordPointer updates the
texture coordinate array state of the active client texture unit,
specified with glClientActiveTexture.[/quote]

Having never done multitexturing before I'm just going by what looks right, so you might need to do a little research to confirm it.

Edit: Just reread your post. /facepalm :( I need to slow down and not post when sick and tired.
You also need to set your glTexEnvs for each texture unit according to how you want the textures to be blended together. So it's a glActiveTexture call for the relevant unit, followed by a bunch of glTexEnv calls.

Incidentally, you have a bug in your second code listing: glDisableClientState (GL_TEXTURE_COORD_ARRAY) will only affect the current client active texture, so you'releaving the TexCoordArray enabled for GL_TEXTURE0.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


You also need to set your glTexEnvs for each texture unit according to how you want the textures to be blended together. So it's a glActiveTexture call for the relevant unit, followed by a bunch of glTexEnv calls.

Incidentally, you have a bug in your second code listing: glDisableClientState (GL_TEXTURE_COORD_ARRAY) will only affect the current client active texture, so you'releaving the TexCoordArray enabled for GL_TEXTURE0.


thanks it works now


This topic is closed to new replies.

Advertisement