Sign in to follow this  
Tomassacre

Game menu in OpenGL

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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);


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this