Parallel use of Vertex-Shader + GL-transformations

Hello,

I have a little OGL-program, which loads some GL-transformations on the stack and then draws a model:

glPushMatrix();
glTranslatef(x,y,z);
glRotatef(a,x,y,z);
drawModel();
glPopMatrix();

In addition of these transformations I will use a vertex-shader written in Cg:

enableMyVertexShader();

glPushMatrix();
glTranslatef(x,y,z);
glRotatef(a,x,y,z);
drawModel();
glPopMatrix();

DisableMyVertexShader();

My problem is, that the vertex-shader works, but on the original model (without the GL-transformations) and not on the translated and rotated one.

Your shader is responsible for applying transformations.
OpenGL just provides you a set of state variables (like modelview matrix in your case)

If I remember correctly (haven’t been working with Cg for a long time), you have to hand over the modelview matrix manually to Cg as a variable. In Cg you don’t have a builtin modelview matrix variable automatically as in GLSL (like in OpenGL 3.x with forward compatibility / core profile).

So, get the matrix with:
glGet(GL_MODELVIEW_MATRIX, …);

And make sure the Cg shader program gets this matrix.
(the GLSL equivalent function would be: glUniformMatrix4fv)

And as DmitryM said: apply the matrix multiplication with the vertex manually in the shader.

Ok, well if I remember correctly (and for me too it has been a while), you can get auto-tracked matricies via glTrackMatrixNV. For instance, something like this:

glTrackMatrixNV( GL_VERTEX_PROGRAM_NV, 60, GL_MODELVIEW, GL_IDENTITY_NV );

and then in the shader when declaring the uniform input, nail it to a set of 4 constant registers, starting at the same base register:

..., uniform float4x4 sgglModelView : C60, ...

See NV_vertex_program for details. May only work for the NVidia profiles.

And for the ARB profiles, you’d just reference glstate.matrix.modelview (or something like that) in the shader and be done with it. Tracking is automagic.

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