Bitmap

Stores a bitmap and draws it to the screen.

const char *filename, int flags = [NONE] );

Constructs the Bitmap by loading a bitmap file. The loaded bitmap may contain an alpha channel. Works like the Load-method.

The only possibile flag is:
MAKE_COLLISION_POLY - Creates a collision polygon

const char *rgbFilename, const char *alphaFilename,
int flags = [NONE] );

Constructs the Bitmap by loading two separate bitmap files, one bitmap for the color information and one 8-bit bitmap for the transparency information. Works like the Load-method.

BITMAP *allegroBmp, int conversionMode, int flags = [NONE] );

Constructs the Bitmap from an Allegro BITMAP. The conversion mode should be one of these:

HAS_ALPHA_CHANNEL - Tells that the BITMAP has an alpha channel
CONVERT_MAGIC_PINK - Converts all magic pink pixels to transparent ones

OpenLayer doesn't free the passed BITMAP even if the Bitmap is destroyed.

int width, int height, Rgba fillColor );

Creates a new Bitmap filled with the specified color.

const Bitmap &other, const Rect &area );

Construct a sub-bitmap of an area of the given Bitmap.

template< class Functor > Bitmap(
int width, int height, Functor functor );

Creates a new Bitmap and calls the 'Rgba operator()(int x, int y)' of the functor object for each pixel.

If you need transparent or translucent parts in the bitmap you need to have an alpha channel for the bitmap. An alpha channel stores the opacity values for each pixel in the bitmap. The higher the alpha value, the more visible the pixel is.

If the alpha value of a pixel is the highest value (1.0) the pixel will be totally solid. But if the alpha value of a pixel is zero it'll be totally transparent and the pixel won't be rendered at all. If the alpha value is between 0.0 and 1.0 the pixel will be partially visible, depending on how high the alpha value is.

There's a version of every Bitmap rendering routine that also takes a RenderMode parameter which affects the way the Bitmap is rendered to the screen. Currently there are quite a few of RenderModes, like Tinted, Clipped and Flipped.

The pixel data will be automatically freed from the memory when the Bitmap object is destroyed. You can also manually free the bitmap data by calling the Destroy()-method.

Loading and destroying of global bitmaps and setting up the PNG image loading are automated now. If you have any dynamically allocated Bitmaps you can choose to let OpenLayer to free them when the program quits by calling the TextRenderer/UseAutoDelete.html">UseAutoDelete() -method.

And a final note about the copy constructor: It won't make a copy of the image, but instead the Bitmap copy will refer to the same image in the memory.

Examples

// Remember that Bitmaps can't be rendered until Setup::SetupProgram and Setup::SetupScreen are called! // 

// Construct a bitmap by loading a bitmap file //
Bitmap myBmp( "gfx/picture.png" );

// Draws the bitmap to the screen such that the top-left //
// corner of the bitmap will be positioned at x = 200, y = 100 //
myBmp.Blit200100 );

// Construct a Bitmap using an Allegro BITMAP with an alpha channel //
// and transparent magic pink pixels //
BITMAP *allegroBmp = create_bitmap(...);
Bitmap myBmp( allegroBmp, HAS_ALPHA_CHANNEL | CONVERT_MAGIC_PINK );

// Construct the Bitmap using a separate bitmap for //
// the color and the transparency information //
// Note that pictureOpacity.bmp must be an 8-bit bitmap! //
Bitmap myBmp( "gfx/picture.bmp""gfx/pictureOpacity.bmp" );


Member functions
Load
Loads the bitmap
Blit
Draws the Bitmap to the screen
BlitRotated
Draws the Bitmap to the screen rotated along a point
BlitStretched
Draws the Bitmap to the screen stretched to the specified size
BlitTransformed
Draws the Bitmap to the screen rotated and stretched
BlitDistorted
Draws the Bitmap to the screen with the given corner points
Width
Returns the width of the Bitmap
Height
Returns the height of the Bitmap
LoadListOfBitmaps
Loads a list of bitmaps from the disk
GetPixel
Returns the color value of a pixel
Destroy
Destroys the Bitmap
IsValid
Checks if the Bitmap was loaded correctly
Save
Saves the Bitmap to disk with the specified filename
CopyFromScreen
Copies a region of the game window to the Bitmap
GetMemoryBitmap
Returns a memory bitmap copy of (part of) the Bitmap
GetCollisionPoly
Returns the generated collision polygon for the Bitmap
SetDefaultPivot
Sets the default pivot point
GetDefaultPivot
Returns the default pivot point

Advanced functions

GetPixelPacked
Returns the color value of the specified pixel in a packed integer
SendToGPU
Sends the Bitmap to the graphics card
UnloadFromGPU
Unloads the Bitmap from the graphics card
Select
Selects the Bitmap as the active texture of OpenGL
UseAutoDelete
Chooses the Bitmap to be automatically deleted when the program quits
HasAlphaChannel
Checks if the Bitmap has an alpha channel
StartFastBlitting
This function should be called right before using FastBlit
FastBlit
A faster version of Blit
FinishFastBlitting
This function should be called after calling FastBlit
UnloadToMemory
Unloads the Bitmap from the graphics card keeping the image data saved in the Bitmap
TexturedQuad
Outputs a raw textured quad to the video card


Questions about Bitmap? Click here.