OpenGL ES Coordinate System on Android?
I am new to Android developing and curently I am playing arround with OpenGL ES 1 using the NDK. Unfortunetely I got a problem with the Coordinate system. In the official example, the following code is used to get the width and height of the Opengl Surface.
eglQuerySurface(display, surface, EGL_WIDTH, &w);
eglQuerySurface(display, surface, EGL_HEIGHT, &h);
Now when I want to setup the viewport with
glViewport( 0, 0, w ,h );
and I render a quad then the quad isn't a quad, it is a deformed rectangle and centered.
How can I setup the Viewport and the开发者_运维百科 Coordinate System correctly?
You have the viewport set up correctly; you need to adjust your projection matrix (or equivalent, if you're in ES 2.0 rather than 1.x). E.g.
glMatrixMode(GL_PROJECTION);
glFrustumf(-(float)w/h, (float)w/h, -1, 1, 1, 500);
OpenGL makes no assumptions about the aspect ratio of your pixels or of your viewport — you have to organise yourself.
精彩评论