PDA

View Full Version : glOrtho



JoshWilczek
02-15-2006, 01:22 PM
I'm currently drawing inside a rectange that is 600x600 pixels. In openGL this area is referenced as a rectangle that has corners (1,1), (-1,1), (-1,-1), and (1,-1). Is there anywhere that this could be scaled to reflect the actual size of the rectange, such as, (300,300), (-300,300), (-300,-300), (300,-300)? From the documentation I've read it seems like glOrtho is the function that would do this. However, I haven't been able to get it to work the way I would expect.

glOrtho(0,600,0,600,0,0);

Thanks for the help!

Relic
02-16-2006, 04:49 AM
And what did the documentation say about zNear == zFar. That throws an invalid_value error.

Try this:

// If the Window's client area is 600x600:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 600.0, 0.0, 600.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor3f(1.0f, 0.0f, 0.0f); // Red
glBegin(GL_QUADS); // Counter-clockwise winding.
glVertex2f(0.0f, 0.0f); // Lower left corner of lower left pixel.
glVertex2f(600.0f, 0.0f);
glVertex2f(600.0f, 600.0f); // Upper right corner of upper right pixel of the window.
glVertex2f(0.0f, 600.0f);
glEnd();That should fill the whole window with a red quad.

For point or line rendering you should adjust the vertices by (+0.5f, +0.5f).

JoshWilczek
02-16-2006, 05:41 AM
Thanks for the help. The zNear==zFar was my issue. Now, however, (0,0) is at the bottom-left of the screen instead of the center like before. Is there any way to change this? It's not that big of a deal, except all of the code that I've written up to this point used that assumption. I know I could fix it by just adding a +offset to each vertex.

Thanks again!