Faery
Faery

Reputation: 4650

OpenGL - actions with right and left button of the mouse

I have some functionality for the left mouse button and it works, but I wanted to have another functionality for the right button. It works, too, but when I try to include both of them, the functionality for the one of the buttons, stops. What am I missing?

void GLFWCALL onMouseRightButton( int button, int action ) {
    if( button==GLFW_MOUSE_BUTTON_RIGHT )
    {
        // ... some code
    } 
}

 void GLFWCALL onMouseMoveRight( int a, int b ) {
     if( dragging_right )
     {
         // some math 
     } 
 }

Then after initialization, I have:

glfwSetMouseButtonCallback( onMouseButtonLeft );
glfwSetMousePosCallback( onMouseMoveLeft );
glfwSetMouseButtonCallback( onMouseButtonRight);
glfwSetMousePosCallback( onMouseMoveRight);

but in this form only the functionality for the right button works, and if I comment the last two functions - glfwSetMouseButtonCallback( onMouseButtonRight); and glfwSetMousePosCallback( onMouseMoveRight); everything with the left button is fine.

Could you please tell me how to make both of them work fine? Thank you very much in advance!

Upvotes: 2

Views: 6724

Answers (1)

Luke B.
Luke B.

Reputation: 1288

When you call the second glfwSetMouseButtonCallback you are actually overwriting the last callback. Your onMouseButton[...] should be like this:

void GLFWCALL onMouseButton( int button, int action ) {
    if( button==GLFW_MOUSE_BUTTON_RIGHT )
    {
        // ... some code
    } 
    else if( button==GLFW_MOUSE_BUTTON_LEFT )
    {

    }
}

Upvotes: 2

Related Questions