PDA

View Full Version : glut, mousewheels & PeekMessage



Joseph19
08-15-2003, 07:44 PM
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("\n%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).]

Bob
08-16-2003, 12:16 AM
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.

Ozzy
08-16-2003, 02:04 AM
You should give a try to GLFW -> http://glfw.sourceforge.net

knackered
08-16-2003, 03:11 AM
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.

Joseph19
08-16-2003, 05:29 AM
Thanks guys, I'll give your suggestions some thought.

--Joseph

virtualchetan
08-18-2003, 07:34 AM
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

Joseph19
08-18-2003, 05:49 PM
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

marcus256
08-18-2003, 09:02 PM
Originally posted by virtualchetan:
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 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 http://www.opengl.org/discussion_boards/ubb/wink.gif).

virtualchetan
09-18-2003, 07:57 AM
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