I am working on mouse input for a game, I am having trouble with the left mouse button, the right button works perfectly.

I am using GLUT.

Here is my mouse event handling code.

I am using integers to keep track of the mouse button states. when the mouse button is released, this is represented by a continually decreasing negative value in iMouseLeftButton and iMouseRightButton.

When the button is depressed, it is represented by a continually increasing positive value.

Strange. GLUT mouseUps have been working for me. What OS version are you on? How soon after pressing the button do you get a GLUT_UP? Does the left button on your mouse generally work as expected in other applications?

It should work. My guess is that your iMouseLeftButton is being unintentionally modified incorrectly somewhere else in your program.

It is strange to me that you are continually increasing or decreasing those values, which suggests to me that maybe you are doing so to use them as some sort of timing values for animation of some sort. If that's the case, then maybe (wild guess) you're doing a iMouseLeftButton += 1; where you meant to be doing a iMouseLeftButton -= 1; instead.

I am using Leopard, and the mouse works fine for all other applications.

The mouseUp event is instantaneous, it occurs seemingly at the same time as i press the mouse down.

I have checked that the only place in the code which sets iMouseLeftButton to a negative value is that in the code that I've put up here. This is what makes me think that random GLUT_UP events are responsible, because the only code that changes iMouseLeftButton to a negative value is inside that IF statement.

And I've also checked that the code responsible for decreasing/increasing iMouseLeftButton is correct. It is exactly the same as that for iMouseRightButton. (except with the variable switched)

QuestingCordiial Wrote:I'll post up some of the other code when I can.

That'd be helpful.

Just as a little sanity check, I tested out glutMouseFunc, using your code snippet, and it works just fine on my system (10.5.3) -- no unexpected mouse ups.

What brand of mouse are you using? I'm using a Wacom mouse (with the tablet) and I've had many issues with it over the last couple years because of the drivers, but have managed to work around them in my own software and report bugs which have been subsequently been fixed in others' software.

I've done a search through all the code and these two bits of code are the only parts that modify the two variables in any way.

I have tried using two different mouses, one windows one and the other the mighty mouse which came with the computer. I don't think the fault is in the mouse though, because both mice work perfectly with all other programs.

I am also using 10.5.3

What I haven't tried is restarting the computer with the different mouse plugged in. I'll try that now.

BTW, you *are* aware that ints have bounding limits right? That is, you need to clamp the value to less than INT_MAX and greater than INT_MIN to get expected behavior. Otherwise, if you let your application sit too long, your mouse button values will eventually grow (or shrink) outside of the limits of an int and unintended values will result.

Can you describe what you're attempting to actually do? The code you've shown is very odd looking; it may very well be that there is a different and more robust approach -- one which will fit better within the functionality GLUT offers.

have you stuck a printf at the top level of the HandleMousePress function to see what GLUT is giving you? It seems more likely that the bug is to do with your (odd looking) integer incrementing. Normally a boolean would be used to store the button state on or off, with a separate counter if you need to know how long it's been down for.

Otherwise, a fix when changing unrelated code can be a sign that you're corrupting memory somewhere. Make sure you're not overrunning any arrays, and that everything is allocated correctly etc.

FWIW, I tested glutWarpPointer on my machine and I can confirm that it screws up values given to glutMouseFunc (i.e. this does indeed look like a genuine GLUT bug). The good news is that inserting the code I listed above does fix the problem if you want to do mouse warping in GLUT.

... And I agree, we normally use Booleans for the inputs and apply animation *based* on those, not actually *to* them.

I don't know if this is at all relevant, but every time you call glutWarpPointer(), mouseMovement (or whatever the name is) function is called, so if you're doing anything in there involving key presses, you'll want to be careful.
-wyrmmage