#### Archived

This topic is now archived and is closed to further replies.

# Problems with glMatrixMode

## Recommended Posts

Hello everybody, and thank you for reading my post. I''m having difficulty getting my scene to render correctly. In my drawGLScence function, I change my glMatrixMode to MODEL_VIEW so I can do some translation and rotation on my models. I want to change my matrixMode to PROJECTION so I can change how the CAMERA is oriented on the scene(Like a simple pan effect). I''m thinking about using the gluLookAt function, but I can''t get it to work correctly. Here is my code. (I still havn''t figured out how to post code in that cool little box, either... ^_^) ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /** translate, rotate models, all that good stuff... */ /* Now I''m finished with my models. I want to load my Projection Matrix so I can translate/rotate */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Coment out gluLookAt because its not rendering right... //gluLookAt(0.0, 0.0, 0.0, // 0.0, 0.0, 60.0, // 0.1,0.0,0.0); } ////////////////////////////////////////////////// ////////////////////////////////////////////////// Now, the problem is when I run the program, it displays my models for ONE FRAME only, then everything goes blank. When I coment out the lines that change the MatrixMode, the problem goes away (imagine that...). Does anyone have any suggestions? Thank you. ~stu

##### Share on other sites
Leave the projection matrix alone. What did it ever do to you?

edit: just to clarify - you shouldn't be doing your camera transform your with the projection matrix. Just perform the inverse of the camera's transformation on the modelview matrix. The projection matrix is just for specifying the projection.

[edited by - benjamin bunny on May 2, 2003 10:42:05 PM]

##### Share on other sites
So how do I translate the camera? Can I use the traditional glTranslatef functions? Is every "camera" movement actually a model transform in disguise? If I look around using the mouse in Quake III, is the "camera" looking around, or is the map transforming?

sorry to sound naive.

##### Share on other sites
Use gluLookAt or glTranslatef, whatever. Just DON''T change to the projection matrix!

  //////////////////////////////////////////////////////////////////////////////////////////////////////////int DrawGLScene(GLvoid) {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW); glLoadIdentity();/**translate, rotate models, all that good stuff...*/gluLookAt(0.0f, 0.0f, -10.0f,          0.0f, 0.0f, 0.0f,          0.0f, 1.0f, 0.0f);////////////////////////////////////////////////////////////////////////////////////////////////////

##### Share on other sites
quote:
Original post by n3odymium
So how do I translate the camera? Can I use the traditional glTranslatef functions? Is every "camera" movement actually a model transform in disguise? If I look around using the mouse in Quake III, is the "camera" looking around, or is the map transforming?

sorry to sound naive.

i dont know which book gave you the impression the projection matrix had anything to do with it. there is no camera and the only way to pretend that is to move everything the other way. if you do that by calling rotate/translate or have glulookat do the work doesnt matter (at least for the result). no matter how, in the end you have the inverse of your cams transformation and apply it to everything rendered. NEVER touch the projection matrix except to call gluperspective, glortho, glfrustum etc. (or if you know what youre doing).

##### Share on other sites
quote:
Original post by n3odymium
So how do I translate the camera? Can I use the traditional glTranslatef functions? Is every "camera" movement actually a model transform in disguise? If I look around using the mouse in Quake III, is the "camera" looking around, or is the map transforming?

sorry to sound naive.

As you''ve rightly guessed, there''s no difference between moving the camera one way and moving the whole world the other.

• ### Forum Statistics

• Total Topics
628377
• Total Posts
2982324

• 10
• 9
• 14
• 24
• 11