Opengl layers?

Started by
2 comments, last by OrangyTang 16 years, 7 months ago
Is it possible to make different layers in openGL? because i have an 3d-scene, and i want to create an 2d-layer in front of it, so i can make things like buttons and text fields in front of the scene. Is there anyone who knows how to do this? Greetz, Leon
Advertisement
glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(0.0, windowwidth, 0.0, windowheight, -1.0, 1.0);glMatrixMode(GL_MODELVIEW);glDisable(GL_DEPTH_TEST);glDepthMask(GL_FALSE);


You can tweak the values for glOrtho to your liking.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
You mean something like:

glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0f, (GLfloat)1920/(GLfloat)1200, 0.1f, 2000.0f);glMatrixMode(GL_MODELVIEW);glBegin(GL_QUADS);(3d gl objects)glEnd();glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(0.0, windowwidth, 0.0, windowheight, -1.0, 1.0);glMatrixMode(GL_MODELVIEW);glDisable(GL_DEPTH_TEST);glDepthMask(GL_FALSE);glBegin(GL_QUADS);(2d gl objects)glEnd();


?

That's the usual way of doing it (although you don't have to draw all your objects in a glBegin/End call). Also remember you need to reenable the depth test and depth writing at the start of the next frame otherwise the state will carry over.

This topic is closed to new replies.

Advertisement