PDA

View Full Version : Getting Mouse Coordinates



31337
10-09-2002, 06:41 PM
What's the easiest way to get mouse coordinates (and change them as nessecary for my 3d game) without using GLUT? I'm using windows.h and I can't find anything about it. Thanks

mikael_aronsson
10-09-2002, 11:52 PM
Hi !

I am not sure what this has to do with OpenGL, but normally you get the mouse coordinates from the WM_MOUSEMOVE message (and the WM_L/RBUTTONUP/DOWN).

Mikael

marcus256
10-10-2002, 01:47 AM
Getting mouse coordinates can be done using the WM_ messages, but changing them is not as easy. You can use SetCursorPos(), but it takes screen coordinates (not window coordinates), so you need to figure out the window position too if you want to move the mouse cursor in window coordinates. You can use the WM_MOVE message to figure out where the window is.

...better yet: use GLFW (http://hem.passagen.se/opengl/glfw/) , which does this for you. Or, you can just check out the source for GLFW to see how it's done.

mikael_aronsson
10-10-2002, 02:12 AM
Hi !

You can use ScreenToClient() and ClientToScreen() to convert mouse coordinates to client area coordinates.

Mikael

31337
10-10-2002, 06:01 AM
I'm going to look into all of these. My problem is I need it so that the mouse can move in any direction indefinatly. How do I access "WM_messages" or whatever? I'm gonna look into GLFW right now

31337
10-10-2002, 10:45 AM
glfw works great! It's my new favorite library!

marcus256
10-11-2002, 01:40 AM
Originally posted by mikael_aronsson:
You can use ScreenToClient() and ClientToScreen() to convert mouse coordinates to client area coordinates.

Thanks Mikael! I will use that from now on http://www.opengl.org/discussion_boards/ubb/smile.gif

31337
10-11-2002, 09:57 PM
glfw doesn't seem to be working. For example after I have initialized it I run the command glfwGetMousePos(&mouseX, &mouseY); and through debugging I have found that mouseX and mouseY always get assigned to 0 for some reason. It seems as though glfw is just ignoring me or something lol. Any ideas?

marcus256
10-12-2002, 09:57 AM
Originally posted by 31337:
glfw doesn't seem to be working. For example after I have initialized it I run the command glfwGetMousePos(&mouseX, &mouseY); and through debugging I have found that mouseX and mouseY always get assigned to 0 for some reason. It seems as though glfw is just ignoring me or something lol. Any ideas?

You need to:

1) Open a window
2) Call glfwPollEvents or glfwSwapBuffers every time you want fresh mouse coords

Hope this helps. If not, you've found a bug.

/Marcus

31337
10-12-2002, 02:15 PM
does it need to be a glfw window or can it be a windows.h window?

marcus256
10-13-2002, 02:36 AM
Originally posted by 31337:
does it need to be a glfw window or can it be a windows.h window?

It must be a GLFW window. Check the manuals - they should hopefully make things more clear. In the source distribution there are also program examples that you can have a look at.

31337
10-13-2002, 11:28 AM
well looks like I'm going to do some experimentation and then rewrite the base code with glfw then. Thanks for your help

marcus256
10-13-2002, 02:19 PM
Don't forget to download the newly released GLFW v2.2. You get joystick support, among other things http://www.opengl.org/discussion_boards/ubb/smile.gif