PDA

View Full Version : load matrix after glFrustum



jack_aerospace
09-30-2013, 09:49 AM
I'm now creating for the first time an Augmented Reality application. I'm using ARToolkit libraries to obtain the transformation matrix.
In an example this matrix is transformed in a GLformat (3x4 to 1x16 cause the last row is always composed by three zeros and a last one) and the loaded with the function glLoadMatrix in GL_MODELVIEW. Everithing work well..
Now I have the problem that the object i want to see in my AR application is too far from the origin of coordinate system, the far clipping plane don't let it see..

I read in the red book that glFrustum can help me, so I write this code, but I don't see anything at all!!
In my opinion mi mistake is the bad use of GL_PROJECTION adn GL_MODELVIEW..

Here I post my code.. maybe someone of you know the answer to my question..


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum (-1, 1, -1, 1, 1.5, 20000.0);
glMatrixMode (GL_MODELVIEW);
glLoadMatrixd( gl_para );

glutSolidCube(40);



I tried also this


glMatrixMode(GL_PROJECTION);
glLoadMatrixd( gl_para );
glFrustum (-1, 1, -1, 1, 1.5, 20000.0);
glMatrixMode (GL_MODELVIEW);

glutSolidCube(40);

Dark Photon
09-30-2013, 06:38 PM
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum (-1, 1, -1, 1, 1.5, 20000.0);
glMatrixMode (GL_MODELVIEW);
glLoadMatrixd( gl_para );

glutSolidCube(40);


Try commenting out glLoadMatrixd and replacing with glLoadIdentity, to get rid of one unknown.

With this, the glutSolidCube sends a cube with X,Y,Z in -20..20 down the pipe. Part of it with Z < -1.5 is in-frustum. However, since the eyepoint is inside the cube, most likely it is backface culled. Try glDisable( GL_CULL_FACE ). Now depending on your other GL state you may be able to see it.

I tried also this



glMatrixMode(GL_PROJECTION);
glLoadMatrixd( gl_para );
glFrustum (-1, 1, -1, 1, 1.5, 20000.0);
glMatrixMode (GL_MODELVIEW);

glutSolidCube(40);

If gl_para is a MODELING and/or VIEWING transform, it should definitely not be mixed into the PROJECTION matrix stack.