Using the mouse scrollwheel in GLUT

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?


Freeglut's glutMouseWheelFunc callback is version dependant and not reliable in X. Use standard mouse function and test for buttons 3 and 4.

The OpenGlut notes on glutMouseWheelFunc state:

Due to lack of information about the mouse, it is impossible to implement this correctly on X at this time. Use of this function limits the portability of your application. (This feature does work on X, just not reliably.) You are encouraged to use the standard, reliable mouse-button reporting, rather than wheel events.

Using standard GLUT mouse reporting:

#include <GL/glut.h>


void mouse(int button, int state, int x, int y)
   // Wheel reports as button 3(scroll up) and button 4(scroll down)
   if ((button == 3) || (button == 4)) // It's a wheel event
       // Each wheel event reports like a button click, GLUT_DOWN then GLUT_UP
       if (state == GLUT_UP) return; // Disregard redundant GLUT_UP events
       printf("Scroll %s At %d %d\n", (button == 3) ? "Up" : "Down", x, y);
   }else{  // normal button event
       printf("Button %s At %d %d\n", (state == GLUT_DOWN) ? "Down" : "Up", x, y);



As the OP stated, it is "dead simple". He was just wrong.

Need Your Help

Problem with Entity Framework 4 and NUnit

entity-framework-4 nunit entity

I've got a simple test project I'm trying to convert from the visual studio unit testing framework to nunit. However, I'm encountering a strange error.

EXTJS grid + JSP data is not loaded

javascript jsp extjs

I tried to code EXTJS Grid using jsp. I modify the EXTJS example to get data from jsp page, but the data is not loaded.