Texture Matrices not working in GSL?

I have the following code that transforms the texture matrix.

  
        static float planeS[4] = { 1.0f, 0.0f, 0.0f, 0.0f };
        static float planeT[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
        static float planeR[4] = { 0.0f, 0.0f, 1.0f, 0.0f };
        static float planeQ[4] = { 0.0f, 0.0f, 0.0f, 1.0f };

        static float matProj[16];
        static float matModel[16];
        static float biasMatrix[16] = { 0.5f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 0.5f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 0.5f, 0.0f,
                                        0.5f, 0.5f, 0.5f, 1.0f };
		
        glPushAttrib(GL_ENABLE_BIT);

        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D,textureID);

        glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
        glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
        glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
        glTexGeni(GL_Q,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);

        glTexGenfv(GL_S,GL_EYE_PLANE,planeS);
        glTexGenfv(GL_T,GL_EYE_PLANE,planeT);
        glTexGenfv(GL_R,GL_EYE_PLANE,planeR);
        glTexGenfv(GL_Q,GL_EYE_PLANE,planeQ);

        glEnable(GL_TEXTURE_GEN_S);
        glEnable(GL_TEXTURE_GEN_T);
        glEnable(GL_TEXTURE_GEN_R);
        glEnable(GL_TEXTURE_GEN_Q);

        glGetFloatv(GL_PROJECTION_MATRIX,matProj);
        glGetFloatv(GL_MODELVIEW_MATRIX,matModel);

        glMatrixMode(GL_TEXTURE);
        glPushMatrix();
        glMultMatrixf(biasMatrix);
        glMultMatrixf(matProj);
        glMultMatrixf(matModel);
        glMatrixMode(GL_MODELVIEW);

This is basically for setting up the texture matrices to correctly project a reflected scene onto a water plane. It all works just fine, but I tried to then create a pixel and vertex shader in GSL and all of the texture transformations went away and I did not get the correct result.

Here are my vertex and texture shaders.

// VERTEX SHADER  
void main()
{			
	// get texture unit 0 coords
	gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
	
	// get vertex position
	gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
}

// FRAGMENT SHADER

uniform sampler2D reflection;

void main()
{
	vec4 color_reflection 	= texture2D(reflection, gl_TexCoord[0].st);

	gl_FragColor = color_reflection;
}

Here are the results I get before using a pixel shader and after. Does anybody know what is wrong with my pixel shader or vertex shader ?

Well, those texgens will be overridden by the vertex shader. You’ll have to implement the equivalent math in the vertex shader yourself.

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