Mouse click on Mesh in OpenGL

Hi everyone,

I am struggling to figure out how to mouse-click onto the mesh. The code is already pre-setup, so I am trying to enhance it. I have tried many other ways and cannot seem to get it to work. What I want to do is to, if pressed on mesh, exit the program. Any suggestions? Here’s the code; I have undone the work I implemented.

void UMouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{
    switch (button)
    {
        case GLFW_MOUSE_BUTTON_LEFT:
        {
            if (action == GLFW_PRESS)
                cout << "Left mouse button pressed" << endl;

            else
               cout << "Left mouse button released" << endl;

        }
        break;

        case GLFW_MOUSE_BUTTON_MIDDLE:
        {
            if (action == GLFW_PRESS)
                cout << "Middle mouse button pressed" << endl;
            else
                cout << "Middle mouse button released" << endl;
        }
        break;
        
        case GLFW_MOUSE_BUTTON_RIGHT:
        {
            if (action == GLFW_PRESS)
                cout << "Right mouse button pressed" << endl;
            else
                cout << "Right mouse button released" << endl;
        }
        break;

        default:
            cout << "Unhandled mouse button event" << endl;
            break;
    }
}

Take look at Clicking on objects for different options how to implement this.