Advertisement

Switching GL Projections

Started by February 13, 2003 04:04 AM
2 comments, last by WildFuse 22 years ago
Hi all What is the best way to swap projections from Perspective to 2d, in order to draw for example a HUD. glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,100,0,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); I then switch back to projection, but it doth not worth to well Maybe missing viewport info ??
I do it so:

// =================================
void CEngine::Set2D()
{
if (!m_In2DMode)
{
// We disable the depth test
glDisable(GL_DEPTH_TEST);

// We choose the projection matrix
glMatrixMode(GL_PROJECTION);

// We save the patrix
glPushMatrix();

// We reset the matrix
glLoadIdentity();

// Scrren size
glOrtho(0, gOpenGL->GetWidth(), 0, gOpenGL->GetHeight(), -1, 1);

// We choose the modelview matrix
glMatrixMode(GL_MODELVIEW);

// We save the matrix
glPushMatrix();

// We reset the matrix
glLoadIdentity();

m_In2DMode = true;
}
}

// =================================
void CEngine::Set3D()
{
if (m_In2DMode)
{
// We load the saved matrix
glPopMatrix();

// We choose the modelview matrix
glMatrixMode(GL_MODELVIEW);

// We load the saved matrix
glPopMatrix();

// We enable the depth test
glEnable(GL_DEPTH_TEST);

m_In2DMode = false;
}

}
Advertisement
Thanks a lot, there was however a prob in your code

you were not popping your projection matrix back, but I fixed it

Thanks a lot again man
Thanks for this bug report

This topic is closed to new replies.

Advertisement