5

I was and have been looking for an example on how to make a game menu. For example i want to have the application open to the menu. From there it would either open "play game" "Show Credits" "Exit".

Everything i have seen so far is for popup menus..

So the answer iam looking for is about use "states" like pause state, game state , ect.. But i cant figure out the layout this should be or how it should be used..Nor how to create the MenuState and cant find an example anywhere

Using glut and freeglew

genpfault
  • 51,148
  • 11
  • 85
  • 139
Glen Morse
  • 2,437
  • 8
  • 51
  • 102
  • 1
    are you asking how to draw text using opengl ? Here's a function you can use http://stackoverflow.com/questions/538661/how-do-i-draw-text-with-glut-opengl-in-c – nurettin Mar 02 '13 at 11:32
  • Well yes and no, I ask cause i hear alot about use "states" like pause state, game state , ect.. But i cant figure out the layout this should be or how it should be used.. and cant find an example anywhere – Glen Morse Mar 02 '13 at 11:52
  • Are you asking how to stop the game interface, show a menu, and when the menu is gone, start the game interface again? – nurettin Mar 02 '13 at 12:04
  • yes that would be one of the "states" – Glen Morse Mar 02 '13 at 12:12

1 Answers1

6

GUI Implementation

The basic idea is to create some textured quads in front of the camera and when the user clicks on the screen translate it into world space and find out which quad, and therefore which button, they clicked on. You may find that orthographic projection is the way to go here.

The exact implementation will depend on how you are interacting with the keyboard and mouse (GLUT, SDL etc.).

You may want to consider using a GUI framework such as CEGUI, FLTK or similar though as this can often be a complex task.

Game States

Game states are a simple way to abstract from the passage of a uesr through the game. It allows you to model the different areas of the game as nodes on a DFA or by using a stack. You can then implement this by creating an api that GameState objects inherit from. you can then implement different kinds of game states by derriving classes from this interface.

The interface itself can provide methods to allow the state to be notified when it is made active and when it is 'paused' and similar.

If using a DFA to manage state then there is one active state that represents the current node the DFA. The state can then select a new state to go to based on the input to the game (Cliking the play button in the menu etc.).

If you are managing game states using a stack it is a little different. First you push the menu state onto the stack and then when a level is selected you can push that onto the stack too. When the level is over the state is popped from the stack and the user returns to the main menu state.

An example of a simple game engine is here: https://bitbucket.org/iwillspeak/thulium/src. GameState is the base class for game states. These are managed by the GameStateFactory. SampleState is a sample game state implementation.

Will
  • 4,585
  • 1
  • 26
  • 48
  • I am using GLUT. but maybe make question a little more clear.. ill update – Glen Morse Mar 02 '13 at 11:53
  • Do you know of any example of this? but yes your answer is exactly what iam talking about – Glen Morse Mar 02 '13 at 12:13
  • 1
    I'ts not perfect but maybe this could help you: https://bitbucket.org/iwillspeak/thulium/src. Take a look at GameState.h and GameState.cpp – Will Mar 02 '13 at 12:14
  • seems this was not a question.. to bad cause you deserve the credit for the answer... I assume the people that closed it dont know what states are so they vote to close it. – Glen Morse Mar 03 '13 at 04:27