PDA

View Full Version : CG and GLUT



DarthBill
02-25-2005, 06:33 PM
Hi,

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.

AnselmG
02-26-2005, 01:40 AM
Hi,
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.

Silkut
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..

DarthBill
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.

ScottManDeath
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.



glPushMatrix();
gltutMultShapeMatrix(live_shape);
cgGLSetStateMatrixParameter(model_view, CG_GL_MODELVIEW_MATRIX,CG_GL_MATRIX_IDENTITY);
cgGLSetStateMatrixParameter(model_view_IT, CG_GL_MODELVIEW_MATRIX,CG_GL_MATRIX_INVERSE_TRANSP OSE );
cgGLSetStateMatrixParameter(model_view_projection, CG_GL_MODELVIEW_PROJECTION_MATRIX,CG_GL_MATRIX_IDE NTITY);
cgGLSetStateMatrixParameter(projection, CG_GL_PROJECTION_MATRIX,CG_GL_MATRIX_IDENTITY);
glPopMatrix();


// shader stuff
// ...

// render shape based on id
gltutRenderShape(live_shape,live_wireframe==1);

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

\\hornet

DarthBill
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.

ScottManDeath
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.