So I'm learning OpenGL right now and trying to use glOrtho to scale my sprites correctly, but it doesn't seem to be working. No matter what arguments I pass to glOrtho, it always defaults back to (-1, 1, -1, 1). I checked for GL errors and got nothing. Here is my test code:
The quad I draw should be tiny, but it covers the entire viewport. Halp!
Name:
Anonymous2011-08-29 19:24
Maybe try glOrtho(-100.0, 100.0, -100.0, 100.0, 0.0, 1.0);
Or just use gluOrtho2D.
Name:
Anonymous2011-08-29 19:27
I do this before glutMainLoop()
void init() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-2.0, 10.0, -2.0, 5.0);
glMatrixMode(GL_MODELVIEW);
glClearColor(1.0, 1.0, 1.0, 1.0);
glEnable(GL_POINT_SMOOTH);
}
Name:
Anonymous2011-08-29 19:30
Oh, I think you should put glOrtho before you do the main loop. Not in your display function.
Name:
Anonymous2011-08-29 19:35
OP here. I've tried gluOrtho2D, tried changing the near and far clipping plane, and also my glOrtho call was originally before the main loop. I just put it there for the code sample. None of it makes any difference =\
Name:
Anonymous2011-08-29 19:56
You have to be in GL_MODELVIEW when you draw.
Name:
Anonymous2011-08-29 20:00
Switching to GL_MODELVIEW didn't change anything. I thought that was only for 3D drawing anyways, right? This is all 2D.
>>13
You're not “in” a projection, you apply a projection to an existing space. The view doesn't vanish just because you haven't transformed it.
Name:
Anonymous2011-08-30 1:35
>>1
As >>10 said: glLoadIdentity() undos glOrtho() as it resetts your current view Matrix. So you have to call glOrtho() in a different MATRIX like this:
...
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(...)
...
glMatrixMode(GL_MODELVIEW);
glLoadLibrary();
...
Btw go read a decent OpenGL Tutorial. Like this: http://www.opengl.org/documentation/red_book/