I'm working on an iphone project where I need both a horizontal and a vertical layout. I've got it working in 2D perfectly well, using the following setup to my projection matrix:
if(isHoriz()){
glRotatef(90.0f,0.0f,0.0f,1.0f);
SOrtho(0, 480, 0, 320, -1, 1);
}
else
SOrtho(0, 320, 0, 480, -1, 1);
The problem lies when I move to 3D
glViewport(0,0,320,480);
glScissor(0,0,320,480);
gluPerspective(28.8f,320/480,0.1f,1000.0f);
if(isHoriz())
glRotatef(90.0f,0.0f,0.0f,1.0f);
This seems to work, but the view is offset vertically wrong. What I want to happen is that the top half of the vertical display becomes the center of the horizontal display. Instead, it seems like the middle of the vertical display becomes the center of the horizontal display.
Because this is an iphone, the window height (480) and width (320) remain constant regardless of rotation. I've tried building the same code into a windows program, and the code that gets the effect I want for the horizontal rotation is simple. I just change the window shape, so that I have a landscape window, and then remove the call to
if(isHoriz())
glRotatef(90.0f,0.0f,0.0f,1.0f);
(I also do something similar to the 2D code).
Am I doing something wrong? Why don't the windows version and the iphone version look the same?
Edit: To clarify, I've tried adding glTranslatef() calls above and below the glRotatef call, but this seems to have an effect on the angle of my camera. The camera code is applied to my modelView matrix immediately after the above code. It looks like this:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(mRotate.mZ,0,0,1);
glRotatef(mRotate.mY,0,1,0);
glRotatef(mRotate.mX,1,0,0);
glTranslatef(-mPos.mX,-mPos.mY,-mPos.mZ);
The initial values of the camera are mRotate.mX = -80, mPos.Z = -8.