
Switching GL Projections
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;
}
}
// =================================
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;
}
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement