Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Registering just one click with GLUT

This topic is 5228 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

OK, in my program I want to place an object with each left-mouse click. Problem is that GLUT does an action with both the pressing and releasing of the mouse button, placing two objects on each click. Here is my code:

void myMouse(int button, int buttonstate, int xx, int yy)
{

if(button == GLUT_LEFT_BUTTON)
{
if(GLUT_UP)

{
doSomething()
glutPostRedisplay();

}
}

}

(note that the if statement doesn''t do anything, apparently)

##### Share on other sites
You need to say if(buttonstate == GLUT_UP) rather than if(GLUT_UP).

[edited by - tiffany_smith on February 26, 2004 12:13:20 AM]

##### Share on other sites
if(GLUT_UP)

GLUT_UP is a constant. If that constant is zero, then the test is always false. If the constant is non-zero then the test is always false.

You need to test it against a variable, like, oh, I don''t know, buttonstate maybe?

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

##### Share on other sites
if(buttonstate==GLUT_UP){etc etc}

"Give a man a fish and he will eat for a day, drown a man in the water and the fish will eat for a week!

[edited by - cmptrgear on February 26, 2004 12:14:31 AM]

##### Share on other sites
quote:
Original post by Agape
if(GLUT_UP)    {    doSomething()    glutPostRedisplay();    }

As long as GLUT_UP is non-zero (and it is not zero), the
if-block will execute.

You probably meant to do:

if (buttonstate == GLUT_UP)    {    doSomething()    glutPostRedisplay();    }

Kami no Itte ga ore ni zettai naru!

##### Share on other sites
It''s been a long night...

Thanks, I appreciate the quick help.

##### Share on other sites
GLUT_UP always evaluates to non-0, so that if() is always true.

If you turn on all warnings, your compiler will probably warn you about this. Thus, you should always turn on all warnings, and fix all the warnings it gives you.

• 18
• 11
• 16
• 9
• 49
• ### Forum Statistics

• Total Topics
631395
• Total Posts
2999780
×