tags:

views:

416

answers:

2

Hiya. I started learning OpenGL and I can't understand the usage of glOrtho. can someone please explain what is it used for ?

thanks

update

is it used to set the range of x y and z coordinates limit ?

glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

it means that the x, y and z range are from -1 to 1?

thanks!

+1  A: 

glOrtho describes a transformation that produces a parallel projection. The current matrix (see glMatrixMode) is multiplied by this matrix and the result replaces the current matrix, as if glMultMatrix were called with the following matrix as its argument:

OpenGL documentation (my bold)

The numbers define the locations of the clipping planes (left, right, bottom, top, near and far).

The "normal" projection is a perspective projection that provides the illusion of depth. Wikipedia defines a parallel projection as:

Parallel projections have lines of projection that are parallel both in reality and in the projection plane.

Parallel projection corresponds to a perspective projection with a hypothetical viewpoint—e.g., one where the camera lies an infinite distance away from the object and has an infinite focal length, or "zoom".

ChrisF
hi thanks for the info.i couldn't quite understand the difference between parallel and perspective projection. i googled a bit and found the answer in http://wiki.answers.com/Q/What_is_the_difference_between_orthogonal_and_perspective_projection
ufk
Unfortunately the information you got from answers.com is pretty worthless. An isometric view, for example, is very 3-D, yet it is a parallel projection without perspective. See here, and there are also links to many other examples of projections: http://en.wikipedia.org/wiki/Isometric_projection
Ben Voigt
+2  A: 

Have a look at this picture: Graphical Projections

The glOrtho command produces an "Oblique" projection that you see in the bottom two panels. No matter how far away vertexes are in the z direction, they will not recede into the distance.

I use glOrtho every time I need to do 2D graphics in OpenGL (such as health bars, menus etc) using the following code every time the window is resized:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, windowWidth, windowHeight, 0.0f, 0.0f, 1.0f);
Mikepote
thanks a lot for clarifying the issue! :)
ufk
oh my god I LOVE YOU. Do you have any idea how long it takes to find/figure out this single line of code online? Thank you, I shall name my first born child after you for this
karpathy