PDA

View Full Version : Selecting a object to change color using popupmenu



programmer17
12-29-2011, 10:40 PM
I am using GLUT
Hello. This is my first post so, you can freely say what I did wrong. :)
I have these 40 circles.
4 per line.
I want the user to be able to select color for each using a pop up menu. Pop up menu has red, green and other 4.
I can already change the color of all.
However, not individual. I tried getting co-ordinates using glutpassivemousefunc. But it does not seem work. Dont know how to put code sorry.
Here is my code if you need: however it does not work so..

void handlemouse( int x, int y)
{
if ( GLUT_RIGHT_BUTTON)
{
mouse_x = x;
mouse_y = y;
printf("\n%d %d",x,y);
}

}
//-------------------------------------------------------------------------------------------------------------------
void mouseButton(int button, int state, int x, int y)
{
if (button = GLUT_RIGHT_BUTTON)
{
handlemouse(x,y);
}

}
//------------------------------------------------------------------------------------------------------------------

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);
glutAttachMenu(GLUT_RIGHT_BUTTON);

}
//-----------------------------------------------------------------------------------------------------------

void processMainMenu(int option)
{
if (option ==1)
{
red = 0; green = 0; blue = 255;
drawcircle(mouse_x, mouse_y);
}
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;
}
}
//------------------------------------------------------------------------------------------------------------------------
Now I know a different idea. But have no idea how to implement it..

It seems that when I attach a menu to mouse button, I loose that callback.
It really doesn't make sense.

I could change a little the interface in order to 'make it work'. By instance requiring the user to select the circle.
Then the pop-up menu will be applied to that circle, without taking into account where the menu was invoqued.
Overall, how would I select a circle and change its colour? How would I do this? Any idea?
Note: I spent 3 days already on this. My holiday days! So its not I am lazy and asking for help. Just dont know how to do it

programmer17
12-30-2011, 09:51 AM
thanks! I got it. It is called picking, just knew about that word. If anyone needs it in the future:
1. Get the window coordinates of the mouse
2. Enter selection mode
3. Redefine the viewing volume so that only a small area of the window around the cursor is rendered
4. Render the scene, either using all primitives or only those relevant to the picking operation
5. Exit selection mode and identify the objects which were rendered on that small part of the screen.