Hi all!
I'm trying to understand this code:
http://developer.apple.com/library/mac/#samplecode/OpenGLScreenSnapshot/Listings/OpenGLScreenReader_m.html%23//apple_ref/doc/uid/DTS10004288-OpenGLScreenReader_m-DontLinkElementID_6
Unfortunately, I'm not acquainted with Objective-C (to be honest, it seems to be extemely unintuitive), but I know how to write programs in C/C++. As this program uses openGL I suppose it is not difficult to write a similar one in C using gl.h library. Am I right?
Can anyone write me a scheme what my openGL program needs to do before calling glReadPixels() routine? Or just translate this into C, if possible:
I have never used the openGL before, but now I need only one function from that huge library: the function that will allow me to grab the current content of the screen - one that puts it somewhere in RAM as a table of RGB ints and returns me the pointer to the first byte.
thanks in advance!
I'm trying to understand this code:
http://developer.apple.com/library/mac/#samplecode/OpenGLScreenSnapshot/Listings/OpenGLScreenReader_m.html%23//apple_ref/doc/uid/DTS10004288-OpenGLScreenReader_m-DontLinkElementID_6
Unfortunately, I'm not acquainted with Objective-C (to be honest, it seems to be extemely unintuitive), but I know how to write programs in C/C++. As this program uses openGL I suppose it is not difficult to write a similar one in C using gl.h library. Am I right?
Can anyone write me a scheme what my openGL program needs to do before calling glReadPixels() routine? Or just translate this into C, if possible:
Code:
// Create a full-screen OpenGL graphics context
// Specify attributes of the GL graphics context
NSOpenGLPixelFormatAttribute attributes[] = {
NSOpenGLPFAFullScreen,
NSOpenGLPFAScreenMask,
CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay),
(NSOpenGLPixelFormatAttribute) 0
};
NSOpenGLPixelFormat *glPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
if (!glPixelFormat)
{
return nil;
}
// Create OpenGL context used to render
mGLContext = [[[NSOpenGLContext alloc] initWithFormat:glPixelFormat shareContext:nil] autorelease];
// Cleanup, pixel format object no longer needed
[glPixelFormat release];
if (!mGLContext)
{
[self release];
return nil;
}
[mGLContext retain];
// Set our context as the current OpenGL context
[mGLContext makeCurrentContext];
// Set full-screen mode
[mGLContext setFullScreen];
NSRect mainScreenRect = [[NSScreen mainScreen] frame];
mWidth = mainScreenRect.size.width;
mHeight = mainScreenRect.size.height;
I have never used the openGL before, but now I need only one function from that huge library: the function that will allow me to grab the current content of the screen - one that puts it somewhere in RAM as a table of RGB ints and returns me the pointer to the first byte.
thanks in advance!