OpenGL: To ortho, or not to ortho...

Started by
22 comments, last by RuneLancer 19 years, 11 months ago
glOrtho and glFrustum are intended for use on the projection matrix. This matrix is applied after the model view matrix. It handles mapping of OpenGL logical coordinates to actual window coordinates.

In 3d mode the projection matrix reduced the x and y coords of a vertex in proportion to the z coord.

I ortho mode, this doesn''t happen. Verteces x,y position is irrelevant of the z coord.

glOrtho sets up the top, bottom, left and right edges of the screen. If you want a pixel to appear at the top of the screen, make its y coord equal the value you specified for top. If you want a pixel to appear at the bottom left of the screen, make its y coord equal the value you specified for bottom and the x equals to the left value.

The point it, if you set glOrtho to have top = 0, left = 0, bottom = 600, right = 800, the bottom right pixel will be specified by a vertex with the xy coords of [800,600]. This will be the case whatever size the screen is. Even if you screen is 20000x10 pixels, the bottom right will still be at [800,600] as far as specifing verteces to OpenGL goes.

If you specify the right and bottom coords to equal the width and height of the screen respectivly, then one OpenGL unit will equal one pixel.
Advertisement
Just a quick comment...

glVertex2f(x,y) == glVertex3f(x,y,0)

does that help clear anything up?
glortho/gluortho2D are the same thing as setting up a window in any old 2D library. Without any depth testing it''ll display stuff like any 2D lib as well. Thing about glortho is if you set the near and far to regular 3D values and add in depth testing you could have a 3D world without perpestive, which is pretty cool. The benifit of ortho lies in the fact the your game will be completely hardware accelerated and have access to fog, light, alphablending, and numerous other effects.

"Life is a double edged sword, we always hope to strike though adversity with the shining side..."

jkettles16 of Venosoft
"Life is a double edged sword, we always hope to strike though adversity with the shining side..."jkettles16 of Venosoft
@Graveyardfilla:
Think of it this way...

If you set your world to be 0,0, 1600,1200 and your resultion is 800x600, every two units would translate to one pixel on your screen. If you''d set it to 0,0, 800,600, every unit would translate to a pixel on your screen. 0,0, 400,300, every half unit.

Basically, it''s like if you had a second screen and were drawing to it. Then when you display it on your screen, that screen is stretched to fit in your window.

This topic is closed to new replies.

Advertisement