user1799323
user1799323

Reputation: 659

OpenGL - pausing an animation with a keystroke

I need to pause the entire animation indefinitely until the user presses the same key again. I have a crude pause using usleep:

#include <unistd.h>

...

if(key == 'p')
    usleep(200000);

Ideally though, I want the time to be indefinite until p is pressed again (and usleep measures in milliseconds so it's not very useful) Can someone point me in the direction of how to do this?

Upvotes: 1

Views: 4101

Answers (1)

Aesthete
Aesthete

Reputation: 18848

static bool paused = false;
if(key == 'p')
  paused = !paused;

// Somewhere in your main loop.
if(!paused)
  Render();

You'll also probably want to try checking for key up and not key down, otherwise you'll pause and resume very rapidly.

Upvotes: 5

Related Questions