PDA

View Full Version : Converting pixel coordinates



jeremyp
04-18-2001, 12:43 PM
I want to test the outlieing corners of a certain area of my window for a mouse click. The idea is to simulate a button. I'm using NeHe's tut 23 direct input for the mouse. I was told that I needed to convert my screen coordinates to window coordinates with a device context function. How do I do that??

zed
04-18-2001, 05:55 PM
gluUnProject(..)
though if your button is 2d (like most buttons are) you can do it much more simply

Deiussum
04-19-2001, 04:58 AM
Actually, he's talking about converting screen coordinates to window coordinates using the Win32 API. (i.e. a coordinate system where the upper left corner of the screen is 0,0 vs. the upper left corner of the window being 0,0)

I'm not sure of an API function to convert it directly, but one way you could do this is to use GetWindowRect, which will give you the upper left coordinate of the window in screen coordinates. It is then just a matter of subtracting the x,y values from the screen coordinates you have to convert them to window coordinates.

If I remember correctly, this is also going to take into account the size of the title bar, menu, window border, etc... So if you want the coordinates relative to the actual client area (i.e. the area where your OpenGL context is actually being drawn), you will have to also subtract a bit for those. There is an API function that you can use to get the size of those as well, but I'll be damned if I can remember the name of it right now...

Just remembered it. GetSystemMetrics.


[This message has been edited by Deiussum (edited 04-19-2001).]