Jump to content
  • Advertisement
Sign in to follow this  
vivekd

Switchi8ng from Orthogonal to Perspective in same scene

This topic is 4442 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having two or more objects rendered in the same scene. For this, I iterate through a loop like this: for(int i = 0; i < objectArray.Length; i++) { fnRenderObject(objectArray); .... } I want each object in the objectArray to be drawn in seperate modes, i.e one in orthogonal, the other Perspective, then the next again Orthogonal and the succeeding one again as Perspective. I tried doing it as: for(int i = 0; i < objectArray.Length; i++) { glMatrixMode(GL_PROJECTION); if(objectArray.DrawMode == DrawMode.Perspective) { gluPerspective(...); } else { glOrthogonal(...); } glMatrixMode(GL_MODELVIEW); fnRenderObject(objectArray); .... } But this failed to display the objects correctly. How do I keep switching the modes?

Share this post


Link to post
Share on other sites
Advertisement
If that is indeed your code and you didn't leave anything else important out, then you will need to first reset the projection matrix to identity before applying a perspective or orthogonal matrix.

gluPerspective and glOrtho multiply with the current matrix on the stack -- they do not load a new one.

Share this post


Link to post
Share on other sites
I'm sorry. Forgot to mention that I have to render the background of the objects before drawing the objects. For that, I already have Loaded the Projection matrix with identity matrix and drawn the background. The code I have give above was just an intermediate code snippet.

Share this post


Link to post
Share on other sites
Quote:
Original post by vivekd
I'm sorry. Forgot to mention that I have to render the background of the objects before drawing the objects. For that, I already have Loaded the Projection matrix with identity matrix and drawn the background. The code I have give above was just an intermediate code snippet.
But on each iteration of the loop, assuming that's all that happens in your actual code, you are multiplying the projection matrix with a new perspective or orthographic one (you are concatenating all those projection matrices). You need the projection matrix to be the identity before you call gluPerspective or glOrtho.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!