Displaying Objects as Bitmaps
<< previous | Chapter 6. Graphics and Sound | next >>

## Displaying Objects as Bitmaps

### Changed in breve 2.0

The methods used for bitmapping have been changed from breve 1.x, so pay close attention to this section if you're updating your simulation from a previous version of breve.

Agents in breve can be displayed as user-specified image files. This technique is referred to as bitmapping. If an object is set up for bitmapping, the bitmap image is shown instead of the 3D object and will always face forward, regardless of the viewer's perspective. This is in contrast to texturing, in which the image is used as a surface for a 3D shape. Texturing is described in the next section, Texturing Objects the section called “Texturing Objects”.

To set a bitmap image for an object in breve, the image must be loaded into breve as described in the previous section, Loading Image Files the section called “Loading Image Files”. Once the image has been loaded, you can set the bitmap image of an object by passing the image to the method "set-bitmap-image" found in Real.tz

The following code loads an image and uses it as the bitmap image for an instance of the class Bird (this example is taken from the Swarm demo):

            breveTexture = (new Image load from "breve.png").
            bird = new Bird.
            bird set-bitmap-image to breveTexture.

This technique is used in the Swarm demo to generate the flying breve logos shown below.

Don't forget that the bitmap is set on an instance by instance basis, so you should call these methods explicitly for each instance you want to bitmap.

Also note that loading multiple images uses up a lot of memory and hurts performance, even if you are loading the same image multiple times. It is therefore preferable to share the same image among many agents when possible. This may require the controller to load the image and pass it out to the agents, instead of having the agents load it themselves:

            # bad idea!

            self set-bitmap-image to (new Image load from "picture.png").

            # good idea!

            self set-bitmap-image to (controller get-shared-image).

<< previous | Up | next >>
Loading Image Files | Table of Contents | Texturing Objects