Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎯 Unreal

Weird GLSL problem

Started by mikeman Jul 8, 2006 at 1:50 PM 0 replies 750+ views
Original Post
mikeman
mikeman
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.