Having problems with projections

Hi Wizards!!!,
I am in a great problem …as I am not able to obtain the 2D projection[ Square] of a 3D Cube on the window…Is there a feasible way to do that…Can you guys give me a hint or can I get a sample code from any of you guys…Please reply me…I am in need of great help…Many Thanks…Cheers


Hi. Honestly I don’t really understand your problem. I’d like to help you but I don’t how…

There is something interesting for me in your post… How can a projection on a window be not 2D? Meaby my monitor is weird but I didn’t noticed any objects flying around me…

glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);

Substitute your own cube diomensions to suit.

P.S. that assumes you have identity on the projection matrix to start with. And of course you’d only call it once. It would be safer to make the following call between the first matrixmode call and the ortho call.


Do you mean, that your cube does not look like a cube, because its faces are not squares but rectangles?

In this case, you didn´t tell OpenGL, the aspect ratio of your window correctly:

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();

float fRatio = ScreenResolutionX / ScreenResolutionY;

gluPerspective (m_fFOVAngle, fRatio, m_fNearPlane, m_fFarPlane);

glMatrixMode (GL_MODELVIEW);

For example if you have a 1024*768 window, fRatio will be 1.33, which simply means, that your screen is 1.33 times wider than it is high. If you do this, than your cube will look like a cube.

But maybe you meant something different :wink: