glut, mousewheels & PeekMessage

I am so close…

I wanted to use both the mouse wheel and glut, so I came up with this:

HWND hWnd = GetForegroundWindow();
MSG message;
#define WM_MOUSEWHEEL 0x020A
if(PeekMessage(&message, hWnd, WM_MOUSEWHEEL,WM_MOUSEWHEEL ,PM_NOREMOVE))
{
short zDelta = (short)HIWORD(message.wParam);
printf("
%d", (int)zDelta);
}

It works sort of. I am getting the normal + or -120 when I flip the mouse wheel, but I only get it SOMETIMES. I am not sure when the WM_MOUSEWHEEL message is getting deleted, but it must be. I am calling the above function in the glutDisplayFunc, and all the glutMouseFuncts (mouse motion, passive motion, and the main mouse one). It works like 50% of the time, half the time when I flip the wheel I get a message, and usually only if I flip it REALLY FAST. If I only call it in the displayFunc, it works like 10% of the time, and if I only call it in all the combined mouse functions, it works 40% of the time…
Also, it works 100% of the time, perfectly, as long as I am actually MOVING the mouse, how strange.
Does anyone have a clue as to what I should do?

–Joseph

[This message has been edited by Joseph19 (edited 08-15-2003).]

GLUT has it’s own message loop that catches messages. If you need to catch messages yourself, GLUT is not what you want to use.

You should give a try to GLFW -> http://glfw.sourceforge.net

Mmm, the only reason one would use GLUT for an application is that it’s platform independent - what you’re doing is making it platform dependent. You appear to have a more than passing knowledge of the windows message pump, so why don’t you just write your own glut? Wouldn’t take more than half a day to get something equal to GLUT.

Thanks guys, I’ll give your suggestions some thought.

–Joseph

I think best way to use Mouse Wheel and GLUT is : look for button values 3(Wheel Up) and 4 (Wheel Down) in the mouse press callback.

(GLUT_LEFT_BUTTON = 0, GLUT_RIGHT_BUTTON = 1, GLUT_MIDDLE_BUTTON = 2, and 3,4 for wheel)

  • Chetan

I don’t think that works, Chetan.

I tried it and 3 and 4 are never sent…

Furthermore, there is no indication of this feature in glut.h, only:

/* Mouse buttons. */
#define GLUT_LEFT_BUTTON 0
#define GLUT_MIDDLE_BUTTON 1
#define GLUT_RIGHT_BUTTON 2

/* Mouse button state. */
#define GLUT_DOWN 0
#define GLUT_UP 1

Are you using windows? Are you using the normal version of GLUT? I found one that has a hacked mouse callback but I need to use the normal one right now, for reasons too boring to mention.

–Joseph

Originally posted by virtualchetan:
[b]I think best way to use Mouse Wheel and GLUT is : look for button values 3(Wheel Up) and 4 (Wheel Down) in the mouse press callback.

(GLUT_LEFT_BUTTON = 0, GLUT_RIGHT_BUTTON = 1, GLUT_MIDDLE_BUTTON = 2, and 3,4 for wheel)

  • Chetan[/b]

I believe that is an XFree86 (Linux) only solution. My guess is that GLUT does not know about the mousewheel, nor buttons 4 & 5, it simply passes the button no. from the X event to the GLUT callback. Since buttons 4 & 5 are usually mapped to the mousewheel (up/down), at least under XFree86, you can get away with your proposed solution (provided that you are running under the right environment).

As Ozzy mentioned, GLFW has support for the mousewheel, both under Windows and under X. GLFW is currently closing in (and sometimes surpasing) GLUT in terms of portability, so it might not be a bad alternative (the obvious recommendation of an author ).

Yeah,
I have tested it on XWindows/Linux only.

But, I suppose one of my friend tested it on Windows as well - Infact she only told me about this solution.

  • Chetan