home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!cs.utexas.edu!tamsun.tamu.edu!bpb9204
- From: bpb9204@tamsun.tamu.edu (Brent)
- Subject: Offscreen bitmap problem
- Message-ID: <1992Sep5.045203.25253@tamsun.tamu.edu>
- Organization: Texas A&M Univ., Inc.
- Distribution: usa
- Date: Sat, 5 Sep 1992 04:52:03 GMT
- Lines: 103
-
-
- Hello! (I'll warn you now, this post is long)
-
- I am writing a small fractal graphics application that generates basic B/W
- images. Most of the program is done and I am now working on updating the
- image after it has been uncovered. For starters, my image window is 208x208
- and the pixels are set as I calculate each. When this image window gets
- covered and then uncovered, I need to update the newly visible area quickly.
- Since fractals take a while to generate, I decided on using an offscreen
- bitmap and draw to both bitmaps simultaneously. Then, do a CopyBits from
- the offscreen to the image window for an update. Does this sound reasonable?
-
- I looked up the info concerning offscreen bitmaps in the UMPG -- Glenn Austin
- had a note in there (the only one) about using offscreen bitmaps. I
- followed his instructions, but I can't get it to work. I am enclosing some
- of my code to show what is going on; please bear with me.
-
- -----------------
- Global variables:
-
- WindowPtr gMainWindow -- the main image window (208x208)
- BitMap gOffBM -- offscreen bitmap
- GrafPort gOffGP -- offscreeen port
-
-
- SetupOffscreen() is called at appl. startup, as part of the initialization
- process. Error detection has been removed from this code for length.
-
- void SetupOffscreen(void)
- {
- gOffBM.rowBytes = 26; // 208/8
- SetRect( &gOffBM.bounds, 0,0, 207,207);
- gOffBM.baseAddr = NewPtrClear( 26* 208); // 208 rows at 26 bytes each.
- if (gOffBM.baseAddr != NULL)
- {
- OpenPort( &gOffGP);
- SetPortBits( &gOffBM);
- gOffGP.portRect = gOffBM.bounds;
- RectRgn( gOffGP.visRgn, &gOffBM.bounds);
- // SetPort( &gOffGP);
- }
- }
-
-
- The next fragment is from my loops to calculate the fractal. It scans from
- top to bottom, left to right, plotting each pixel as it calculates it.
- This code draws the image correctly to gMainWindow:
-
-
- if ( (dabs(z.r) < 10.0) || (dabs(z.i) < 10.0) )
- {
- SetPort(gMainWindow); // plot the main window's image
- PenPat( black);
- MoveTo(x, y);
- Line(0,0); // plot the pixel
-
- SetPort( &gOffGP); // plot the offscreen bitmap's image
- PenPat( black);
- MoveTo(x, y);
- Line(0,0); // plot the pixel
- }
- else
- {
- // do the same as above, but PenPat(white) for both ports.
- }
-
-
- Say that the image has been drawn and some window is on top of gMainWindow.
- When gMainWindow is uncovered and I get the update event, here is the
- code that runs for the update:
-
-
- [...]
- else if (gMainWindow == (WindowPtr)theEvent->message)
- {
- Print("Main update");
- GetPort(&savedPort);
- BeginUpdate(gMainWindow);
- SetPort(gMainWindow);
- EraseRect(&gMainWindow->portRect);
- CopyBits( &gOffBM, &gMainWindow->portBits,
- &gOffBM.bounds, &gMainWindow->portBits.bounds,
- srcCopy, NULL);
- EndUpdate(gMainWindow);
- SetPort(savedPort);
- }
- ------------------ end of code parts.
-
- What happens, you might ask? Well, when I get the update event, this last
- section of code executes and the uncovered area is painted white. This
- implies that the offscreen bitmap is not getting set, but I think I have
- followed directions OK. (Inside mac is vague about offscreen ports).
-
- All the code I have here is exactly what is in my program (pasted from it).
- All error checks find things are happening OK, also.
-
- If you can find any problems with the above code, please let me know. I'm
- new to this offscreen bitmap stuff and a friend of mine has my mac program-
- ming books.
-
- Thanks,
- -Brent
- bpb9204@tamsun.tamu.edu
-