Using the mouse scrollwheel in GLUT

后端 未结 3 434
孤独总比滥情好
孤独总比滥情好 2020-12-01 07:39

I want to use the mouse scrollwheel in my OpenGL GLUT program to zoom in and out of a scene? How do I do that?

3条回答
  •  我在风中等你
    2020-12-01 08:14

    Note that venerable Nate Robin's GLUT library doesn't support the scrollwheel. But, later implementations of GLUT like FreeGLUT do.

    Using the scroll wheel in FreeGLUT is dead simple. Here is how:

    Declare a callback function that shall be called whenever the scroll wheel is scrolled. This is the prototype:

    void mouseWheel(int, int, int, int);
    

    Register the callback with the (Free)GLUT function glutMouseWheelFunc().

    glutMouseWheelFunc(mouseWheel);
    

    Define the callback function. The second parameter gives the direction of the scroll. Values of +1 is forward, -1 is backward.

    void mouseWheel(int button, int dir, int x, int y)
    {
        if (dir > 0)
        {
            // Zoom in
        }
        else
        {
            // Zoom out
        }
    
        return;
    }
    

    That's it!

提交回复
热议问题