6.4. Displaying Objects as Bitmaps

Agents in breve can be displayed as images or textured to aid in visualization. If the object is set to be displayed as a certain image, then the object is always rendered facing forward. The first step is to load an image or texture into breve.

If you wish to texture the object, pass the image number to the Real.tz method set-texture; if you wish to display the object as the image, then pass the image number to the Real.tz method set-bitmap.

The following code loads an image and uses it as the bitmap image for an instance of the fictional class Bird:
	breveTexture = (self load-image from "breve.png"). 
	bird = new Bird. bird set-image to breveTexture.

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

Don't forget that the texture is set on an instance by instance basis, so you should call these methods for explicitly for each instance you want to texture or display as an image. Because the controller object must load the texture and usually holds the texture reference number, it can sometimes be a little difficult to set a texture when new objects are created by non-controller objects.

The solution is to define methods in the controller object which will return the image reference number. Any object in the simulation can thus access these numbers by using the controller variable and calling these methods. In this example, an object sets a certain texture during initialization:

	self set-texture to (controller get-tree-texture).