Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
1  
Please add some images of what you expect and what you get so we can see whats wrong. –  Roy T. Feb 21 '13 at 21:40
1  
@RoyT.: I've added the current state and a description of how I want it to look like. –  Chris Feb 21 '13 at 22:29
    
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 –  Roy T. Feb 22 '13 at 9:15
    
@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. –  Chris Feb 22 '13 at 9:49
    
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). –  Roy T. Feb 22 '13 at 10:34
show 1 more comment

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
    
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()? –  Chris Feb 22 '13 at 11:04
    
I've done it..Thank you neo! –  Chris Feb 22 '13 at 11:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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