Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between glOrthof and glViewPort

On OpenGL-ES i'm confused on what the difference is between setting

glOrthof()  
glViewPort()
GLU.gluOrtho2D()

with it's respective parameters. Since I believe it's all setting the part you can see to the specified coordinates (width, height). Which should I use?

like image 228
user717572 Avatar asked Sep 27 '11 16:09

user717572


People also ask

What does glViewport do?

The glViewport function specifies the affine transformation of x and y from normalized device coordinates to window coordinates. Let (xnd , ynd ) be normalized device coordinates.

What is difference between gluOrtho2D () and glOrtho () in opengl?

The difference is that glFrustum takes clipping planes as arguments, and gluPerspective takes a field of view and aspect ratio. glOrtho and gluOrtho2D set up 2D projection modes (i.e., parallel projection). Such are not necessarily 2D, but they do imply that farther objects are not any smaller than closer ones.

Is glViewport necessary?

You always need to call glViewport() before starting to draw to a framebuffer with a different size. This is necessary because the viewport is not part of the framebuffer state.

What is GL Ortho?

The glOrtho function describes a perspective matrix that produces a parallel projection.


1 Answers

The glViewport determins the portion of the window to which OpenGL is drawing to. This may be the entire window, or a subsection (think console game's "split screen" mode- a different viewport for every player).

glOrthof applies an orthographic projection to the current matrix, which is usually set to the projection matrix before this call. The projection matrix is combined with the modelview to produce a matrix that translates your OpenGL coordinates to screen coordinates.

gluOrtho2D,

This is equivalent to calling glOrtho with near = -1 and far = 1.

I'd recommend this page for more details on how viewing and transformation works in OpenGL.

Which should you use? Viewports and orthographic projections are different concerns, so you'll need a call for each. glOrthof and gluOrtho2D are roughly equivalent; know the difference and use one or the other.

like image 190
luke Avatar answered Oct 12 '22 19:10

luke