Skip to main content
gamedev.net
🔒 Locked

Game menu

Started by Dunge 12 replies 1k views
Original Post
Dunge
Dunge
What is the best way to create a menu for a game? I would like something like you know some 2D button (from bitmap files), some text and at the back a 3D scene... how should I do it? Use projection for both or change ortho/projection in the same frame? Use raster graphic with glDrawPixels and font text (wglUseFontBitmap with a CreateFont thingy) or use textured quads/triangles with with the bitmap I want on it and a bitmap file with all the letter to decode text and draw it as texture? Thx..
Zealot
Zealot
Well, I was planning on using an AVI file for this, with different frames being states for buttons and such.

Just render the 3d scene and copy it to a bmp file, then do whatever to make the menu, and create an AVI with it.

En taro Adun!
Doom to all who threaten the homeworld!
*Protoss Zealot - Starcraft*
----------------------------------------------------------You know, I might as well go ahead and say I can't fix the problem... because that's when I figure out how.
Dunge
Dunge
That''s the worst idea I''ve seen
Dunge
Dunge
lol... hey I want to make a simple menu you know a square who is written "New Game" on it who change color when it is selected and etc... I have the .bmp for each state that''s not the trouble and AVI is a file format for movies with compression and all.. why would I use that if I can only bind another bitmap to the texture? Damn do you think that menus in game like "enter commercials games name here" are made with AVI''s file?
xria
xria
I''m using textured quads in ortho mode to do my menus and 2d overlays, and I really haven''t run into any problems to make me think this method is a bad Idea. It Looks really nice and is very easy to create and use. And Most importantly its SIMPLE and FAST.


BauerGL
BauerGL
Aah interesting topic (at least for me right now ). They way I did it on my little "game" that I worked on some week ago was like this (whis in no way is good).

first I initialize the the menu (loading bmp's, setting up view, etc)

then I have the menu loop:


    
int CGame::MenuLoop()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

CVector3D startgame = CVector3D(1.0f, 0.0f, 0.0);
CVector3D quitgame = CVector3D(1.0f, 0.0f, 0.0f);
CVector3D credits = CVector3D(1.0f, 0.0f, 0.0);

static float hold = 0.0f;
hold -= m_pTimer->GetDeltaTime();
if(hold < -0.5f)
hold = 0.0f;

switch(m_Menupointer)
{
case MENU_STARTGAME:
{
startgame = CVector3D(1.0f, 1.0f, 0.0f);

if(KeyDown(VK_RETURN))
return 0;
if(KeyDown(VK_DOWN) && hold < 0.0f)
{
m_Menupointer = MENU_CREDITS;
hold = 0.2f;
}
}break;
case MENU_CREDITS:
{
credits = CVector3D(1.0f, 1.0f, 0.0f);

// Show credits page


if(KeyDown(VK_DOWN) && hold < 0.0f)
{
m_Menupointer = MENU_QUIT;
hold = 0.2f;
}
else if(KeyDown(VK_UP) && hold < 0.0f)
{
m_Menupointer = MENU_STARTGAME;
hold = 0.2f;
}
}break;
case MENU_QUIT:
{
quitgame = CVector3D(1.0f, 1.0f, 0.0f);

if(KeyDown(VK_RETURN))
return -1;
if(KeyDown(VK_UP) && hold < 0.0f)
{
m_Menupointer = MENU_CREDITS;
hold = 0.2f;
}
}break;

default: break;
}

glColor3f(startgame.x, startgame.y, startgame.z);
m_pMenuGui->DrawTexturedQuad(CVector2D(272.0f, 95.0f), CVector2D(528.0f, 127.0f), m_pMenuTexs[0].texID);

glColor3f(credits.x, credits.y, credits.z);
m_pMenuGui->DrawTexturedQuad(CVector2D(272.0f, 53.0f), CVector2D(528.0f, 85.0f), m_pMenuTexs[2].texID);

glColor3f(quitgame.x, quitgame.y, quitgame.z);
m_pMenuGui->DrawTexturedQuad(CVector2D(272.0f, 10.0f), CVector2D(528.0f, 43.0f), m_pMenuTexs[1].texID);

return 1;
}


This makes a simple "list" of bitmaps (start game, credits, quit game). And I have a state which tells if the current selection is start game, credits or quit. It then looks for that state and if the state is for example "start game" then the colour for the start game bitmap is set to yellow. After that it looks for any keypresses (which is handled in a nutty way, not the KeyDown() but the m_Menupointer thing) and changes the selection accordingly. It then renders the bitmaps with the apropriate color. Note that the .bmp's have to be white colored in order to change the colors this way.

And that's how I did it, and I aint saying that you should use it, but I think that some parts of it are more or less good.

Edit: If anyone wants to you are very very welcomed to point down improvements on "my" method. I know it's probably a horrible way to do it, but it is the best that I have done so far (haven't tried alot though).

[edited by - BauerGL on August 4, 2002 8:56:54 AM]
_the_phantom_
_the_phantom_
quote:
Original post by Dunge
lol... hey I want to make a simple menu you know a square who is written "New Game" on it who change color when it is selected and etc... I have the .bmp for each state that''s not the trouble and AVI is a file format for movies with compression and all.. why would I use that if I can only bind another bitmap to the texture? Damn do you think that menus in game like "enter commercials games name here" are made with AVI''s file?


first off, please dont insult my inteligance, i know full well how buttons and things are done with current commerical games, however I dont see any reason why the idea of putting them in an AVI file is a bad one, later on it could be usefull for constantly animating buttons or such like, just ''cause an idea doesnt fit in with what is currently about dont dismiss it out of hand, I''m sure the person in question had a good reason for wanting to use an AVI file.

personaly, your attitude puts me off the idea of helpping you in future, because whatever I might well present you will probably right off as ''the worst idea you''ve ever seen'' with out even considering that i might well have a perfectly good reason for doing things that way

Dunge
Dunge
_the_phantom_ : I didn''t say this guy had a bad reason of using AVI file, I just said it really don''t fit with what I want to do, I asked a question, don''t want to know what someone else did for a different thing

BauerGL : At least you are on the subject The way you are doing it is what I though I would do because I heard raster is very slow.. but like you said you are not completly sure if this is the best way, and nor am I Sorry if I can''t help you to improve your method but I''ll use a bit of your code for mine Thanks..
BauerGL
BauerGL
Dunge: Hehe feel free to do so, although I surely won''t recommend it. I''m working on a rebuild of my game now and I''m wondering alot of how to implement a good menu. Good as in good coded as in good design. So I asked around a bit and someone said to use different classes. So in my game I have a Menu class, and the menu class has some Button classes. And the Button classes share a static member which tells which of the Button''s are chosen. They also have a function to draw themselves, and a color variable (like I used, kinda). That''s as far as I have come so far, haven''t gotten to implement it yet. If you come up with something please let me know cause this is something I need tips/experience with.
BauerGL
BauerGL
Anyone who have done this before maybe could post some tips/ideas? It be very grateful if they did
Xero-X2
Xero-X2
I just used a drawfunction for the menu and a two state varibles one for which page im on and the other for the item your on, then I just go from there and draw what ever the page looks like and any of its effects then I draw the highlight effect like I draw that peice of text in a diffrent color or a box around it or what ever. its not the simpleist or the fastest but you can make a menu with nice animations demos, or anything you want for that matter. If you want to do this I suggest that you make sure that the draw and the button stuff is diffrent from the rest of the game just to make sure its less confusing when you ever need to look at it again. thats the mistake I made because I was in to much of a rush.
"I seek knowledge and to help those who also seek it"
xria
xria
What I did was make a Gui class and a Button class. The button class stores the Button Texture, x/y offset, width and height of the button, and a function pointer called "OnPress". Make a list of Button''s in the Gui class, and make a Gui member function to create and add a button to the list. Then Just make Gui::render function to go trough the list and draw each button, and a GUI update function to compare the mouse coords to each Button''s "box". If the mouse falls within the button''s box, it calls OnPress if the mousebutton is down, or just changes the box''s color if the mousebutton isn''t down.

Set up a class structure sorta like that and you can create buttons once and let the class handle the rest. Also remember that you gotta resize your menus based on resolution, which will pose a problem without some sort of organized system in place.
Hell, I''m still having little quirks with my Gui resizing bitmap fonts. Damned Bitmap Fonts. I hate those little bastards.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.