Search code examples
copenglglut

GLUT menu creates problems with OpenGL game?


I am trying to make a 2D game with GLUT & OpenGL. I am using a menu with the click of right mouse button its a pop up, menu works fine but in order to reload my drawing function I have to click again the right button. For example if a change is made with the click of the button in order to see the change I have to click again.

int main(int argc,char **argv)
{
  glutInit(&argc, argv); 
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowPosition(50, 50);
  glutInitWindowSize(800, 800);
  glutCreateWindow("GAME"); 

  init(); 

  glutDisplayFunc(drawgame);
  glutMouseFunc(clickforaction);

  glutCreateMenu(MenuSelect);
  glutAddMenuEntry("Action",1);
  glutAddMenuEntry("Action2",2);
  glutAttachMenu(GLUT_RIGHT_BUTTON);

  glutMainLoop(); 
}

Solution

  • You've to update the display when the mouse is clicked. Call glutPostRedisplay to mark the current window as needing to be redisplayed.

    void clickforaction(int button, int state, int x, int y)
    {
        // [...]
    
        glutPostRedisplay();
    }