shawn619

04-19-2013, 05:06 PM

I have couple questions that would GREATLY assist me in understanding opengl. Some questions pertain to basic glsl functions, but i think the majority are opengl related, so i posted this in opengl thread instead of glsl.

(i) Each gl_ModelViewMatrix matrix needs to correspond to a gl_PushMatrix, because a gl_PushMatrix "creates" a new modelviewmatrix on the stack, right?(assuming matrixmode=gl_modelview)

If so, does the glsl shader program receive the corresponding vertex's modelviewmatrix when vertices are passed to the shader?

To further explain,

glPushMatrix();

glTranslatef(0,5,0);

glutSolidCube(20);//first cube

glTranslatef(0,5,0);

glutSolidCube(20);//second cube

glPopMatrix();

In the resulting modelviewmatrix from the above code, the components in the matrix would show a +10 x-axis translation. But that translation is only true for the second cube, while the first cube only has a +5 x-axis translation. So, how am i supposed to, for example, transform from object-eye coordinate space in the following code if i recieve a vertex from the first cube, while the corresponding modelviewmatrix has a 10 translation, when i really need the 5 translation for the first cube:

v = vec3(gl_ModelViewMatrix * gl_Vertex);

(ii) In glsl, are "gl_LightSource[x]", where 'x' is 0 to max_lights, coordinates already in eye view when passed to glsl shader program?

I appreciate any answers, thanks!

(i) Each gl_ModelViewMatrix matrix needs to correspond to a gl_PushMatrix, because a gl_PushMatrix "creates" a new modelviewmatrix on the stack, right?(assuming matrixmode=gl_modelview)

If so, does the glsl shader program receive the corresponding vertex's modelviewmatrix when vertices are passed to the shader?

To further explain,

glPushMatrix();

glTranslatef(0,5,0);

glutSolidCube(20);//first cube

glTranslatef(0,5,0);

glutSolidCube(20);//second cube

glPopMatrix();

In the resulting modelviewmatrix from the above code, the components in the matrix would show a +10 x-axis translation. But that translation is only true for the second cube, while the first cube only has a +5 x-axis translation. So, how am i supposed to, for example, transform from object-eye coordinate space in the following code if i recieve a vertex from the first cube, while the corresponding modelviewmatrix has a 10 translation, when i really need the 5 translation for the first cube:

v = vec3(gl_ModelViewMatrix * gl_Vertex);

(ii) In glsl, are "gl_LightSource[x]", where 'x' is 0 to max_lights, coordinates already in eye view when passed to glsl shader program?

I appreciate any answers, thanks!