Question

How can I capture the screen with Haskell on Mac OS X?

I've read Screen capture in Haskell?. But I'm working on a Mac Mini. So, the Windows solution is not applicable and the GTK solution does not work because it only captures a black screen. GTK in Macs only captures black screens.

Was it helpful?

Solution 2

I programmed this C code to capture the screen of Macs and to show it in an OpenGL window through the function glDrawPixels:

opengl-capture.c

http://pastebin.com/pMH2rDNH

Coding the FFI for Haskell is quite trivial. I'll do it soon.

OTHER TIPS

How can I capture the screen with … and OpenGL?

Only with some luck. OpenGL is primarily a drawing API and the contents of the main framebuffer are undefined unless it's drawn to by OpenGL functions themself. That OpenGL could be abused was due to the way graphics system did manage their on-screen windows' framebuffers: After a window without predefined background color/brush was created, its initial framebuffer content was simply everything that was on the screen right before the window's creation. If a OpenGL context is created on top of this, the framebuffer could be read out using glReadPixels, that way creating a screenshot.

Today window compositing has become the norm which makes abusing OpenGL for taking screenshots almost impossible. With compositing each window has its own off-screen framebuffer and the screen's contents are composited only at the end. If you used that method outlined above, which relies on uninitialized memory containing the desired content, on a compositing window system, the results will vary wildly, between solid clear color, over wildly distorted junk fragments, to data noise.

Since taking a screenshot reliably must take into account a lot of idiosyncrasy of the system this is to happen on, it's virtually impossible to write a truly portable screenshot program.

And OpenGL is definitely the wrong tool for it, no matter that people (including myself) were able to abuse it for such in the past.

This might be useful to find the solution in C:

NeHe Productions - Using gluUnProject
http://nehe.gamedev.net/article/using_gluunproject/16013/

Apple Mailing Lists - Re: Screen snapshot example code posted
http://lists.apple.com/archives/cocoa-dev/2005/Aug/msg00901.html

Compiling OpenGL programs on Windows, Linux and OS X
http://goanna.cs.rmit.edu.au/~gl/teaching/Interactive3D/2012/compiling.html

Grab Mac OS Screen using GL_RGB format

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top