Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

glOrtho

Name: Anonymous 2011-08-29 19:11

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:

void Draw() {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-100.0, 100.0, -100.0, 100.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    glBegin(GL_QUADS);
        glColor3f(1.0f, 0.0f, 0.0f);
        glVertex2f(-1.0f, 1.0f);
        glVertex2f(1.0f, 1.0f);
        glVertex2f(1.0f, -1.0f);
        glVertex2f(-1.0f, -1.0f);
    glEnd();
}

The quad I draw should be tiny, but it covers the entire viewport. Halp!

Name: Anonymous 2011-08-29 19:24

Maybe try     glOrtho(-100.0, 100.0, -100.0, 100.0, 0.0, 1.0);
Or just use gluOrtho2D.

Name: Anonymous 2011-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: Anonymous 2011-08-29 19:30

Oh, I think you should put glOrtho before you do the main loop. Not in your display function.

Name: Anonymous 2011-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: Anonymous 2011-08-29 19:56

You have to be in GL_MODELVIEW when you draw.

Name: Anonymous 2011-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.

Name: Anonymous 2011-08-29 20:03

You should start with working code. Here is an example from a graphics course. http://www.cse.nd.edu/courses/cse40166/www/resources/triforce.tar.gz

Name: Anonymous 2011-08-29 20:08

>>7
2D in opengl is really 3D orthographic projection.

Name: Anonymous 2011-08-29 20:10

When you do that second glLoadIdentity, you're undoing your glOrtho.

Name: Anonymous 2011-08-29 20:34

Pronounced 'glor-fo'.

Name: Anonymous 2011-08-29 21:15

>>10
I'll project your ortho, NOMSAYN?

Name: Anonymous 2011-08-29 21:18

>>10
Not OP, but now I am confused. How is it that the quad still gets rendered like you would in ortho projection?

Name: Anonymous 2011-08-29 21:25

learning OpenGL
FFP

Nope.

Name: Anonymous 2011-08-29 21:36

>>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: Anonymous 2011-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/

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List