Sign in to follow this  
DarkCybo1

ARB Multitexturing problems..

Recommended Posts

A little problem. I cant use two different textures on a primitive, only one appears. http://img519.imageshack.us/img519/9118/multiproblem0tq.jpg
void drawCube()
{
 
   glActiveTextureARB(GL_TEXTURE0_ARB);
   glBindTexture(GL_TEXTURE_2D, tex[0]);
 
   glActiveTextureARB(GL_TEXTURE1_ARB);
   glBindTexture(GL_TEXTURE_2D, tex[1]);
 
   glRotatef(fRot, 0.0f, 1.0f, 0.0f);
 
   glBegin(GL_QUADS);
 
      glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0); glVertex3f(-.5f, 0.5f, 5.0f);
      glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 0); glVertex3f(.5f, 0.5f, 5.0f);
      glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 1); glVertex3f(.5f, -0.5f, 5.0f);
      glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 1); glVertex3f(-.5f, -0.5f, 5.0f);
 
      glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0); glVertex3f(.5f, 0.5f, 5.0f);
      glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1); glVertex3f(.5f, 0.5f, -5.0f);
      glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1); glVertex3f(.5f, -0.5f, -5.0f);
      glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0); glVertex3f(.5f, -0.5f, 5.0f);
 
   glEnd();
 
}

And yes, I do have multi-texturing on my videocard.

Share this post


Link to post
Share on other sites
Why are you supplying one set of texture coordinates only when you use two textures? For the first quad, you don't specify texture coordinates for the first texture unit, only the second. That means the first texture quad will get the same texture coordinates for each vertex for the first texture unit, which is the last used texture coordinate.

Same for second quad, but now the second unit gets the same set of coordinates for each vertex instead.

It also looks like you haven't enabled the second texture unit, since there's no trace of that texture in the rendered image at all. Also check the texture combiners to make sure the two textures are combined correctly.

Share this post


Link to post
Share on other sites
I agree. That's not the way multitexturing works.

The calls to glMultiTexCoord2fARB only specify texture coordinates for _that_ individual texture unit. You will need to enable (at the very least) the second unit using glEnable(GL_TEXTURE1_ARB), and then setup the texture combiner to blend the textures properly for you.

Share this post


Link to post
Share on other sites
Alright. It seems to be working properly now..

void drawCube()
{

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, tex[0]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);
glEnable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, tex[1]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);
glEnable(GL_TEXTURE_2D);

glRotatef(fRot, 0.0f, 1.0f, 0.0f);

glBegin(GL_QUADS);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
glVertex3f(-.5f, 0.5f, 5.0f);

glVertex3f(.5f, 0.5f, 5.0f);
glVertex3f(.5f, -0.5f, 5.0f);
glVertex3f(-.5f, -0.5f, 5.0f);

glVertex3f(.5f, 0.5f, 5.0f);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
glVertex3f(.5f, 0.5f, -5.0f);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
glVertex3f(.5f, -0.5f, -5.0f);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
glVertex3f(.5f, -0.5f, 5.0f);

glEnd();

}


One thing. What would I need to do to have one of the textures appear more visibly then the other?

http://img296.imageshack.us/img296/1771/multitexture0rk.jpg

Share this post


Link to post
Share on other sites
You can use alpha to control the amount of texture blending, through the constant or primary color setting. (See the GL_ARB_texture_env_combine spec.)

However, you are pretty limited in what you can do. Pixel (er, fragment) shaders will give you a lot more flexibility in controlling the way textures are blended.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this