• Advertisement
Sign in to follow this  

GLSL multitexturing problems *Fixed*

This topic is 3700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reason, only the first texture unit is referenced by my samplers. For setting the samplers, I do this after having created, compiled, and linked the shader program:
int unit0Loc, unit1Loc;
unit0Loc = glGetUniformLocationARB(program, "unit0");
unit1Loc = glGetUniformLocationARB(program, "unit1");

glUniform1iARB(unit0Loc, 0);
glUniform1iARB(unit1Loc, 1);

For specifying the textures for each unit in the program, I use this:
int maxUnits = TextureManager::getMaxTextureUnits();

for(register int i=0; i<maxUnits; ++i) {
	glActiveTextureARB(GL_TEXTURE0_ARB + i);
	glBindTexture(GL_TEXTURE_2D, textures);
	printf("Texture '%i' bound to unit '%i'\n", textures, i);

For drawing the primitive I use this:
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0);	glVertex2f(-1, -1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 0);	glVertex2f(1, -1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 1);	glVertex2f(1, 1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 1);	glVertex2f(-1, 1);

And, finally, in the vertex shader I use:
void main(void)
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = gl_MultiTexCoord1;
	gl_Position = ftransform();

And in the fragment shader:
uniform sampler2D unit0, unit1;

void main(void)
	gl_FragColor = texture2D(unit0, gl_TexCoord[0].st) * texture2D(unit1, gl_TexCoord[1].st);

[Edited by - biggoron on February 2, 2008 4:15:26 PM]

Share this post

Link to post
Share on other sites
u only need to use different texture unit coordinates if theyre different,
thus remove
the glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0); etc
+ also remove gl_TexCoord[1] = gl_MultiTexCoord1;

+ use texture2D(unit1, gl_TexCoord[0].st) instead of texture2D(unit1, gl_TexCoord[1].st)

though what u have should work

gl_FragColor = texture2D(unit0, gl_TexCoord[0].st);
+ does
gl_FragColor = texture2D(unit1, gl_TexCoord[0].st)

if so then
gl_FragColor = texture2D(unit0, gl_TexCoord[0].st) * gl_FragColor = texture2D(unit1, gl_TexCoord[0].st)
should work

Share this post

Link to post
Share on other sites
u only need to use different texture unit coordinates if theyre different

I know, it's for testing.

Both unit0 and unit1 refer to the same texture. texture2D(unit0, xy) = texture2D(unit1, xy). It's as if I'm not setting the samplers, although I am. I'm setting them after the linking but before the binding. I assumed it wouldn't matter whether it was bound or not, but I will try it.

What do you know, that fixed it! I don't recall the 3DLabs ARB extensions docs or the GL 2.0 docs mentioning anything about the shader being used before setting variables. Perhaps an implementation thing? I'm using a HD 2600 XT card with Catalyst 8.1.

Either way, it's solved. Thanks.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement