Original Post
hello, i've got the my reflection work in fixed pipeline, but i met some trouble when using shader. the reflection texture is already stored in ref_tex and set to texture0. fixed pipeline(use automatically generated texcoord, the reflected image is right):
use shader(the image was distorted):
i dunno how this could happen. any help would be appreciated. [Edited by - bybw on December 31, 2004 9:13:34 AM]
[Vertex]
void main(void)
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_Vertex;
}
[Fragment]
uniform sampler2D tex;
void main (void)
{
gl_FragColor= texture2DProj(tex, gl_TexCoord[0]);
}
glMatrixMode(GL_TEXTURE);
glLoadMatrixf(Mr);
glMultMatrixf(projection);
glMultMatrixf(modelview);
// here i got the texture matrix i've setup, right?
shader.begin();
// get location and set uniform
shader.setUniform1i("tex", 0);
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, ref_tex);
glEnable(GL_TEXTURE_2D);
// draw water plane
glBegin(GL_QUADS);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
glVertex3f(-size, 0, -size);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
glVertex3f(-size, 0, size);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
glVertex3f( size, 0, size);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
glVertex3f( size, 0, -size);
glEnd();
shader.end();