In DRAW_MODE_SOLID, pixels of the bitmap being drawn onto are simply replaced by those produced by the drawing function.DRAW_MODE_SOLID - the default, solid color drawing DRAW_MODE_XOR - exclusive-or drawing DRAW_MODE_COPY_PATTERN - multicolored pattern fill DRAW_MODE_SOLID_PATTERN - single color pattern fill DRAW_MODE_MASKED_PATTERN - masked pattern fill DRAW_MODE_TRANS - translucent color blending
In DRAW_MODE_XOR, pixels are written to the bitmap with an exclusive-or operation rather than a simple copy, so drawing the same shape twice will erase it. Because it involves reading as well as writing the bitmap memory, xor drawing is a lot slower than the normal replace mode.
With the patterned modes, you provide a pattern bitmap which is tiled across the surface of the shape. Allegro stores a pointer to this bitmap rather than copying it, so you must not destroy the bitmap while it is still selected as the pattern. The width and height of the pattern must be powers of two, but they can be different, eg. a 64x16 pattern is fine, but a 17x3 one is not. The pattern is tiled in a grid starting at point (x_anchor, y_anchor). Normally you should just pass zero for these values, which lets you draw several adjacent shapes and have the patterns meet up exactly along the shared edges. Zero alignment may look peculiar if you are moving a patterned shape around the screen, however, because the shape will move but the pattern alignment will not, so in some situations you may wish to alter the anchor position.
When you select DRAW_MODE_COPY_PATTERN, pixels are simply copied from the pattern bitmap onto the destination bitmap. This allows the use of multicolored patterns, and means that the color you pass to the drawing routine is ignored. This is the fastest of the patterned modes.
In DRAW_MODE_SOLID_PATTERN, each pixel in the pattern bitmap is compared with the mask color, which is zero in 256-color modes or bright pink for truecolor data (maximum red and blue, zero green). If the pattern pixel is solid, a pixel of the color you passed to the drawing routine is written to the destination bitmap, otherwise a zero is written. The pattern is thus treated as a monochrome bitmask, which lets you use the same pattern to draw different shapes in different colors, but prevents the use of multicolored patterns.
DRAW_MODE_MASKED_PATTERN is almost the same as DRAW_MODE_SOLID_PATTERN, but the masked pixels are skipped rather than being written as zeros, so the background shows through the gaps.
In DRAW_MODE_TRANS, the global color_map table or truecolor blender functions are used to overlay pixels on top of the existing image. This must only be used after you have set up the color mapping table (for 256 color modes) or blender functions (for truecolor modes). Because it involves reading as well as writing the bitmap memory, translucent drawing is very slow if you draw directly to video RAM, so wherever possible you should use a memory bitmap instead.
See also: xor_mode, solid_mode, color_map, set_trans_blender.
Examples using this: exalpha, excolmap, exjoy, expat, extrans.
See also: drawing_mode.
Examples using this: exspline, exupdate.
See also: drawing_mode.
Examples using this: exalpha, expat.
In paletted video modes, translucency and lighting are implemented with a 64k lookup table, which contains the result of combining any two colors c1 and c2. You must set up this table before you use any of the translucency or lighting routines. Depending on how you construct the table, a range of different effects are possible. For example, translucency can be implemented by using a color halfway between c1 and c2 as the result of the combination. Lighting is achieved by treating one of the colors as a light level (0-255) rather than a color, and setting up the table appropriately. A range of specialised effects are possible, for instance replacing any color with any other color and making individual source or destination colors completely solid or invisible. Color mapping tables can be precalculated with the colormap utility, or generated at runtime. Read chapter "Structures and types defined by Allegro" for an internal description of the COLOR_MAP structure.
color_map = malloc(sizeof(COLOR_MAP)); if (!color_map) abort_on_error("Not enough memory for color map!");
See also: create_color_table, create_light_table, create_trans_table, create_blender_table, set_trans_blender, draw_trans_sprite, draw_lit_sprite, draw_gouraud_sprite, drawing_mode.
Examples using this: ex3d, excolmap, exlights, exshade, extrans.
This function treats source color #0 as a special case, leaving the destination unchanged whenever a zero source pixel is encountered, so that masked sprites will draw correctly. This function will take advantage of the global rgb_map variable to speed up color conversions. If the callback function is not NULL, it will be called 256 times during the calculation, allowing you to display a progress indicator. Example:
COLOR_MAP trans_table; ... /* Build a color lookup table for translucent drawing. */ create_trans_table(&trans_table, pal, 128, 128, 128, NULL);
See also: color_map, create_light_table, create_color_table, create_blender_table, draw_trans_sprite, draw_lit_sprite, draw_gouraud_sprite, rgb_map.
Examples using this: ex3d, extrans.
This function will take advantage of the global rgb_ap variable to speed up color conversions. If the callback function is not NULL, it will be called 256 times during the calculation, allowing you to display a progress indicator. Example:
COLOR_MAP light_table; ... /* Build a color lookup table for lighting effects. */ create_light_table(&light_table, pal, 0, 0, 0, NULL);
See also: color_map, create_trans_table, create_color_table, create_blender_table, draw_trans_sprite, draw_lit_sprite, draw_gouraud_sprite, rgb_map.
Examples using this: ex3d, exshade, extrans.
Your blend routine will be passed a pointer to the palette and the two indices of the colors which are to be combined, and should fill in the RGB structure with the desired result in 0-63 format. Allegro will then search the palette for the closest match to the RGB color that you requested, so it doesn't matter if the palette has no exact match for this color.
If the callback function is not NULL, it will be called 256 times during the calculation, allowing you to display a progress indicator. Example:
COLOR_MAP greyscale_table; ... void return_grey_color(const PALETTE pal, int x, int y, RGB *rgb) { ... } ... /* Build a color lookup table for greyscale effect. */ create_color_table(&greyscale_table, pal, return_grey_color, NULL);
See also: color_map, create_light_table, create_trans_table, create_blender_table, draw_trans_sprite, draw_lit_sprite, draw_gouraud_sprite, rgb_map.
Examples using this: excolmap.
See also: color_map, create_light_table, create_trans_table, create_color_table, draw_trans_sprite, draw_lit_sprite, draw_gouraud_sprite, set_trans_blender, set_blender_mode.
In truecolor video modes, translucency and lighting are implemented by a blender function of the form:
unsigned long (*BLENDER_FUNC)(unsigned long x, y, n);
For each pixel to be drawn, this routine is passed two color parameters x and y, decomposes them into their red, green and blue components, combines them according to some mathematical transformation involving the interpolation factor n, and then merges the result back into a single return color value, which will be used to draw the pixel onto the destination bitmap.
The parameter x represents the blending modifier color and the parameter y represents the base color to be modified. The interpolation factor n is in the range [0-255] and controls the solidity of the blending.
When a translucent drawing function is used, x is the color of the source, y is the color of the bitmap being drawn onto and n is the alpha level that was passed to the function that sets the blending mode (the RGB triplet that was passed to this function is not taken into account).
When a lit sprite drawing function is used, x is the color represented by the RGB triplet that was passed to the function that sets the blending mode (the alpha level that was passed to this function is not taken into account), y is the color of the sprite and n is the alpha level that was passed to the drawing function itself.
Since these routines may be used from various different color depths, there are three such callbacks, one for use with 15-bit 5.5.5 pixels, one for 16 bit 5.6.5 pixels, and one for 24-bit 8.8.8 pixels (this can be shared between the 24 and 32-bit code since the bit packing is the same).
See also: set_blender_mode, set_alpha_blender, set_write_alpha_blender, color_map, draw_trans_sprite, draw_lit_sprite, drawing_mode, set_add_blender, set_burn_blender, set_color_blender, set_difference_blender, set_dissolve_blender, set_dodge_blender, set_hue_blender, set_invert_blender, set_luminance_blender, set_multiply_blender, set_saturation_blender, set_screen_blender.
Examples using this: ex3d, exblend, exrotscl, exshade, extrans, extrans2, exxfade.
See also: set_trans_blender, draw_trans_sprite, draw_trans_rle_sprite, set_write_alpha_blender.
Examples using this: exalpha, exrotscl, extrans.
See also: set_alpha_blender, draw_trans_sprite, drawing_mode.
Examples using this: exalpha, extrans.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
Examples using this: exalpha.
See also: set_trans_blender, drawing_mode.
See also: set_trans_blender, drawing_mode.
See also: set_blender_mode_ex, set_trans_blender, color_map, draw_trans_sprite, draw_lit_sprite, drawing_mode.
See also: set_blender_mode, set_alpha_blender.