Game menu in OpenGL

Started by
4 comments, last by kaysik 19 years, 5 months ago
Hi: Im working on this Final Fantasy like battle scene in OpenGL, where I have a couple of good guys and an enemy. The scene looks good but Im lacking a fundamental part in FF-like games (and RPG's in general) and thats the Menu, you know, where the character name's and HP appear and all that. I've been looking around but can't seem to find a convincent way to put 2d graphics blended onto an OpenGL scene, I tried puting a Billboard infront of the camera but I didnt think it looked fine. The question is, how can I create a 2D menu in an openGL scene? Thanx, Tom
Advertisement
Quote:Original post by Tomassacre
Hi:
Im working on this Final Fantasy like battle scene in OpenGL, where I have a couple of good guys and an enemy. The scene looks good but Im lacking a fundamental part in FF-like games (and RPG's in general) and thats the Menu, you know, where the character name's and HP appear and all that. I've been looking around but can't seem to find a convincent way to put 2d graphics blended onto an OpenGL scene, I tried puting a Billboard infront of the camera but I didnt think it looked fine.
The question is, how can I create a 2D menu in an openGL scene?

Thanx,

Tom

I believe what you're looking for is how to render with orthographic projection. Try searching 'orthographic projection' and you should get some topics discussing this.

On a side note, instead of doing it just like FF and the rest of them, why not try to come up with something original and creative and interesting?
Because first I want to learn how to do things and then I'll start doing new things. Thnx for the ortho tip, I'll search more on that.
You could also do it with glDrawPixels.
Disclaimer: "I am in no way qualified to present advice on any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)"
Quote:Original post by Mazer
On a side note, instead of doing it just like FF and the rest of them, why not try to come up with something original and creative and interesting?


Hey ma' how about some cookies?

no dice.
Roger that, lets run like hell!
To get openGL into "2D" and back to normal mode you can use this code:

   // to get to 2D   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   gluOrtho2D(0.0, (GLfloat)window_width,            0.0, (GLfloat)window_height);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   // render HUD/GUI here   // get back to normal 3D mode   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   gluPerspective(60, (GLfloat)window_width/         (GLfloat)window_height, NEAR_PLANE, FAR_PLANE);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();


That will allow you to render nice 2D quads over whatever is on screen currently. The way I do it is split the code into two functions such as go2D() and go3D(), then have a game loop like so:

   while (!done)   {      // basic update      update()            // goto 2D mode and render the game      go3D()      renderGame()      // goto 2D mode and render the gui/menu/hud      go2D()      renderGui()   }


Look up bitmap fonts (NeHe has a good tut on it I believe) but basically you do something like so:

   // disable depth test so the hud is always drawn over everything   glDisable(GL_DEPTH_TEST);   // enable blend so that the hud alpha'ed   glEnable(GL_BLEND);   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);   glColor3f(1.0f,1.0f,1.0f);   // draw your hud textre   // l, r, t, b are in screen pixle co-ordinates for left   // right, top and bottom.  If you want to cover the whole   // screen then you'd use (for a 1024*768 res setup)   // l = 0, r = 1024, t = 800, b = 0   glBegin(GL_QUADS);      glTexCoord2f(0.0f, 0.0f); glVertex2i(l, b);      glTexCoord2f(1.0f, 0.0f); glVertex2i(r, b);      glTexCoord2f(1.0f, 1.0f); glVertex2i(r, t);      glTexCoord2f(0.0f, 1.0f); glVertex2i(l, t);   glEnd();   // Draw text over background pic here or whatever   // reset modes   glDisable(GL_BLEND);   glEnable(GL_DEPTH_TEST);

This topic is closed to new replies.

Advertisement