开发者

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 lin开发者_如何学Pythone 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜