ufk ufk - 1 year ago 132
C++ Question

Explain the usage of glOrtho()?

I can't understand the usage of glOrtho. can someone explain what is it used for ?


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?

Answer Source

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:

glOrtho(0.0f, windowWidth, windowHeight, 0.0f, 0.0f, 1.0f);

This will remap the OpenGL coordinates into the equivalent pixel values (X going from 0 to windowWidth and Y going from 0 to windowHeight). Note that I've flipped the Y values because OpenGL coordinates start from the bottom left corner of the window. So by flipping, I get a more conventional (0,0) starting at the top left corner of the window rather.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download