View Full Version : is glViewport needed or used in OpenGL ES 2.0?

12-17-2012, 01:56 PM
What does glViewport do when you are using OpenGLES 2.0? Isn't everything defined by the various matrices you use in the shaders?


12-17-2012, 02:59 PM
Hi Bob,

Don't confuse glViewport with the transformation matrices (as I did not too long ago). All glViewport does is define the area of the drawing context that you will actually draw to.

For example, let's assume your window is 800 by 600 pixels. Calling glViewport(0, 0, 800, 600) means you will draw to the whole screen. Calling glViewPort(0, 0, 400, 300) means you will only draw in the bottom left quadrant.

12-17-2012, 05:11 PM
I still thought that somehow what the viewport call did ultimately boiled down to what the projection matrices did.

So it is needed in OpenGLES 2?

12-17-2012, 06:34 PM
I can't give you a 100% sure answer since I don't personally work with OpenGL ES 2.0, but you should still need it, if only just once during your initialization.

Generally glViewport would help if you were trying to draw multiple views, like in 3D modeling software or multiplayer split-screen games. Half the window might use one set of projection matrices, like perspective; the other half may use another, like orthographic. A call to glViewport scales (and depending on your transformation matrices, possibly distorts) the drawing output/buffer to fit within the rectangle you set. If you use a fully symmetrical projection matrix, the vanishing point will be at the center of your specified viewport.

12-18-2012, 08:39 AM
Yes, it is needed. glViewport sets the viewport that is used by the viewport transformation step which transforms NDCs (normalized device coordinates) to viewport coordinates. This is needed both in OpenGL ES 2.0+ and OpenGL Core 3.x+