• Advertisement
Sign in to follow this  

Weird GLSL problem

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

The problem has been detected in my GeForce5200, 84.21 ForceWare. Basically, consider this extremely simple fragment shader(the vertex shader just calls ftransform):
void main()
{
    vec4 n=gl_ModelViewMatrix*vec4(1,0,0,0);
    gl_FragColor=vec4(n.xyz,1);
}

Then, the geometry:
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glTranslatef(cpos.x,cpos.y,cpos.z);			
									
glPushMatrix();
glRotatef(270.0,0,1,0);
glBegin(GL_QUADS);
glNormal3f(0,0,1);
glVertex3f(-1,1,1);
glVertex3f(1,1,1);
glVertex3f(1,-1,1);
glVertex3f(-1,-1,1);
glEnd();
glPopMatrix();

glPopMatrix();

Obviously, this program has no function other to present a problem I encountered with my actual application. Anyway, the quad is rendered blue, as it should. However, the program behaves correctly only if the quad is the first primitive rendered. If I put, right after glTranslatef(...) these 2 lines: glBegin(GL_POINTS);glEnd(); then the quad is rendered red! In simple terms, the fragment shader "sees" the gl_ModelViewMatrix as Identity. If, after the no-op glBegin()/glEnd() I disable the shaders, and then immediately enable them again, and then render the quad, it's blue again. It's as if, for the fragment shader, the uniform gl_ModelViewMatrix gets "stuck" in the value it had before the first primitive was rendered, and stays that way until the shaders are disabled. I should point out that if I get the current value of the modelview matrix and pass it myself through a uniform to the fragment shader, it works fine. Has anyone seen this before? Is it a bug? I'm pretty sure accessing State Uniform variables from fragment shaders is perfectly legal, so this shouldn't happen.

Share this post


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

  • Advertisement