Advertisement

Interface and getting mouse position

Started by December 14, 2004 04:24 AM
2 comments, last by GameDev.net 19 years, 11 months ago
Hi. I have a neet little 3d app, and everything is fine, but now I find myself doing some 2d interface implementation, and I am not sure what to do. I have concentrated on OpenGL 3d work for a couple years now, with no 2d, so I am very rusty here. I am using Ortho for my interface. It's painted fine. As with all ortho stuff, 0,0 is top left, 10,0 is 10 pixels in, etc. Now I need to get the 2d coords of the mouse, and hopefully get the x and y to corrolate to my ortho icons, so I know if the user is over one of my interface buttons. I expect this is stupidly simple and I have overlooked it. Anyone able to help? Thanks for any and all help.
What platform are you using? SDL, Windows + DirectInput, plain Win32 API, Linux (native X server calls), GTK, wxWindows, GTK, GLUT, GLFW, ... (did I miss a major one[wink])?
It' a little different for each API/framework.
Advertisement
Hi.

Just using OpenGL and basic window calls.

I tried using GetCursorPos, but that returns the x and y position of the cursor, with no regards for where our window begins and ends. So if the top of my window starts around 200 pixles down the screen, I will get my 100th pixel returned as 300.

I need to get the x and y relative to my window, so if he clicks the top left pixel of my window, it returns 0,0. No matter where my window is.
Ok, I have found the windows function ScreenToClient, and it is doing the job well.

Now, I think these windows calls are slow, so I shall have to look into using another input system. I used DirectInput a few years ago, I guess I'll go back to it. But I'll get the interface working first.

This topic is closed to new replies.

Advertisement