I want to render my scene at the lower left corner of windows, the following codes work fine if the Camera is located at(0,0,0), but my scene
doe not stay at the viewport(0,0,w/4,h/4)if the Camera position change, what should I do in order to have my scene stay at the lower left corner when Camera move.
MyRenderFunction(Camera* cam)
{
int w=cam->m_Width;
int h=cam->m_Height;
glPushMatrix();
glViewport(0,0,w/4,h/4);
Note the braces near the push/pop calls. I know it is not typical, but I have added them to my GL coding standard and swear by it. It really helps keep things in order, and easily find matching push/pop pairs. Try fixing the push/pop pairings and I bet your code starts behaving as expected.
when I add a simple axis drawing in your modified code, it always show the 2D drawing, not 3D drawing in 3D view.
If I comment out the second glLoadIdentity()(the line wit Question to ask) , it shows the 3D drawing in 3D view, but if I modify the camera poition, the drawing position change or disappear.
Thanks
P.S. Sorry, somehow I can not get your orginal format.
The call to glLoadIdentity means that your drawing will not be transformed. It sets the modelview transform to the idenity matrix, essentially cancelling out any previous model transformation you may have had. This leaves only the projection transform to affect your vertices. Only the X and Y axes will be drawn. This is to be expected. The camera position is not related to the viewport. The only relation between the camera and the viewport is the viewing frustum you create. This frustum (ortho/perspective) is mapped to the viewport bounds that you specify. All of the code above works as expected. I would verify the width and height being returned from your camera object.