Problem getting mouse Co-ordinates.

I am having trouble with this. I am using GLUT.
Trying to get mouse co-ordinates for the whole day and unsuccesfull after all that work. Help please.
what i want to do it keep track where the user right clicks the mouse
So that I know where to do stuff.
Else it is doing stuff all around.

Here is what I have about mouse in main:
1
2
glutMouseFunc(mouseButton); 
 glutPassiveMotionFunc(handlemouse);


here is my handlemouse function :
1
2
3
4
5
void handlemouse( int x, int y)
{     
     mouse_x = x;
     mouse_y = y;      
}


here is my mousebutton function:
1
2
3
4
5
6
7
void mouseButton(int button, int state, int x, int y) 
{
      if (button == GLUT_RIGHT_BUTTON)
    {
         handlemouse(x,y);       
    }
}

this is where I am calling it :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void createPopupMenus()
{     
       int mainMenu = glutCreateMenu(processMainMenu);       
       glutAddMenuEntry("Blue",1);
       glutAddMenuEntry("Green",2);
       glutAddMenuEntry("Light Blue",3);
       glutAddMenuEntry("Yellow",4);
       glutAddMenuEntry("Red",5);
       glutAddMenuEntry("White",6);
       float y = 3.8;
        for (int m = 0; m < 10; m++)
     {         
         for ( float x = -6.5; x <= -3.5; x++)
         { 
           mouseButton(GLUT_RIGHT_BUTTON, GLUT_DOWN, x, y);
         }
         y = y - 0.7;
     } 
       glutAttachMenu(GLUT_RIGHT_BUTTON);     
         
}


this is my popup menu function if you need:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void processMainMenu(int option) 
{
         
     if (option ==1)
     {red = 0;  green = 0; blue = 255;  // red green blue are float variables                               
     }
     else if (option==2)
     {red = 0;  green = 100; blue = 0; 
     }
     else if (option==3)
     {red = 0;  green = 255; blue = 255; 
     }
     else if (option==4)
     {red = 265;  green = 140; blue = 0; 
     }
     else if (option==5)
     {red = 1;  green = 0; blue = 0; 
     }
     else if (option==6)
     {red = 1;  green = 1; blue = 1; 
     }
}


Thanks!


Last edited on
bump!
Topic archived. No new replies allowed.