Switchi8ng from Orthogonal to Perspective in same scene

Started by
2 comments, last by Kalidor 17 years, 11 months ago
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?
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.
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.
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.

This topic is closed to new replies.

Advertisement