Jump to content
  • Advertisement
Sign in to follow this  
angry

GLSL and Texture Matrix Problems

This topic is 4438 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

I'm projecting a reflection texture onto a couple quads by changing the texture matrix before I do anything. And this works great if I don't use my fragment shader. But as soon as I start using a fragment shader my texture gets screwed. So what am I doing wrong? The source looks something like this:
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5f, 0.5f, 0.0f);
glScalef(0.5f, 0.5f, 1.0f);
	
glMultMatrixf(camera->projection);
glMultMatrixf(camera->transform.inverse());
glMatrixMode(GL_MODELVIEW);

//... render tristrip 32x32 grid quads and set texcoords to 
// glTexCoord3f(x, 0.0f, z), where the x and z are the same 
// as the tristrip quad coordinates..
for( int z=0; z<1024; z+=32 ) {
  if( !rewind ) {
    for( int x=0; x<=1024; x+=32 ) {
      glTexCoord3f(x, 0.0f, z      ); glVertex3f(x, 0.0f, z);
      glTexCoord3f(x, 0.0f, z+32.0f); glVertex3f(x, 0.0f, z+32.0f);
    }
  } else {
    //... eh you get the idea
  }
  rewind = !rewind;
}



And the fragment shader looks like this:
uniform sampler2D reflection;
void main(void)
{
  vec4 refl = texture2D(reflection, gl_TexCoord[0].xy);
  gl_FragColor = refl;
}


Oh, and of course I setup the shader program and the uniforms, and also binds the texture. So the problem doesn't lie there :)

Share this post


Link to post
Share on other sites
Advertisement
Yay! I solved it :)

The problem was that I wasn't changing the texture matrix for the right texture! I bound another texture after my reflection texture.

Also I needed to change texture2D(reflection, gl_TexCoord[0].xy) into texture2DProj(reflection, gl_TexCoord[0].xyz).

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!