Jump to content
  • Advertisement
Sign in to follow this  
ic0de

How to multitexture?

This topic is 2570 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!