Sign in to follow this  

Switchi8ng from Orthogonal to Perspective in same scene

This topic is 4223 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]); .... } 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[i].DrawMode == DrawMode.Perspective) { gluPerspective(...); } else { glOrthogonal(...); } glMatrixMode(GL_MODELVIEW); fnRenderObject(objectArray[i]); .... } 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
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

This topic is 4223 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this