Name
BeginDoubleBuffer -- start double buffering for current display (V2.0)
Synopsis
BeginDoubleBuffer([hardware])
Function
This command puts the current display in double buffering mode. The graphics that are drawn after this command was called will not be visible until you call Flip(). Double buffering is used to avoid that screen updates are visible to the user. As the name implies, you have two buffers in double buffering mode: A front buffer (visible to the user) and a back buffer (in memory). Your screen updates are always drawn to the back (memory) buffer and when you are finished with that, you call the Flip() command to bring the back buffer to the front. After that, you can draw the next update. This technique ensures that no flickering will be visible because Flip() will always refresh the whole display in one go.

Double buffers are extremely useful if many graphics have to be drawn in a screen update. If you only need to move a little player image around, you should better use sprites because that is faster. Remember that a double buffered display will always refresh the whole screen. Thus, if you have an application running in 640x480 at 25fps, it will be quite some work for Hollywood because it has to draw a screen of 640x480 25 times a second.

Double buffers are installed on a per display basis. Thus, when you call BeginDoubleBuffer(), it will change the currently selected display into a double-buffered one. It will not change all displays to double-buffered! If you want all your displays to be double-buffered, you need to call BeginDoubleBuffer() for each of your displays.

Some restrictions apply:

Starting with Hollywood 5.0, there is a new optional argument hardware that allows you to enable hardware double buffering. On supported systems, this is much faster than software double buffering because it will completely operate in video memory which can use the GPU for drawing. There are some restrictions, though: If you use a hardware double buffer, you should draw to it using hardware brushes whenever this is possible. All other drawing commands will be much slower! Only by using hardware brushes can you get full hardware accelerated drawing. Using normal drawing functions with a hardware double buffer can even be slower than using them on a software double buffer. This is especially the case with graphics that use an alpha channel, e.g. anti-aliased text or vector shapes, because for alpha channel drawing, Hollywood has to read from the destination device which will be very slow for hardware double buffers because reading from video memory is very slow. Thus, you should try to use hardware brushes whereever possible when you work with a hardware double buffer. See hardware brushes for details.

Please note that currently hardware double buffering is only supported on AmigaOS and Android by default. However, plugins that install a display adapter are also able to support hardware double buffers for their display adapter. In that case you can also use hardware double buffers on systems other than AmigaOS and Android. For example, the GL Galore and RebelSDL plugins allow you to use hardware double buffers on Windows, macOS, and Linux. See Obtaining plugins for details.

Please note that Hollywood might also fall back to single buffering on some systems. Therefore, it is not safe to assume that calling Flip() will really switch buffers. It could also just draw the single buffer and then simply let you draw on it again.

Inputs
hardware
optional: whether or not to create a hardware double buffer (defaults to False which means software double buffering) (V5.0)
Example
BeginDoubleBuffer()
CreateBrush(1, 64, 64, #RED)
For k = -64 To 640
   Cls
   DisplayBrush(1, k, #CENTER)
   Flip
Next
EndDoubleBuffer()
The code above moves a red rectangle from the outer left to the outer right without any visible flickering. This is not a good example because we only move a little image around. It is a lot of overhead to refresh the whole 640x480 pixels just for this little image, so you should better use sprites in this case. Remember that double buffering is only recommended when there are a lot of graphics to draw.

Show TOC