draw a "fullscreen" square

Started by
2 comments, last by widggman 12 years, 10 months ago
The title might look a bit weird... sorry about that.

What I mean by "fullscreen" is the whole OpenGL surface where you can render your scene. What i want to do is draw a perfect square that will cover the whole scene. The most important, i want it to be adapted if the window is resized.

So, let say my ratio of Width / Height is equal to X. Then I want to draw a square, centered at the middle, with sides of length max(1, X). And I want to know the right geometry for it. Is it better to use glScale or glTranslate ? And let say that the near distance is at Y.

Thanks.

Advertisement
If this is for the purpose of deferred or post process effects, or GUI then you might be best off splitting your render process into two stages, first where you draw all 3D geometry using perspective projection matrix, camera view matrix etc, and a second where you change to an orthographic projection matrix, depth test and write switched off, camera view identity matrix and draw all your 2D geometry.
Basically you can set up a glViewport(0, 0, screenWidth, screenHeight) view matrix, and a gluOrtho2D(0, screenWidth, 0, screenHeight) projection matrix, and then your geometry units will map straight onto device screen units (don't use any model/view transform matrix).
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//Render a quad
{-1, -1, 0} to {1, 1, 0}

and that's all!

you might want to also disable depth writing and testing with glDisable(GL_DEPTH_TEST) and glDepthMask(FALSE);
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);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//Render a quad
{-1, -1, 0} to {1, 1, 0}

and that's all!

you might want to also disable depth writing and testing with glDisable(GL_DEPTH_TEST) and glDepthMask(FALSE);


Thanks!

This topic is closed to new replies.

Advertisement