6.3. Loading Image Files

breve supports three image file formats: 1) SGI, 2) JPEG, 3) PNG. Though JPEG is the most common, most graphics programs can output images in all three formats. Specifically, the shareware program Graphic Converter can convert between the three formats.

PNG is the preferred image format—it allows more control over how the image is loaded into a texture. Support for the SGI format is provided for backwards compatibility. Support for the JPEG format is provided because it is somewhat more common than PNG.

Image files to be loaded must be square, and the length of the sides of the images must be a power of two (for example, 256x256 or 128x128).

When loading images, breve needs to be supplied information about transparency, typically called the alpha channel. If an alpha channel is provided in the image, then the alpha channel is used to determine transparency. If no alpha channel is given, breve uses the color intensity to determine transparency, such that white is fully transparent, and black is totally opaque. JPEG does not support alpha channels, so the intensity method is always used for JPEGs. This is the main reason that PNG is the preferred format.

To load the image or texture, use the Control.tz method load-image. The method takes a string containing the filename of the image file to load and returns a number representing the loaded image. If -1 is returned, then an error occurred and the file could not be read. Otherwise, the number returned will be used to refer to the image later on.