PDA

View Full Version : Temporaryly disable and re-enable gluPerspective?



darkrappey
11-25-2006, 04:59 PM
I'm working on a Heads Up Display for my application. I need to be able to acuratly place quads on the screen. This was easy before I used gluPerspective but now that it is enabled, -1x, -1y is no longer an exact corner.

Is there a way to disable gluPerspective while drawing the HUD and re-enable it for the rest of geometry?

Komat
11-25-2006, 07:01 PM
The gluPerspective is nothing that is enabled or disabled. That function simply modifies currently set matrix so you can redefine that matrix at any time.

To draw the hud you might use something like:


// Configure orthographic projection.

glMatrixMode( GL_PROJECTION ) ;
glLoadIdentity() ;
gluOrtho2D( -1.0, 1.0, -1.0, 1.0 )
glMatrixMode( GL_MODELVIEW ) ;

// Draw HUD quads.


// Configure perspective projection

glMatrixMode( GL_PROJECTION ) ;
glLoadIdentity() ;
gluPerspective ( desired parameters )
glMatrixMode( GL_MODELVIEW ) ;

// Draw the geometry

darkrappey
11-25-2006, 10:18 PM
Ok I'll try to figure it out using Ortho2D thanks.

zeoverlord
11-26-2006, 05:26 AM
How about some ready made code, it works like a charm.


void ViewOrtho(int x, int y) // Set Up An Ortho View
{
glMatrixMode(GL_PROJECTION); // Select Projection
glPushMatrix(); // Push The Matrix
glLoadIdentity(); // Reset The Matrix
glOrtho( 0, x , y , 0, -1, 1 ); // Select Ortho Mode
glMatrixMode(GL_MODELVIEW); // Select Modelview Matrix
glPushMatrix(); // Push The Matrix
glLoadIdentity(); // Reset The Matrix
}

void ViewPerspective(void) // Set Up A Perspective View
{
glMatrixMode( GL_PROJECTION ); // Select Projection
glPopMatrix(); // Pop The Matrix
glMatrixMode( GL_MODELVIEW ); // Select Modelview
glPopMatrix(); // Pop The Matrix
}

darkrappey
12-02-2006, 11:47 PM
That looks like it should work, thanks. I'll try it out.

darkrappey
12-04-2006, 05:33 PM
Well I thought I understood the code you gave me but I can't seem to get it to work. The HUD quads don't show at all in orthographic. I tried switching the Z location of the quads from negative to positive and turning off back-face culling.

I call ViewOrtho(config.resX, config.resY) imedietly before drawing the HUD and call ViewPerspective before drawing worldly geometry.

-thanks in advance