Ortho mode - what's wrong?

Hello.
I’ve have a question about switching beetwen projection modes. The problem is that when I want to jump to the ortho mode and then draw something nothing happens. I have no idea why is that so because I’ve copied these lines just straight from a tutorial - look :

glMatrixMode(GL_PROJECTION_MATRIX);
glPushMatrix();

glLoadIdentity();
glOrtho(0, Width, 0, Height, 1, -1); // Switch to ortograhpic projection

glMatrixMode(GL_MODELVIEW);

/* blah blah blah goes here */

glMatrixMode(GL_PROJECTION_MATRIX);
glPopMatrix();
glMatrixMode(GL_MODELVIEW); // Back to the perspective

Is there anything wrong? I don’t think I’ve screwd up drawing of primitives…

It’s GL_PROJECTION, not GL_PROJECTION_MATRIX.

OK

Thanks

Let’s look at your code it seems a bit strange:

// Start
glMatrixMode(GL_PROJECTION); // not GL_PROJECTION_MATRIX
glPushMatrix(); // Save projection matrix

glLoadIdentity(); // Clear project matrix
glOrtho(0, Width, 0, Height, 1, -1); // Switch to ortograhpic projection

glMatrixMode(GL_MODELVIEW); // Draw matrix state unknown
// We have not use glLoadIdentity for Modelview so matrix in state of last call to draw world

/* blah blah blah goes here */

glMatrixMode(GL_PROJECTION); // Back to Projection matrix
glPopMatrix(); // Restore projection matrix from last Push command
glMatrixMode(GL_MODELVIEW); // Back to the perspective
// Modelview state unknown???

Is there anything wrong? I don’t think I’ve screwd up drawing of primitives…

I don’t think it is primitive problem, more a initializing the diffrent matrix modes.

Also not enought code to see if there are any other problems. post more of the display routine code.

[This message has been edited by nexusone (edited 04-03-2003).]

[This message has been edited by nexusone (edited 04-03-2003).]

Originally posted by Orzech:

glOrtho(0, Width, 0, Height, 1, -1); //

You reversed the values for the near and far plane. Try :
glOrtho(0, Width, 0, Height, -1, 1);

try with a glLoadIdentity() instead of a push/pop matrix, and create the matrix from the blank template.

[b][i]
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Width, 0, Height, 1, -1);

glMatrixMode(GL_MODELVIEW);
glIdentity();
// BLA BLA BLA ECT…

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glPerspective(…);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// BLA BLA BLA again…

[/i][/b]

maybe you don’t need the glLoadIdentity() after the glMatrixMode(GL_MODELVIEW), but usually, the ‘camera’ is different from perspective views and orthographic views. That could screw up things too.

[This message has been edited by oliii (edited 04-03-2003).]

Haha! Ok guys, thanks for your help but reply of Bob (first post) already solved my problem. It was just a tiny bug. I used GL_PROJECTION_MATRIX insted of GL_PROJECTION. That’s all. Everthing works just fine.

Thanks

Orzech