Transformations seem to work improperly
Ok, so I have a weird problem with OpenGL in landscape mode on iOS. From what I've read on the internet I have to rotate the scene myself, so I did that like this:
void GameViewController::onSurfaceChanged(int width, int height)
{
float aspect = (float)width / (float)height;
float fovy = 90.0f;
glMatrixMode(GL_PROJECTION);
float xmin, xmax, ymin, yma开发者_Python百科x;
ymax = 0.01f * Math::tan(fovy * 3.1415f / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glViewport(0, 0, width, height);
glLoadIdentity();
glRotatef(-90.0f, 0.0f, 0.0f, 1.0f);
glFrustumf(xmin, xmax, ymin, ymax, 0.01f, 320.0f);
}
My center of my camera isn't the center of the screen now though. So I reset all matrices (projection, modelview) so they are all identity, and then I drew a unit circle on the screen. Now I see what's going wrong, not all coordinates from -1 to 1 are actually on my screen! Here is a screenshot to show what I mean:
Now my question: what could possibly cause this?
EDIT: after some more investigation i found that in this obj-c method:
-(void)setupView:(GLView*)view
{
CGRect rect = view.bounds;
glViewport(0, 0, rect.size.width, rect.size.height);
gameView->onSurfaceCreated();
gameView->onSurfaceChanged(rect.size.width, rect.size.height);
view.multipleTouchEnabled = YES;
}
the view's size suddenly turned out to be 1216*1568. The problem is probably there. Manually passing 768 * 1024 to onSurfaceChanged gives me even weirder results.
Seems like there was an error in the template I was using. Using the default Open GL ES template way of creating a context gives me the proper 1024*768 screen size. Problem fixed.
精彩评论