PDA

View Full Version : get current mouse position's color



dousti91
01-28-2013, 12:12 PM
Hi. I'm have a square(white color) in my screen. Now i get the mouse position(x and y) through this code:


POINT pt;
GetCursorPos(&pt);

I want to know if the mouse is on the my square.
How to know the color of mouse position(x,y) on the screen?

dousti91
01-28-2013, 12:42 PM
How to use glReadPixels() for reading color of a pixel. Can you give me an example please?
Thanks

V-man
02-03-2013, 08:13 AM
How to use glReadPixels() for reading color of a pixel. Can you give me an example please?
Thanks

GLubyte rgba[4];
glReadPixels(point.x, windowheight-1-point.y, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, rgba);

You need to do windowheight-1-point.y because coordinate for y is from bottom=0 to top while for Windows, it is inverted. We read a BGRA format because that is the format that is typically used on Windows.