Picking

I need to attach my popupmenu to the selected object. I think I did something wrong. could you look at it. below are my functions.

  1. Mouse function:
void mouseButton(int button, int state, int x, int y) 
{
    if 	((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN))
     {
                handlemouse(x, y, button);
     }
    
}
  1. Second Mouse Function
void handlemouse( int x, int y, int button)
{
       
        printf("Mouse button %d pressed at %d %d
", button, x, y);
        gl_select(x,y);       
         
}
  1. Select Function:
void gl_select(int x, int y)
{
    GLuint buff[64] = {0};
    GLint hits, view[4];
    int id;
    glSelectBuffer(64, buff);
    glGetIntegerv(GL_VIEWPORT, view);
    glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(1);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
   	gluPickMatrix(x, y, 1.0, 1.0, view);
	gluPerspective(45,1,1,100);
	glMatrixMode(GL_MODELVIEW);
	glutSwapBuffers();
	background();
    createPopupMenus();	
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	hits = glRenderMode(GL_RENDER);			
}
  1. Background(My Rendering)
void background()
{
  glLoadIdentity();  
  draw_background();
  draw_hline();
  draw_vline();
  draw_colorcircles(-6.5, -3.2, 0, 0 , 255);
  draw_colorcircles(-5.5, -3.2, 0, 100 , 0);
  draw_colorcircles(-4.5, -3.2, 0, 255 , 255);
  draw_colorcircles(-3.5, -3.2, 265, 140 , 0);
  draw_colorcircles(-2.5, -3.2, 1, 0 , 0);
  draw_colorcircles(-1.5, -3.2, 1, 1 , 1); 
  glutSwapBuffers();
} 
  1. Pop up menus
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;                                                                
     }
     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; 
     }
}

Did I do anything wrong here? And could you tell me how to attach the pop up menu to the selected object? I have 40 circles. I want the user to select each and change the color using pop up menu.
and o Also:

float y = 3.8;
    int name=1;
    for (int m = 0; m < 10; m++)
     {                      
         for ( float x = -6.5; x <= -3.5; x++)
         {
             
             glPushName(name);
             name++;                                                            
             drawcircle (x,y);                  
             
         }         
         y = y - 0.7;
         
     }                    
}

is my pushname right? Because I highly doubt it

what has glut programming got to do with the title of the post?

Picking means to select a object.
http://www.opengl.org/resources/faq/technical/selection.htm

the problem you are having is a GLUT issue - not OpenGL selection/picking.

I need to attach my popupmenu to the selected object

and

And could you tell me how to attach the pop up menu to the selected object

Seems you have the selection made, but need to attach a GLUT menu.
Again, what has the title of picking got to do with your issue?

well nvm. I just made 40 if statements