Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: glReadPixels for screen capture
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: glReadPixels for screen capture



Man, I was messing with this a while back.  I know
that the format of the data in memory has to be RGBA.
I was reading data into a void*, and you seem to be
reading into a pixmap.  Dunno if that matters or not.

If you look at the memory after the glReadPixels call,
you should see something like:  RR GG BB FF (the alpha
channel will be FFs).  The address that the picture
data lives at is the last parameter of the
glReadPixels function.  In your case, it looks like
whatever address GetPixBaseAddr is returning.

I didn't have to mess with the INT_8_8_8_8/REV unless
I was going from PPC to Intel.  I was getting that
freaky pastel look as well, but only on the Intel
side.  My image was either really blue or pink.
Probably because I had the data out of order (ie:  I
was reading FF RR GG BB which means that the red value
is always FF).

Try this code and see if this helps you out any
better.  Most people seem to reference the glgrab.c
example.  It looks similar to what you have, but I
never had a problem going from PPC to PPC.

http://www.cocoabuilder.com/archive/message/cocoa/2005/8/13/144256

Thorrin

--- Jeff Schindler <email@hidden>
wrote:

> Hello,
>
> We're using glReadPixels to capture the screen.  I'm
> seeing an issue where
> the bytes come out unexpectedly swapped.  I have a
> G4 and a MacBook Pro
> where our code works correctly.  But we have another
> G5 machine where the
> bytes are swapped (giving the resulting pixmap a
> blue tint).  I'm guessing I
> need to specify GL_UNSIGNED_INT_8_8_8_8_REV at
> times, but I cannot determine
> the determining factor for that.  GL_PACK_SWAP_BYTES
> is off on all 3
> machines.  Any assistance is much appreciated.  BTW
> - I've inherited this
> code and I'm an OpenGL novice.
>
>    CGLContextObj    glContextObj;
>    CGLPixelFormatObj pixelFormatObj;
>    long numPixelFormats;
>
>    // it looks like a CGDirectDisplayID and
> DisplayIDType are
>    // equivalent...
>    const CGOpenGLDisplayMask displayMask =
>
>
CGDisplayIDToOpenGLDisplayMask((CGDirectDisplayID)fDisplayId);
>
>    CGLPixelFormatAttribute attribs[] =
>    {
>       kCGLPFAFullScreen,
>       kCGLPFADisplayMask,
> (CGLPixelFormatAttribute)displayMask,
>       kCGLPFANoRecovery,
>       (CGLPixelFormatAttribute)0
>    };
>
>    CGLChoosePixelFormat(attribs, &pixelFormatObj,
> &numPixelFormats);
>
>    CGLCreateContext(pixelFormatObj, NULL,
> &glContextObj);
>
>    CGLDestroyPixelFormat(pixelFormatObj);
>    pixelFormatObj = NULL;
>
>    CGLSetCurrentContext(glContextObj);
>    CGLSetFullScreen(glContextObj);
>
>    // Grab stuff
>    GLint viewport[4];
>
>    glReadBuffer(GL_FRONT);
>    glGetIntegerv(GL_VIEWPORT, viewport);
>
>    const GLint width  = viewport[2];
>    const GLint height = viewport[3];
>
>    Rect qdBounds = (*this->GetDevice())->gdRect;
>    GWorldPtr offscreen = NULL;
>    OSErr err = UtilityAllocateGWorld(&offscreen, 32,
> &qdBounds);
>    if ((err == noErr) and (offscreen != NULL))
>    {
>       PixMapHandle pixmap =
> GetGWorldPixMap(offscreen);
>
>       glFinish();    /* Finish all OpenGL commands
> */
>
>       glPixelStorei(GL_PACK_ALIGNMENT, 4); /* Force
> 4-byte alignment */
>       glPixelStorei(GL_PACK_ROW_LENGTH,
> ((**pixmap).rowBytes & 0x3fff) / 4);
>       glPixelStorei(GL_PACK_SKIP_ROWS, 0);
>       glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
>
>       LockPixels(pixmap);
>       glReadPixels(0, 0, width, height,
>          GL_BGRA,
>          GL_UNSIGNED_INT_8_8_8_8,
>          GetPixBaseAddr(pixmap));
>
>       PixelShuffle pixelShuffle = Null_shuffle;
>
>       swizzleBitmap(offscreen, pixelShuffle);
>
>       UnlockPixels(pixmap);
>    }
>    // end stuff
>    CGLSetCurrentContext(NULL);
>    CGLClearDrawable(glContextObj);
>    CGLDestroyContext(glContextObj);
>    return offscreen;
>
> Jeff
>
>  _______________________________________________
> Do not post admin requests to the list. They will be
> ignored.
> Mac-opengl mailing list
> (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
>
> This email sent to email@hidden
>


"Everyone is allergic to giant rocks hitting them in the head!"
-Thorrin's elf chick after casting a 'meteor swarm' spell ;)



____________________________________________________________________________________
Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545469
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >glReadPixels for screen capture (From: "Jeff Schindler" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.