PDA

View Full Version : Adjusting aspect-ratio



Sagiv B
04-01-2012, 11:10 PM
Hi,

I'm using GLES2, and I'd like to know how adjust aspect-ratio to match new window dimension.
usually, I'd write something like that in the 'surfaceChange' function:
glViewport(0, 0, width, height); //Reset The Current Viewport
glMatrixMode(GL_PROJECTION); //Select The Projection Matrix
glLoadIdentity();
//Calculate The Aspect Ratio Of The Window
gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW); //Select The Modelview Matrix
glLoadIdentity();

But it seems like most of this code is not supported in GLES2 (I get many compilation error on missing declaration).
Am I missing some 'include' files? or maybe there's a different way for setting the aspect-ratio in GLES2?

Thanks.

gardin
04-18-2012, 11:00 AM
There is no matrix stack on an OpenGL ES 2.0 implementation, just as with OpenGL 3.x and newer, the fixed function pipeline has been removed and a lot of the initial functionality in OpenGL 2.0 shaders have also been removed.

Thus, gluPerspective is not being used anymore, nor any matrix operations at all.

What you're probably looking for is using uniforms. You need to define your own uniform matrices in your shaders and supply them with your own calculated values. Google for gluPerspective and you'll find the code used for the matrices in the specification.

If you're looking for an implementation that do support all of this, and you do not plan to use shaders, i would recommend looking at OpenGL ES 1.x instead.