I’m developing an 4 split viewer in OpenGL. One view is a perspective view, the other ones are for orthogonal projections (front, left, top).
I wrote a method that draws a cube from (-1,-1,-1) to (1,1,1) and it works well in the perspective view, but i can’t get it to work in my views that use glOrtho(…).
Right now I set it up like this:
glOrtho(0, width, height, 0, 0, 1);
The funny thing is, that the view doesn’t show the cube at all. I implemented a border for the view in OpenGL which gets shown correctly though.
I’m using Qt and wrote a derived class of QGLWidget.
glOrthodefine 6 clipping planes in the view space after themodel transformand theview transform. So you should specify the parameters of glOrtho in theEye Space, not theScreen Space. in your case, it should beglOrtho(-width/(float)height, width/height, -1.0f, 1.0f, -1.0f, 1.0f)which assumes theeye positionis in(0.0, 0.0, 0.0)and yourviewportiswidthbyheight. theNearValparameter ofglOrthoshould be negative if the near plane is behind the viewer(the eye position). You may want to man glOrtho. the 4th Chapter ofCg tuturialcan give you a detailed information about the transformation of different coordinate spaces i.e.Object Space,World Space,Eye Space,Clip space,Normalized Device SpaceandWindow Space.