basic multitexturing problem

Hi,

I’m experiencing troubles when trying to bind a texture unit… this is very basic code :frowning:
This works IF I leave glActiveTexture(GL_TEXTURE1_ARB) before glActiveTexture(GL_TEXTURE0_ARB) ; black screen if I don’t.


        glActiveTexture(GL_TEXTURE1_ARB);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, depth_tex);

        glActiveTexture(GL_TEXTURE0_ARB);
        glBindTexture(GL_TEXTURE_2D, depth_tex);
        glEnable(GL_TEXTURE_2D);

this produces a black screen :


        glActiveTexture(GL_TEXTURE1_ARB);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, color_tex);

        glActiveTexture(GL_TEXTURE0_ARB);
        glBindTexture(GL_TEXTURE_2D, depth_tex);
        glEnable(GL_TEXTURE_2D);

So I thought this was a problem during the initialisation of color_tex ( which is, btw, rendered to in a previous pass ), but I can’t see anything wrong ( maybe the internal format, but it doesn’t changes anything ) :


    glBindTexture (GL_TEXTURE_2D, color_tex);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D( GL_TEXTURE_2D,0,GL_RGBA,512,512,0,GL_RGBA,GL_FLOAT,0 );

I don’t know if it changes anything, but I’m rendering a VBO without any texture coordinates into a FBO ( this is also the way I rendered color_tex & depth_tex )

Does anyone see something I’m doing wrong ?

Thanks !

AFAIK, you can’t bind the same texture (depth_tex) to two texture units (0 and 1) at the same time.

Well, it seems that I can … the example you quoted works … it doesn’t work only if I select another texture in GL_TEXTURE1_ARB …

Never had any problems binding the same texture to multiple texture units.

What function are you using to combine the textures?
Are you using a fragment shader? Are you using texture combiners?
Straight multitexturing?
Keep in mind that straight multitexturing multiplies the color components. Depending on the contents of your “depth texture”, when multiplied with the color texture, the results may well be black or almost black.

Also, I noticed that the order in which you call the glEnable and the glBindTexture differs between the two texture units. I don’t know by heart if that should make a difference. You might want to look it up in the manual just in case.

Still doesn’t work …

Here is how I create the textures :


    glBindTexture (GL_TEXTURE_2D, color_tex[i]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D( GL_TEXTURE_2D,0,GL_RGB8,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,0 );

    glBindTexture (GL_TEXTURE_2D, depth_tex[i]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D( GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT32F_NV/*24_ARB*/,512,512,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL);

// targets binding
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer[i]);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, color_tex[i], 0);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D, depth_tex[i], 0);

This is my main loop :


        glActiveTextureARB(GL_TEXTURE0_ARB);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, depth_tex[0] );

/*
        glActiveTextureARB(GL_TEXTURE1_ARB);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, color_tex[0] );
*/

        Shader->ON();

        PeelShader->Set1i(PeelShader->Get("z_tex"), 0  );
        PeelShader->Set1i(PeelShader->Get("color_tex"), 1  );

        Render();

        Shader->OFF();

This works, but I obviously can’t use the texture unit 1 since it is commented. So here is a simplified version of my shader :


uniform sampler2D z_tex;
uniform sampler2D color_tex;

void main(void){

	vec2 UVs = vec2(gl_FragCoord.x/512.0, gl_FragCoord.y/512.0);

	float frontDepth = texture2D(z_tex, UVs ).r;
	float red  = texture2D(color_tex, UVs).x;

	gl_FragColor = vec4(1.0,0.0,0.0,1.0) ;
}

… and I really can’t say what is wrong.
z_tex and color_tex are rendered to in a previous pass ( and it seems to work )
The geometry is in a VBO
… and, well, that’s it…

Does anyone see what’s wrong ? I’ve been on this code for days now.

Thanks

found it >_<

Everything was working properly … everything but the final render of the dest FBO …
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
corrected it.

Shame on me :’(

http://www.opengl.org/wiki/index.php/GLSL_:_common_mistakes#Enable_Or_Not_To_Enable