🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #23577

Question About Offscreen Bitmaps...

#23577
From: Michael Domino
Date: Tue, 12 Jan 1988 21:38
62 lines
2554 bytes
I have this display that is quite involved and takes a couple of seconds to
set up.  There are four windows, so I have been calling GetNewWindow, doing
the necessary drawing, then going on to the next window, repeating this for
each window.  But this looks not-so-clever to a user, so what I thought I
would do is set everything up in an offscreen bitmap, use CopyBits to
display the whole thing all at once, and then set the portBits field of each
window's grafport back to screenBits, so that all subsequent drawing takes
place on the screen.  I've used CopyBits successfully before to copy
something from screenBits to an offscreen bitmap (to refresh the screen
later), but I've never had any occasion to actually do any drawing offscreen.

I thought the following code might work...but it doesn't (just get garbage).
The windows are set to be initially invisible.  This code is probably
incredibly naive.  What's the proper way?  Lightspeed C, by the way.

BitMap offScreenBits;    /* The offscreen bitmap. */
Rect boundsRect;    /* The copy bounds. */

/* This function works fine. */
Ptr NewBitMap(b, r)
BitMap *b;
Rect r;
{
	b->rowBytes = ((r.right - r.left + 15) / 16) * 2;
	b->baseAddr = NewPtr(b->rowBytes * (r.bottom - r.top));
	b->bounds = r;
	if(MemError() != noErr)
	   return NULL;
   else return b->baseAddr;
}

func()
{
	int i, firstWID = 128;
	WindowPtr w;

   boundsRect.left = 2;
   boundsRect.right = 510;
   boundsRect.top = 20;
   boundsRect.bottom = 340;
   if(NewBitMap(&offScreenBits, boundsRect) == NULL)
	   return errorcode;
																	   
   for(i = 0; i < 4; i++)
   {
	   w = GetNewWindow(firstWID + i, NULL, (WindowPtr)-1L);
	   SetPort(w);
	   SetPortBits(&offScreenBits);
	   ShowWindow(w);
	   DrawStuff(w);
	   SetPortBits(&screenBits);
	}
	CopyBits(&offScreenBits, &screenBits, &offScreenBits.bounds,
									   &boundsRect, srcCopy, NULL);
}



Michael Domino @ SUNY/Buffalo
internet: domino@cs.buffalo.edu
uucp:     ..!{rutgers,watmath,boulder,decvax}!sunybcs!domino
BITNET:   domino@sunybcs.BITNET       phone:    716-881-6420
Technical Details
Message-ID: <7784@sunybcs.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!sunybcs!domino

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!sunybcs!domino
From: domino@sunybcs (Michael Domino)
Newsgroups: comp.sys.mac
Subject: Question About Offscreen Bitmaps...
Keywords: bitmaps, windows
Message-ID: <7784@sunybcs.UUCP>
Date: 12 Jan 88 21:38:06 GMT
Sender: nobody@sunybcs.UUCP
Reply-To: domino@sunybcs.UUCP (Michael Domino)
Distribution: na
Organization: SUNY/Buffalo Computer Science
Lines: 62