C (114/304)

From:Gabriele Svelto
Date:14 Aug 2000 at 01:35:09
Subject:Re: CGX and Bitmaps

Hi Rik,
I know something about double-buffering, hope this helps although I haven't tested it yet.
Basically this works like that: Once you opened the screen you allocate as much additional screen buffers you need (one for double-buffering, two for triple-buffering) with AllocScreenBuffer() from intuition.library using this parameters:

struct ScreenBuffer *scr_buffer;

scr_buffer = AllocScreenBuffer(scr, NULL, 0); /* scr is your Screen pointer */
or
scr_buffer = AllocScreenBuffer(scr, NULL, SB_SCREEN_BITMAP);

this second call will return the ScreenBuffer pointer to the screen's bitmap ('cos you need both the ScreenBuffers you allocated and the screen's one you need to make this call once, after opening the screen). The ScreenBuffer structures will contain a BitMap pointer (sb_BitMap) you can use for drawing. Once you want to swap the screen buffers you just call:

result = ChangeScreenBuffer(scr, scr_buffer);

This will install the new ScreenBuffer scr_buffer in the Screen scr and return a non-zero value on success or zero on failure. This call fails only if intuition doesn't allow swapping the buffers, this only happens if intuition is drawing on the screen a menu or gadget... If you disable intution for this screen using the SA_Quiet tag on OpenScreenTags() this should never happen. When quitting just free all the ScreenBuffers with FreeScreenBuffer() (including the Screen's one, beware!) and close the Screen.
Hope this helps, see ya

Gabriele