Problems with glMatrixMode

Started by
4 comments, last by n3odymium 20 years, 11 months ago
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
Thanks for listening!
Advertisement
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]

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

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.
Thanks for listening!
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);////////////////////////////////////////////////////////////////////////////////////////////////////  
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).

f@dzhttp://festini.device-zero.de
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.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

This topic is closed to new replies.

Advertisement