Search code examples
copenglglutfreeglut

detect mouse clicks in OpenGL in C


Is there any way that I can detect mouse click position by not using glutMouseFunc()?

All examples that I found online getting mouse click by using glutMouseFunc(). However, I don't want the detect mouse click function always active. I want to record the mouse click position only after user selects a certain option in the menu. To be exact, I want to record 4 mouse click positions, after user selects an option in the menu.


Solution

  • First of all, OpenGL has nothing to do with the mouse callback. It is Graphics library. For your ultimate goal, basically as @Mikhail suggested, you insert a conditional statement inside your glutMouseFunc, therefore,

    void mouse_callback(){
    
    if ( command_seleteced == true )
       store mouse position
    
    }