Thread: Pause in OpenGL, but don't stop drawing... ?

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    21

    Pause in OpenGL, but don't stop drawing... ?

    I've made a version of 2D Asteroids using OpenGL on a *nix system.

    I'm wondering how, after the player has cleared the field of rocks, to pause the game prior to displaying a new cluster of rocks. Basically, here are the sequence of events I want to achieve:

    - Player kills last asteroid,
    - Message pops up announcing graduation to a new level of the game for about 5 seconds. In the meantime, the ship is still able to fly around in the background, but no asteroids appear.
    - After the time of 5 seconds is up, the message disappears, and the field is repopulated with asteroids.
    - The game continues.

    I can use any of the pausing techniques discussed on the forums here, but simply pausing the operation of the program altogether obviously prevents the rendering of the ship to stop as well. I'd like the display cycle to continue.

    I hope I'm clear with the description of my problem. Thanks for any help.

    ~arker

  2. #2
    What, do you mean to pause the asteroids from coming at the end of the level? That's simple, just have a wave flag that flips on after 5 seconds of completion that basically tells your asteroid maker to do its thing, and after you created the last asteroid for your next level, flip it off.

    edit: plz, don't flip your code off where the flag is, I used it in a different sense.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    you could have a bool that you switch on when the player clears a level that prevents asteriods from being created. and then have a variable that holds the time that the level was completed. then, somewhere, check the time and whenever 5 seconds is up, switch the bool off to allow the new asteroids to be created.

    that sounded a little scrambled. maybe it would make more sense in pseudocode

    Code:
    bool player_won = false;
    int timer = 0;
    
    main loop
    {
       if ( player kills all asteroids && player_won == false )
       {
          player_won = true;
          timer = GetTickCount();
       }
    
       if ( all asteroids dead && player_won == false )
       {
           make new asteroids
       }
      
       if ( GetTickCount() - timer >= 5000 )
          player_won = false;
    }
    hope that made sense

    [edit]

    i used GetTickCount() which is a windows function. i dont know the equivalent *nix function, sorry
    I came up with a cool phrase to put down here, but i forgot it...

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You could also create a thread for the dialog box and it would execute while the your main process was running.

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    21
    Originally posted by ...

    Code:
    bool player_won = false;
    int timer = 0;
    
    main loop
    {
       if ( player kills all asteroids && player_won == false )
       {
          player_won = true;
          timer = GetTickCount();
       }
    
       if ( all asteroids dead && player_won == false )
       {
           make new asteroids
       }
      
       if ( GetTickCount() - timer >= 5000 )
          player_won = false;
    }
    Based on this, I chose something similar to the following:
    Code:
    #include <time.h>
    
    void myDisplayFunction(void)
    {
           if ( timer <= time(NULL) - 5 )
               rockDisplay();
           else
               printMessage("Starting next level");
    }
    Then, elsewhere in my code, once a level is cleared or any other pause is warranted,
    Code:
    timer = time(NULL);
    Certainly nothing fancy, quite simple, and maybe a little more portable. Works quite well too.

    Thanks all for the advice,
    ~arker

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you make games without drawing in OpenGL?
    By Jake.c in forum Game Programming
    Replies: 9
    Last Post: 02-11-2009, 10:00 AM
  2. drawing my ui (openGL)
    By hannibar in forum Game Programming
    Replies: 1
    Last Post: 04-12-2006, 07:24 AM
  3. OpenGL Linux Line Drawing Problem
    By swanley007 in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2006, 09:31 AM
  4. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM