View Full Version : CG and GLUT

02-25-2005, 06:33 PM

Has anybody used the GLUT built-in geometric objects (glutWireTeapot in my case) along with CG? My teapot is going through some strange translations when passed through a CG shader, but non-GLUT vertices that are going through the same shader show up where I expect them to. Has anybody else run across this problem? Thanks.

02-26-2005, 01:40 AM
you probably set your Modelviewmatrix for CG right before you call glutSolidTeapot() - but this call has a internal translation - that's why the teapot isn't at the desired position. Just use the ARB vertex profile and lookup the Modelview Matrix with the "glstate" variables. that should solve the problem.

02-26-2005, 03:56 PM
Don't forget to check nVidia's documentation, especially about Cg Toolkit, an important part talk about moving into 3D space through Cg, something like that..

03-01-2005, 03:42 PM
That glState trick worked. Out of curiosity, is there any way to make this work in a non-ARB profile? Thanks to both of you for your help.

03-01-2005, 05:12 PM
I had the same problem. I solved it by manually applying the internal transformations used by the glut shapes. I have a function gltutMultShapeMatrix(int shape) which applys the transformations based on the shape enumeration.

cgGLSetStateMatrixParameter(model_view, CG_GL_MODELVIEW_MATRIX,CG_GL_MATRIX_IDENTITY);
cgGLSetStateMatrixParameter(model_view_projection, CG_GL_MODELVIEW_PROJECTION_MATRIX,CG_GL_MATRIX_IDE NTITY);

// shader stuff
// ...

// render shape based on id

If you are interested, I could send you the code for all glut shapes with proper transformations. I also added texture coordinates for shapes like the cone and the torus.

Mikkel Gjoel
03-02-2005, 01:01 AM
Also, don't forget that the glut-teapot is a NURBS-surface (not that it should matter), and that it's defined with cw-winding, not ccw (this might matter) :p


03-02-2005, 03:14 PM
ScottManDeath, thanks for the offer; I would be interested in seeing that code. It's really for my own curiosity, though...I don't need it for anything important, so don't put yourself to too much trouble.

03-03-2005, 03:29 AM
The code can be found in the source code of GLUT, here is the important stuff

Transformations done internally by glutTeapot, scale is the parameter:

glRotatef(270.0, 1.0, 0.0, 0.0);
glScalef(0.5 * scale, 0.5 * scale, 0.5 * scale);
glTranslatef(0.0, 0.0, -1.5);

For my "ÜberShapeRender" function ;) , If you send me your email address (e.g. via Private Message), I'll send you the code, it would be to much to post here directly. Don't expect to much, the function is just there to conveniently render some shapes.