Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a pixel off of the screen?

I am trying to make a simple bot for a web game, so I would like to be able to read the color of a pixel on the screen. I've done this on Windows with GetPixel(), but I can't seem to figure it out on OS X. I been looking online and came across glReadPixel. When I made a simple command line tool in XCode, I put in the following code. However, I cannot seem to make it work. I keep getting a EXC_BAD_ACCESS error from this:

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

I thought the above code would store the red value of the pixel at (0,0) into r. Oh, I'd like to avoid take a screen shot approach because that is slow. Any help?

P.S. With the command line tool, my end goal is to make a bash script or an applescript, since I already have a command line tool that can click on the screen.

like image 291
hassaanm Avatar asked Dec 13 '10 03:12

hassaanm


1 Answers

glReadPixels is only concerned about reading a pixel from the frame buffer (the area into which your graphics card draws).

Reading pixels from the "screen" is not related to OpenGL at all. You need system-specific functions for that.

like image 128
Kos Avatar answered Nov 10 '22 11:11

Kos