Jump to content
  • Advertisement

Archived

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

Agape

Registering just one click with GLUT

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!