I have an OpenGL(3.3)+GLEW application. I want to draw a black vertical rectangle at the left side of the window for writing some information on it, like fps (I use GLEW function for drawing text).

I have a common pipeline, like this:

 m_transformation = PersProjTrans * CameraRotateTrans *
           CameraTranslationTrans * TranslationTrans * 
           RotateTrans * ScaleTrans;

I know how it works, but I can't figure out how to draw a projection of the rectangle on the window, like 2d.

I would be glad to any advise.


You can use an Orthographic projection matrix to transform your vertexes. Then you can simply provide your triangle verts in terms of screen pixels, e.g.: a vertex at (0,0), one at (10, 0) and one at (5, 10).

Here's another reference of OpenGL matrices, with a lot of maths. Make sure to do a search for "OpenGL orthographic projection" and "2D drawing with OpenGL" and you should find a lot of useful information also.

I should also note that to overlay 2D over 3D, you'll have to disable depth testing before drawing the 2D parts. I.e.: glDisable(GL_DEPTH_TEST);.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.