Question

i'm continue my dialog with openGL and c++ and for a now i want to make "scenes", that will change each other. for example screen with button "go next", i push button and then begin game. What is the best approach with openGL in c++ for this ? The main question is what make with glut initialization commands like :

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(0,0);
glutCreateWindow("Puzzle quest!");

// Registration
glutDisplayFunc(Draw);
glutIdleFunc(Draw);

Is i need to implement this method in both classes, or only in one, and then only "show start button/ hide game functionality, hide start button/ show game functionality+start timer" ?

Was it helpful?

Solution

I do not mess with screen settings during scene/mode changes. Screen setings is changed on resize of the OpenGL window not on some button event...

You have to write your visualization and UI logic stuff dependent on some variables for example:

enum _game_screens_enum
 {
 _game_screen_main_menu=0,
 _game_screen_game,
 _game_screen_game_over,
 _game_screen_help,
 _game_screen_intro,
 _game_screen_redefine_keys,
 _game_screen_high_score,
 _game_screen_exit,
 };

int screen=_game_screen_main_menu;

Now in draw,update and UI handling functions just add appropriate ifs for example:

void draw()
 {
 if (screen==_game_screen_main_menu)
  {
  // draw main menu ...
  }
 else if (screen==_game_screen_game)
  {
  // draw in game screen stuff...
  }
 else ...
 }

And that is it ...

OTHER TIPS

Are you looking for a fade effect or some sort of transition where they are blended? Fade effect should be easy if using alpha channel... enable blend... draw black quad in front of everything as its alpha value increases from 0 to 1 over whatever time frame you want the fade to occur. The fade in would be the opposite. Not sure about the blending scenes effect... maybe accum buffer, or read pixels and then draw pixels if you can change alpha values.

Otherwise, glutDisplayFunc is the correct way to switch between scenes/drawing functions. Try just fading effect, it could be of great help.

You should only initialize glut once.

Normally, the display and idle callbacks would do different things depending on what state you're in.

On a high level:

void idle()
{
   if (showingMenu)
      menu.idle();
   else
      currentScene.idle();
}

You could do it by switching functions, but I think that makes debugging more difficult.

(You should probably not use the same function for drawing and idling, though.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top