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?
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.