TexGeni not working with GSL ??

Started by
2 comments, last by soconne 18 years, 7 months ago
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 ?
Author Freeworld3Dhttp://www.freeworld3d.org
Advertisement
using a vertex shader disables ALL fixed function per vertex opertaions, including texture coord generation, as such you have todo this yourself somehow
I converted this code from CG and I had no problems with this at all. I did not have to manually do anything to the texture coordinates with CG.

But with this program I just disabled the vertex shader and only bound the fragment shader. Here is the result.



Any ideas ?
Author Freeworld3Dhttp://www.freeworld3d.org
Nevermind, I had to divide the xy values of gl_TexCoord[0] by the w component. It works fine now.
Author Freeworld3Dhttp://www.freeworld3d.org

This topic is closed to new replies.

Advertisement