is glViewport needed or used in OpenGL ES 2.0?
What does glViewport do when you are using OpenGLES 2.0? Isn't everything defined by the various matrices you use in the shaders?
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.
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?
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.
Last edited by Aestivae; 12-17-2012 at 06:35 PM.
Reason: redundancy: "center will be at the center"
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+
Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
Technical Blog: http://www.rastergrid.com/blog/