4
\$\begingroup\$

I am writing a simple game in c++ using opengl in a windows system.

I have the scene and I need some informative text to appeared to the left top/bottom of the screen

I am printing these messages with a little plane and the text on it, but I want them to be aligned at the corners of the screen.

So I've read this question here and I thought it seemed quite good and closer to my needs.

So, this is some of my code already used:

In init function of openGL:

glShadeModel (GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);  
glClearDepth(1);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

In the Resize function:

if (window_height == 0) window_height = 1;
glViewport(0, 0, window_width, window_height); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity();
gluPerspective(60.0, (float)window_width/(float) window_height, 1.0, 550.0);

And finally in the render function:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); 
glLoadIdentity();
glTranslatef(0, 0, -250); //is used for making the scene visible
RenderScene();
glutSwapBuffers();

I've tried using the ready3D() and then RenderScene() functions but the scene looked a lot different to what I was aiming.

How can I achieve this simple HUD (printing messages aligned to the window's corners)?

Edit #1:

This is what I see (terrain and message below): enter image description here

I want the message to be aligned at the bottom left corner as well as other messages.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Please add some images of what you expect and what you get so we can see whats wrong. \$\endgroup\$
    – Roy T.
    Feb 21, 2013 at 21:40
  • 1
    \$\begingroup\$ @RoyT.: I've added the current state and a description of how I want it to look like. \$\endgroup\$
    – Chris
    Feb 21, 2013 at 22:29
  • \$\begingroup\$ Also note that you're using OpenGL in the old/deprecated way. A good read on the new way is this free book arcsynthesis.org/gltut/index.html \$\endgroup\$
    – Roy T.
    Feb 22, 2013 at 9:15
  • \$\begingroup\$ @RoyT.: I have been told about it Roy, but this is what we were taught in class. I will surely check this for my next project. \$\endgroup\$
    – Chris
    Feb 22, 2013 at 9:49
  • \$\begingroup\$ Ah man I hate it when they teach terribly outdated stuff in class. Be sure to tell your teacher that his/her approach is frowned upon for over 5 years now (in a friendly way :P). \$\endgroup\$
    – Roy T.
    Feb 22, 2013 at 10:34

1 Answer 1

3
\$\begingroup\$

You should set the projection matrix properly first, from OpenGL FAQ 9.030,

To set up a 2D projection, you need to change the Projection matrix. Normally, it's convenient to set up the projection so one world coordinate unit is equal to one screen pixel, as follows:

 glMatrixMode (GL_PROJECTION);
 glLoadIdentity ();
 gluOrtho2D (0, windowWidth, 0, windowHeight);

You can have more details from the OpenGL FAQ

\$\endgroup\$
1
  • \$\begingroup\$ So I've managed to enable my 2D hud/gui, but I cannot manage to restore or even display only my scene (disabled the render2D) in 3D. Could you please tell me in which order should I write the calls in ready3D()? \$\endgroup\$
    – Chris
    Feb 22, 2013 at 11:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .