Sorry, again Multitexturing

I want to make a texture of my current screen, including its depth and the RGBA values.

//////////// my main program

// Render to Texture

glActiveTexture(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, depthToTexture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0);

glActiveTexture(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, RGBAtoTexture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0);


texLoc = glGetUniformLocationARB(p, "dTexture");
glUniform1iARB(texLoc, 0);

texLoc = glGetUniformLocationARB(p, "texture");
glUniform1iARB(texLoc, 1);

// Render Scene

/************************************ depth ****************************************/
glActiveTexture(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, depthToTexture);

// and draw textured quad with our rendered texture
glEnable(GL_TEXTURE_2D);

/************************************ RGBA ****************************************/

glActiveTexture(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, RGBAtoTexture);
	
// and draw textured quad with our rendered texture
glEnable(GL_TEXTURE_2D);

glBegin( GL_QUADS );
//	glColor4fv(orgColor);
	glMultiTexCoord2f (GL_TEXTURE0_ARB, 0, 0);
	glMultiTexCoord2f (GL_TEXTURE1_ARB, 0, 0);
	glVertex2f(0, 0);
	glMultiTexCoord2f (GL_TEXTURE0_ARB, 0, 1);
	glMultiTexCoord2f (GL_TEXTURE1_ARB, 0, 1);
	glVertex2f(0, WIN_HEIGHT);
	glMultiTexCoord2f (GL_TEXTURE0_ARB, 1, 1);
	glMultiTexCoord2f (GL_TEXTURE1_ARB, 1, 1);
	glVertex2f(WIN_WIDTH, WIN_HEIGHT);
	glMultiTexCoord2f (GL_TEXTURE0_ARB, 1, 0);
	glMultiTexCoord2f (GL_TEXTURE1_ARB, 1, 0);
	glVertex2f(WIN_WIDTH, 0);
glEnd();

glDisable(GL_TEXTURE_2D);

//////////////// Vertex Shader

gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;

//////////////// Fragment Shader

gl_FragColor = texture2D(dTexture, gl_TexCoord[0].st); // works

but
gl_FragColor = texture2D(texture, gl_TexCoord[1].st);
works not.


If switch the TEXTUREIndices the other texture works (here the RGBA would work then). Finally, I get only access to TEXTURE0.

I tested different combinations. Nothing will work. What do I wrong?

Thanx

theres no need to specify the same info twice ie glMultiTexCoord2f (GL_TEXTURE0_ARB, 1, 1);
glMultiTexCoord2f (GL_TEXTURE1_ARB, 1, 1);
any texture unit can use any texture coordinates ie GL_TEXTURE7 doesnt have to use GL_TEXTURE7 texture coord

Ok, I have changed that in the main program and the shaders. But there is still the main problem that only the first texture unit (TEXTURE0) is accessable in the fragment shader. Any idea?

What’s the size of your RGBAtoTexture?
What’s the min filter? (mipmap is default!)
You didn’t say what HW you’re running on. It might be that you’re missing non-power-of-two texture support. Try power-of-two client window size or move to texture rectangles.
You shouldn’t need to enable texturing because fragment shaders work on texture image units.

RGBA texture: 512512
depth texture: 512
512
client window: 512*512

So it cannot be a power-of-2 problem. The texture just fits the screen, so you actually don’t see that it’s a texture. It is just for the purpose of multipassing.

The min filter is GL_LINEAR.

HW: NVIDIA GeForce 6800

And finally:
Although I am not really sure about the term texture image units, it also works without enabling. But it still results in the depth texture which is my TEXTURE0, regardless of which sampler I use in the frag shader.

Actually both texures are 5125124*sizeof(unsigned char)

Are you doing

//gl_FragColor = texture2D(dTexture, gl_TexCoord[0].st); // works
gl_FragColor = texture2D(texture, gl_TexCoord[1].st);

or this

gl_FragColor = texture2D(dTexture, gl_TexCoord[0].st); // works
gl_FragColor = texture2D(texture, gl_TexCoord[1].st);

Finally, inspect the assembly code dump for the shaders. Get NVemulate to turn this feature on if you haven’t. If all else fails, make a GLUT sample and upload it somewhere.

I have only one assignment. I just wanted to show both relevant alternatives I have tested.
And I don’t use the gl_TexCoord[1] anymore, because both RGBA and depth have the same coordinates.

So it’s like that:

//gl_FragColor = texture2D(dTexture, gl_TexCoord[0].st); // shows depth
gl_FragColor = texture2D(texture, gl_TexCoord[0].st); // unforunately shows depth, too.

Ok, I will try that with NVemulate.

Thx

Ok. Seems as if there is no problem with the access of the different texture units in the frag shaders. So maybe both ones have the same content.

My Code:

glActiveTexture(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, depthToTexture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0);

glActiveTexture(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, RGBAtoTexture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0);

texLoc = glGetUniformLocationARB(p, "dTexture");
glUniform1iARB(texLoc, 0);

texLoc = glGetUniformLocationARB(p, "cTexture");
glUniform1iARB(texLoc, 1);

Would it be possible that glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0) changes des Buffer and writes the depth into it?

Or do I have to deactivate Texture0 before activating Texture1 or something like this?

Because I cannot find what’s wrong in my program, please have a look at my code:

http://www.informatik.fh-wiesbaden.de/~msiek001/
or
http://www.informatik.fh-wiesbaden.de/~msiek001/EasyShader.zip

thx

OK, two seconds with GLIntercept(http://glintercept.nutty.org) revealed some problems:

  1. TexFunctions.cpp Line 51:
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, WIN_WIDTH, WIN_HEIGHT, 0, GL_DEPTH_COMPONENT24,GL_FLOAT,NULL);

The “format” parameter has to be GL_DEPTH_COMPONENT for depth textures. Read the spec on ARB depth texture.

  1. When you are setting the uniforms on the GLSL program, no GLSL program is bound so these generate GL errors, and the texture values are left at their initial value of 0.

Add a line glUseProgramObjectARB(p); to line 108 of tex_functions.cpp

What he ^^^ said and this:

  • Current shaders won’t work with the RGBA sampler because you use gl_TexCoord[1] but only send glMultiTexCoord2f(GL_TEXTURE0_ARB);
  • Warning, pixelformat GLUT_RGBA does not contain GLUT_ALPHA! If you want a destination alpha you must explicitly request it.
  • glEnable(GL_LIGHTING) is missing.
  • The first luminance texture download is obsolete.

Hooray, it works.
I didn’t know that the program object wasn’t bound, because I do it in the main program. Furthermore there was an error with the texture coordinates caused by all the changes.

Ok, now: downloading of GLIntercept.

Thx all for the help.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.