multitexture, second texture doesnt show

Hi,

I have looked at many different posts here, and cannot see what i am doing different. I have tried using each of the two textures as the first texture unit, so I know the textures are loaded fine because they display. But with 2 active textures, it always only shows the first texture.

The images are black with the first image having a red line only the left half, and the second image having a green line only on the right half.

I am just doing a test to see if i can add the 2 images together so that it the final result has a black background with a half red/half green line.

void TestObject::Draw()
{

glDisable(GL_LIGHTING);
glColor4f(0.f,0.f,1.f,0.5f);

glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_poTex0->GetTID());
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);

glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_poTex1->GetTID());

glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);

glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_ADD);

glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_PREVIOUS);

glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB,GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE1);

glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB,GL_SRC_COLOR);

glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0,0.f,0.f);
glMultiTexCoord2f(GL_TEXTURE1,0.f,0.f);
glColor4f(1.f,1.f,1.f,0.5f);
glVertex3f(-50.f,-50.f,0.f);
glMultiTexCoord2f(GL_TEXTURE0,1.f,0.f);
glMultiTexCoord2f(GL_TEXTURE1,1.f,0.f);
glColor4f(1.f,1.f,1.f,0.5f);
glVertex3f(50.f,-50.f,0.f);

	glMultiTexCoord2f(GL_TEXTURE0,1.f,1.f);

glMultiTexCoord2f(GL_TEXTURE1,1.f,1.f);
glColor4f(1.f,1.f,1.f,0.5f);
glVertex3f(50.f,50.f,0.f);

	glMultiTexCoord2f(GL_TEXTURE0,0.f,1.f);

glMultiTexCoord2f(GL_TEXTURE1,0.f,1.f);
glColor4f(1.f,1.f,1.f,0.5f);
glVertex3f(-50.f,50.f,0.f);
glEnd();

glActiveTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);
GLenum err = glGetError();

const GLubyte* mess = gluErrorString(err);
}

Thanks,

jeremy

Your code should work fine if your GL driver supports ARB_texture_env_crossbar. Maybe it doesn’t?
Try replacing GL_TEXTURE1 with just GL_TEXTURE. Like this

glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE1);
=>
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE);

I tried just using GL_TEXTURE as you suggest but it is still the same problem.

I just checked, my gf4mx doesnt support ARB_texture_env_crossbar. I checked on the delphi3d.net hardware site and it seems that no nvidia cards support it!!!

Can i not do what i want without the crossbar extension?

I just tried the following:
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_poTex0->GetTID());
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);

glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_poTex1->GetTID());
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_ADD);

and it did not work either. sigh.

Originally posted by bumby:
I tried just using GL_TEXTURE as you suggest but it is still the same problem.
After this modification it should work on anything with two texture units, even without crossbar support. And it should definitely work on your Geforce 4MX.

There must be some mistake in other parts of the code, probably in your texture class (m_poTex0 and m_poTex1).

Sanity check:

[b]I just checked, my gf4mx doesnt support ARB_texture_env_crossbar. I checked on the delphi3d.net hardware site and it seems that no nvidia cards support it!!!

Can i not do what i want without the crossbar extension?[/b]
First, with the modification I suggested, you don’t need the crossbar extension to do what you want.

Second, and this is going to be confusing, the drivers don’t advertise the crossbar extension, but all NVIDIA cards from Riva TNT and up do support the crossbar functionality.

The reason for this is that NVIDIA started allowing practically the same thing as the crossbar extension, plus a few things more, with NV_texture_env_combine4. However, tec4 and crossbar define different behaviours on error conditions (incomplete mipmap pyramids, which should never happen in finished code). It’s not possible for a driver to advertise both extensions at the same time, but tec4 support automatically implies crossbar support as long as the application isn’t broken.

This issue was fixed when crossbar was promoted to a core feature.

Or in short: don’t worry. Crossbar is supported on your card, even though you don’t see it in the extension string.

Besides, you don’t need crossbar support for your particular problem code anyway.

Glad to hear about the crossbar ext…got a bit panicky there.

I tried the modified code you suggested and it shows the quad colored yellow…as expected.

here is the init function from my texture object…

void Texture::Init()
{
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &m_nTexID);

glBindTexture(GL_TEXTURE_2D, m_nTexID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_nWidth, m_nHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_pData);

}

The only other areas of the code are gl setup and the render func…

setup:
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);

glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
glClearDepth(1.0f);
glPolygonOffset(1,1);

The render func:
makes the rc current,
clears the buffers,
sets the viewport,
sets up the modelview,

and calls the TestObject::Draw func from before.

btw, appreciate the help!

i am so dumb,

I have a section of my app that i was previously using to experiment with arb vertex programs, and i had left the initialization active. In the init, i had:

1.enabled vertex programs with glEnable.
2. bound a vertex program.
3. called program string arb.

damn damn damn.

blew that code away and it works fine.

thanks for your help!

I should add that the reason the vertex program was causing the problem was that the vp didnt support multiple textures, only the base texture unit.

J