Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!cbmvax!vu-vlsi!swatsun!jackiw From: jackiw@cs.swarthmore.edu (Nick Jackiw) Newsgroups: comp.sys.mac.programmer Subject: Re: Animation Questions Keywords: CopyBits, VBlank Message-ID: <3172@carthage.cs.swarthmore.edu> Date: 13 Oct 89 15:50:47 GMT References: <3123@crdgw1.crd.ge.com> Reply-To: jackiw@carthage (Nick Jackiw) Organization: Visual Geometry Project, Swarthmore College, PA Lines: 77 In article <3123@crdgw1.crd.ge.com> leue@galen.crd.ge.com (Bill Leue) writes: > [Discussion of offscreen animating] > However, there are still two glitches. First, the objects being animated > are sometimes "sheared" horizontally, so that they are torn into two > pieces which don't quite track each other as the object moves (say) > horizontally. I'm tenatively diagnosing this problem as a lack of > synchronization with the screen refresh. Am I right? Yes. > If so, I suspect > there's a mechanism to synchronize drawing with vertical blanking. Does > anyone have any lore (or posssibly code) they feel like sharing on this > subject? There are two cases. On the MAC 128, 128K/E, Plus, and SE, it's simple. The "tick counter" is installed as a VBL task in the screen's retrace interval. Consequently, waiting for the tickCount to change guarantees you're in the retrace interval. Code would look like this: var junk:longint; ... Delay(1,x); {Wait for next tick-count} CopyBits(...); {Start drawing as fast as you can} If you are drawing multiple objects per screen refresh, draw the ones closer to the top of the screen first. This helps keep your drawing "in front of" the electron gun. On the case of Macs with external video cards, the tick-count is not synchronized to your video redraw. Instead you'll have to make your own VBL task (which merely sets a flag visible to your application meaning "Draw now!") and install it in the VBL queue of the appropriate video card. E-mail for more details on this. > > Second, I am using "Classic" QuickDraw to perform limited color drawing. > I use ForeColor() and BackColor() calls along with a 50% grey pattern fill > to get a useful range of colors using dithering. In this way I can > get color objects on a color system, but don't have to make special code > for monochrome systems. It works fine, except that the objects which > are animated using CopyBits only display in black and white. I guess I > thought that since I was using the same QD calls to write to the offscreen > bitmap that I used to write the "static" portions of the screen, the > objects would also show up in color. Wrong! Anyone have an idea what I'm > doing wrong? Remember, I am NOT using Color QD at all -- just the 8 > colors in normal QD. You aren't doing anything wrong; you've come across a limitation of the (incredibly farseeing IMHO) original QD coloring scheme. While computers with CQD are capable of *drawing* any color they choose into your on-screen window, the bitmap in which the image is saved (i. e. yourPort^.portBits) is still only one-bit-deep (i. e. capable of expressing at most two colors). Consequently, any CopyBits(source->dest) call in which source is a 1-bit (old style) grafport can only interpret that image's data in terms of forecolor (bit=0) or backcolor (bit=1), regardless of how many different forecolors and backcolors were used in composing it. To overcome this, you'll need to go to a deeper bitmap, and get into true ColorQuickdraw. Alternately, you could create *separate* off-screen bitmaps for each "color separation" of your final object, and copyBits them (with a mask) on top of each other (changing forecolor+backcolor appropriately between calls) in your destination window. > Thanks! Hope it works. Is it, by chance, a *game?* God knows Macs could use more good animation games. > -Bill Leue > leue@crd.ge.com -- _ _|\____ Nick Jackiw | Visual Geometry Project | Math Department / /_/ O> \ ------------+-------------------------+ Swarthmore College | O> | 215-328-8225| jackiw@cs.swarthmore.edu| Swarthmore PA 19081 \_Guernica_/ ------------+-------------------------+ USA