ARB Multitexturing problems..

Started by
3 comments, last by Falken42 18 years, 5 months ago
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.
Hey babe.
Advertisement
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.
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.
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
Hey babe.
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.

This topic is closed to new replies.

Advertisement