• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# glOrtho help!

## 1 post in this topic

Please give me some syntax and examples using glOrtho or glOrtho2d... Im using it in a crappy little game like asteroids... Please help,..thanks!
0

##### Share on other sites
glOrtho() takes 6 parameters:
(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)
left and right are x-axis coordinate bounds
bottom and top are the y-axis coordinate bounds
near and far are the z-axis coordinate bounds

gluOrtho2D() is just a special case of glOrtho() which automatically sets near and far (z-axis coordinate bounds) to be between -1.0 and 1.0.

These functions basically allow you to set up your own coordinate system for whatever drawing you want to do. Instead of drawing in actual screen coordinates, you would be drawing in your coordinate system, as you specified.

For example:
Say I wanted to draw a large square centered in the middle of a screen with the coordinate system specified as
glOrtho(-30.0, 30.0, -30.0, 30.0, 30.0, -30.0);
Here''s how I''d do it
glVertex3f(-25.0, -25.0, 0.0); //lower-left, z-axis at origin
glVertex3f(25.0, -25.0, 0.0); //lower-right
glVertex3f(25.0, 25.0, 0.0); //upper-right
glVertex3f(-25.0, 25.0, 0.0); //upper-left
glEnd();

This would leave a 5 unit space around the square, because the bounds of my coordinate system extended between -30 and 30 for every axis.

Hope this helps,
Thek
0