14

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
user717572
  • 3,626
  • 7
  • 35
  • 60

1 Answers1

23

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.

luke
  • 36,103
  • 8
  • 58
  • 81
  • about the split screen mode, does this mean glViewport is like pointing to a location in the 3d world? btw i'l study the link when I can find some time ;) thanks! – user717572 Sep 27 '11 at 20:18
  • And if I for example would do something like scrolling through the world/map, translate ALL of the objects or change the glViewport or the glOrtho projection? (sorry couldn't edit anymore) – user717572 Sep 27 '11 at 20:25
  • The viewport has nothing to do with the 3D world. It has to do with the final screen coordinates. To move things around in 3D space you want to glRotate/glTranslate when the modelview matrix is active. Definitely check out that link. – luke Sep 28 '11 at 11:36