1
\$\begingroup\$

I have this program that starts a loop when the key is pressed

The problem is that when i start the loop, i want to be able to stop it halfway with my mousepress.

The problem is that it doesn't register my mousepress until my loop is done.

How do I stop it halfway if the mouse was pressed in my loop? I tried a flag, if(mousePressed) but the flag doesnt change until the loop is done

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Random guess: are you polling the event queue anywhere in that loop? \$\endgroup\$ – thedaian Oct 3 '11 at 14:09
2
\$\begingroup\$

You have to register the function that handles the callback function to be executed when a button is mouse pressed during your display() loop. This has to be done before running the main loop, when you are initialising everything that GLUT requires.

glutMouseFunc (MouseButton); 

Then you need to define the callback function itself, for example, something like this.

void MouseButton(int button, int state, int x, int y)
{
  // Respond to mouse button presses.
  // If button1 pressed, mark this state 

  if (button == GLUT_LEFT_BUTTON)
    {
      g_bButton1Down = (state == GLUT_DOWN) ? TRUE : FALSE;
    }
}

Note that g_bButton1Down is the global variable that you have to check to see if the mouse button is being pressed or not inside your main display() GLUT loop.

Take a loop at the glutMouseFunc specifications.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks. I was trying to change a flag while I was inside a drawing loop (not an event loop). I failed. So i ended up changing my loop to be a timed function and since every time my timed step would end it would allow the mouse and keyboard functions to register changes it worked perfectly \$\endgroup\$ – Andre Oct 3 '11 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.