I want to copy what's in a pane's image to a PicHandle 9for later export
to the scrap). I seem to be copying the dest rect correctly, but the
data isn't showing up. I've tried both copying srcRect to srcRect &&
(what's shown) srcRect to a 0,0 based rect. Neither seems to help. Can
anyone see what I may be doing wrong? I'm running on 10.2.6 & CW 8.3, if
that makes a differenceŠ
Thanks!
Mark
marc@mac.com
----
Notes:
(a) ST_Rect wraps a Rect
(b) StGWorldPtrSaver locks a GWorldPtr
(c) m_GLPane is the pane that I want the image of
PicHandle picHandle(NULL);
ST_Rect bounds;
WindowPtr windowPtr = m_GLPane->GetMacWindow();
m_GLPane->CalcPortFrameRect(bounds);
{
ST_Rect offsetBounds(bounds);
offsetBounds.OffsetX(-bounds.top);
offsetBounds.OffsetY(-bounds.left);
LGWorld * newGWorld = new LGWorld(offsetBounds, 32);
if (newGWorld)
{
GWorldPtr outGWorldPtr = newGWorld->GetMacGWorld();
const BitMap *aBitMap =
GetPortBitMapForCopyBits(GetWindowPort(windowPtr));
const BitMap *outBitMap = GetPortBitMapForCopyBits(outGWorldPtr);
{
StGWorldPtrSaver outGWorldSaver(outGWorldPtr);
picHandle = OpenPicture(&bounds);
CopyBits( aBitMap, outBitMap, &bounds, &offsetBounds,
srcCopy, 0L);
ClosePicture();
}
UScrap::SetData(kScrapFlavorTypePicture, *picHandle,
GetHandleSize((Handle)picHandle), true);
delete newGWorld;
}
}
David Phillip Oster - 25 Aug 2003 07:36 GMT
> I want to copy what's in a pane's image to a PicHandle 9for later export
> to the scrap). I seem to be copying the dest rect correctly, but the
> data isn't showing up. I've tried both copying srcRect to srcRect &&
> (what's shown) srcRect to a 0,0 based rect. Neither seems to help. Can
> anyone see what I may be doing wrong? I'm running on 10.2.6 & CW 8.3, if
> that makes a differenceŠ
You may need to use glReadPixels() to read the pixels from the OpenGL
framebuffer, then copy them, one scan line at a time, to an appropriate
GWorld. Then, your code may work.
Mark Dawson - 25 Aug 2003 17:20 GMT
> > I want to copy what's in a pane's image to a PicHandle 9for later export
> > to the scrap). I seem to be copying the dest rect correctly, but the
[quoted text clipped - 6 lines]
> framebuffer, then copy them, one scan line at a time, to an appropriate
> GWorld. Then, your code may work.
Looks like that this is the problem--I taking a snapshot of a GL context
doesn't work directly--it wasn't that my code was copying wrong, but
that it was important that the pane was a OpenGL pane (I didn't realize
that it made a difference).
Thanks! I'll look into thisŠ
Mark
Jon Summers - 25 Aug 2003 08:03 GMT
> data isn't showing up. I've tried both copying srcRect to srcRect &&
> (what's shown) srcRect to a 0,0 based rect. Neither seems to help. Can
> anyone see what I may be doing wrong? I'm running on 10.2.6 & CW 8.3, if
> that makes a difference
It is an off-by-one error in the number of GWorlds required :-)
You don¹t need the temporary destination GWorld.
Record the Picture by blitting the pane's bit of the window onto itself.
m_GLPane->FocusDraw();// remember to focus on the pane...
m_GLPane->CalcPortFrameRect(bounds);
OpenCPicParams ocpp;
std::memset(&ocpp, 0, sizeof(OpenCPicParams));
ocpp.srcRect = bounds;
ocpp.hRes = ocpp.vRes = (72L << 16);
ocpp.version = 2;
picHandle = ::OpenCPicture(&ocpp);
const BitMap *aBitMap =
::GetPortBitMapForCopyBits(::GetWindowPort(GLPane->GetMacWindow()));
::CopyBits(aBitMap, aBitMap, &bounds, &bounds, srcCopy, 0L);
::ClosePicture();

Signature
jons(AT)vrtools(DOT)com
David Phillip Oster - 25 Aug 2003 16:11 GMT
> > data isn't showing up. I've tried both copying srcRect to srcRect &&
> > (what's shown) srcRect to a 0,0 based rect. Neither seems to help. Can
[quoted text clipped - 16 lines]
>
> picHandle = ::OpenCPicture(&ocpp);
ClipRect(&bounds); // <-------- don't forget this.
> const BitMap *aBitMap =
> ::GetPortBitMapForCopyBits(::GetWindowPort(GLPane->GetMacWindow()));
> ::CopyBits(aBitMap, aBitMap, &bounds, &bounds, srcCopy, 0L);
> ::ClosePicture();
If you are reusing your original window, remember to set the ClipRect
appropriately, or a large PICT may be clipped.