Fuzzyzilla
Fuzzyzilla

Reputation: 356

No events generated by ScrollWheel - GLUT

I am making an OpenGL application, using GLUT as my base. I am just started to implement non-console interactions, and the mouse was easy enough to implement. Then, when I went to implement mouse scrolling, I found that no events are passed to glutMouseFunc when the mouse is scrolled. I saw on other forums that it should call it's callback with 3 and 4 into int button for scroll up and down, respectively.

I am trying to avoid glutMouseWheelFunc(...) as much as possible, due to it not being platform-independent.

So, how can I implement scrolling in a working, platform-independent way?

Thanks!

Here is a short code segment showing the issue -

#pragma once
#include <iostream>

#include <GL/glut.h>
#include <GL/glext.h>

void onMouse(int button, int state, int x, int y);

int main(int argc, char** argv) {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(256,256);

    glutCreateWindow("Mousewheel Test");

    glutMouseFunc(onMouse);

    glutMainLoop();
}

void onMouse(int button, int state, int x, int y){
    //Here, an event is generated for left, right, and middle clicks (though middle is the same as right...), 
    //but not scrolling!
    std::cout << "Mouse event. Button: " << button << " state: " << state << '\n';
}

Upvotes: 0

Views: 479

Answers (1)

FBergo
FBergo

Reputation: 1071

Using freeglut 3.0.0 + Linux + gcc your example works (with minor adjustments, a glutDisplayFunc must be registered or glut refuses to open the window), and the wheel is reported in onMouse as buttons 3 and 4.

Using GLUT 3.7.6 + Windows 10 + Visual Studio 2017 the mouse wheel apparently cannot be captured by glut (there is no wheel callback, and the callbacks for mouse and keyboard report nothing).

The original GLUT (by Mark Kilgard) is very old, and hasn't been updated since 2001 ( https://user.xmission.com/~nate/glut.html ), so probably there is no way to write wheel-aware code that works with any GLUT and any platform.

The freeglut implementation is supposed to correctly capture the mouse wheel regardless of the platform.

Upvotes: 1

Related Questions