# Can't get GLUTMouseFunc to work

I can’t figure out what’s wrong. Can somebody type up (or copy) some simple code that shows how to get the mouse function working. I just need it to detect some down clicks. Thanx much.

How about post your code,so we can see what you are doing.

For examples look at my website. www.angelfire.com/linux/nexusone/

Originally posted by PilotC150:
I can’t figure out what’s wrong. Can somebody type up (or copy) some simple code that shows how to get the mouse function working. I just need it to detect some down clicks. Thanx much.

void myMouse(int button, int state, int xcoord, int ycoord)
{
int x = xcoord;
int y = 480 - ycoord;
if(button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
if((x > 170 && x < 270) && (y < 390 && y > 290)) { // SQUARE 1;
if(current_player == 1 && square1 == -1) {
square1 = 1;
switchPlayer();
}
else if(current_player == 0 && square1 == -1) {
square1 = 0;
switchPlayer();
}
}
}
}

Well do you have x/y also definded as a globel variable?

also could try this:

int x;
int y;

x = xcoord;
y = 480 - ycoord;

But more important maybe your is how your if statements are being used and the order.

if(button == GLUT_LEFT_BUTTON && state == GLUT_UP)// I am not sure what order your logic will work it may AND GLUT_LEFT_BUTTON and state, which I am not sure you want.

Try
if ((button == GLUT_LEFT_BUTTON) && (state == GLUT_UP) // This forces the if statement to compare both Button states first and then AND them. You may also wan to check your other and make sure then compare in the correct order.

if((x > 170 && x < 270) && (y < 390 && y > 290)) { // SQUARE 1;
Try
if(((x > 170) && (x < 270)) && ((y < 390) && (y > 290))) { // SQUARE 1;