How to read a screen pixel?

I am trying to make a simple bot for a web game, so I would like to be able to read the pixel color on the screen. I did this on Windows using GetPixel (), but I can't figure out what it is on OS X. I was looking online and came across glReadPixel. When I made a simple command line tool in Xcode, I entered the following code. However, I cannot get it to work. I get an EXC_BAD_ACCESS error message:

GLfloat r;
glReadPixels(0, 0, 1, 1, GL_RED, GL_FLOAT, &r);

I thought the above code would save the red pixel value at (0,0) in r. Oh, I would like to avoid approaching the screen because it is slow. Any help?

PS Using the command line tool, my ultimate goal is to create a bash script or applescript, since I already have a command line tool that can be clicked on the screen.

+5
source share
1 answer

glReadPixels it only worries about reading a pixel from the frame buffer (the area that your video card draws into).

Reading pixels from the "screen" is not at all related to OpenGL. To do this, you need system functions.

+4
source

All Articles