Thread: State Management

  1. #1

    State Management

    can anyone please explain to me how to do state managment in OpenGL? if you can please contact me on AIM or e-mail.

    AIM: Seanrru123
    E-mail: [email protected]

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    57
    Or even better, contact me. AIM: Gamer Tazar... I am the one hes asking this for. For more information on what he means:

    In a game in OpenGL, how would you make it go from the Title Screen in the beginning, to the menu. Then to the actual game when they select it. And when they get past the first level, load the second. Does anyone have any code that i could see?
    Thanks.
    Language: C++
    Compiler: Visual C++ 6.0
    Currently Working On: Simple OpenGL aspects

  3. #3
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    It shouldn't matter what graphics library you use. This will work with any game code, regardless of graphics library, OS, platform, etc.

    Enumerate 2 variables to hold Major Game states and Minor Game states. In your main game loop use a switch to test for the major states, then a sub switch to test for the minor states (I actually only test for the major states in my main game loop, then calls a function (seperate function for each major state) that has a switch that checks for minor game states).

    Here's a generic example:
    Code:
    //global declares 
    enum GameState
    {gsIntro,gsMenu,gsSettings,gsCombat,gsOptions};
    
    enum SubState
    {ss1,ss2,ss3,ss4,ss5,ss6};
    
    GameState MajorState;
    SubState MinorState;
    
    //main game loop
    void GameLoop()
    {
       switch(MajorState)
      {
       case gsIntro:
       {
           GetIntroInput();	
           DoIntroBlt();
        }break;
       case gsMenu:
       {		
         GetMenuInput();
         DoMenuBlt();
        }break;
       case etc. etc. etc.....do the same
      }
    }
    
    //sample generic minor state check function
    void GetMenuInput()
    {
      switch(MinorState)
      {
        case ss1:
        {
          //get mouse/keyboard input for main menu buttons
        }break;
        case ss2:
        {
          //get mouse/keyboard input for options menu buttons
        }break;
        case etc. etc. etc.....
      }
    }

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    A state machine is a language independent concept. Read more about state machines here:

    http://www.redbrick.dcu.ie/academic/...ter08.doc.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finite State Machine
    By ArlexBee-871RBO in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2008, 11:59 AM
  2. Grammar to FSA to C code (Newbie)
    By aybe in forum C Programming
    Replies: 4
    Last Post: 02-29-2008, 02:10 PM
  3. input/switch statement issues
    By peanut in forum C Programming
    Replies: 5
    Last Post: 10-27-2006, 02:58 PM
  4. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  5. Finite State Machine Project Help
    By ryanbradley in forum C++ Programming
    Replies: 4
    Last Post: 03-06-2004, 10:23 AM