50 " -V log level: LOG_INFO, LOG_NOTICE, LOG_ERR, LOG_DEBUG\n"
51 " -s render one frame to ex_allegro_4.png and exit\n"
57 while ((
getoptret = getopt(argc, argv,
"hvsV:")) != EOF) {
60 fprintf(stderr,
"Date de compilation : %s a %s.\n", __DATE__, __TIME__);
63 if (!strncmp(
"LOG_NULL", optarg, 8)) {
65 }
else if (!strncmp(
"LOG_NOTICE", optarg, 10)) {
67 }
else if (!strncmp(
"LOG_INFO", optarg, 8)) {
69 }
else if (!strncmp(
"LOG_ERR", optarg, 7)) {
71 }
else if (!strncmp(
"LOG_DEBUG", optarg, 9)) {
74 fprintf(stderr,
"%s is not a valid log level\n", optarg);
93 if (!spr)
return NULL;
103static int expect(
BITMAP* bmp,
int x,
int y,
int r,
int g,
int b,
const char* what) {
106 n_log(
LOG_ERR,
"%s: pixel %d,%d is %d,%d,%d, expected %d,%d,%d", what, x, y,
getr(c),
getg(c),
getb(c), r, g, b);
118 rect(buf, 20, 20, 219, 119,
makecol(255, 255, 255));
141 for (
int y = 0; y < 40; y++) {
146 for (
int x = 0; x < 40; x++)
putpixel(buf, 530 + x, 280,
makecol(255, 255, 255));
149 textprintf_ex(buf,
font, 20, 400,
makecol(255, 255, 255), -1,
"Allegro 4 on Allegro 5: %dx%d, t=%.1f",
SCREEN_W,
SCREEN_H, t);
150 textprintf_centre_ex(buf,
font, buf->
w / 2, 430,
makecol(0, 0, 0),
makecol(255, 220, 0),
" centred, with a background ");
154int main(
int argc,
char** argv) {
202 ok =
expect(buf, 21, 151, 20, 30, 60,
"draw_sprite mask") && ok;
203 ok =
expect(buf, 32, 182, 240, 200, 40,
"draw_sprite body") && ok;
204 ok =
expect(buf, 100, 30, 60, 120, 60,
"rectfill") && ok;
205 ok =
expect(buf, 485, 265, 30, 30, 128,
"bmp_write32") && ok;
206 ok =
expect(buf, 540, 280, 255, 255, 255,
"putpixel") && ok;
209 if (abs(
getr(c) - 137) > 2 || abs(
getg(c) - 15) > 2 || abs(
getb(c) - 30) > 2) {
223 ok =
expect(fade, 2, 2, 44, 44, 44,
"fade step at opacity 64") && ok;
224 for (
int i = 0; i < 255; i++)
rectfill(fade, 0, 0, 7, 7,
makeacol(0, 0, 0, 1));
226 ok =
expect(fade, 2, 2, 0, 0, 0,
"fade to black at opacity 1") && ok;
238 n_log(
LOG_NOTICE,
"ex_allegro_4: %s", ok ?
"all checks passed" :
"some checks FAILED");
static volatile int close_asked
static BITMAP * make_sprite(void)
static void close_cb(void)
static void draw_scene(BITMAP *buf, BITMAP *spr, double t)
static int expect(BITMAP *bmp, int x, int y, int r, int g, int b, const char *what)
static int screenshot_mode
void process_args(int argc, char **argv)
int install_mouse(void)
start the input thread for the mouse
uintptr_t bmp_write_line(BITMAP *bmp, int y)
lock the bitmap and return the address of line y, 32 bit ARGB pixels
void draw_sprite_h_flip(BITMAP *bmp, BITMAP *sprite, int x, int y)
draw a sprite mirrored horizontally
void destroy_bitmap(BITMAP *bmp)
free a bitmap
void set_trans_blender(int r, int g, int b, int a)
blend with a constant opacity a (0-255), r, g and b are ignored
void allegro_exit(void)
shut everything down
char allegro_error[256]
last error message, as in Allegro 4
int set_close_button_callback(void(*proc)(void))
call proc when the window close button is pressed
void bmp_unwrite_line(BITMAP *bmp)
no-op, the bitmap is unlocked when next drawn with the GPU
BITMAP * create_bitmap(int width, int height)
create a w x h bitmap
#define SCREEN_H
screen height
int bitmap_mask_color(BITMAP *bmp)
the mask colour, magenta
int getr(int c)
red component
void line(BITMAP *bmp, int x1, int y1, int x2, int y2, int color)
draw a line
volatile char key[227]
TRUE while the key is held.
int save_bitmap(const char *filename, BITMAP *bmp, const RGB *pal)
save a bitmap
void textout_right_ex(BITMAP *bmp, const FONT *f, const char *s, int x, int y, int color, int bg)
draw a string ending at x
FONT * font
the default 8x8 font, valid after allegro_init()
void textprintf_ex(BITMAP *bmp, const FONT *f, int x, int y, int color, int bg, const char *format,...)
draw a formatted string
void drawing_mode(int mode, BITMAP *pattern, int x_anchor, int y_anchor)
set the drawing mode of primitives, pattern arguments are ignored
#define itofix(x)
int to fixed
#define DRAW_MODE_SOLID
drawing mode: plain copy
#define ftofix(x)
double to fixed
#define bmp_write32(addr, c)
write a 32 bit pixel at addr
int makeacol(int r, int g, int b, int a)
make a colour with alpha
BITMAP * screen
the screen, valid after set_gfx_mode()
void set_alpha_blender(void)
blend with the alpha channel of the source colour or sprite
#define GFX_OPENGL_WINDOWED
AllegroGL windowed: screen is shown on allegro_gl_flip() only.
#define DRAW_MODE_TRANS
drawing mode: blend with the current blender
int install_keyboard(void)
start the input thread for the keyboard
int set_gfx_mode(int card, int w, int h, int v_w, int v_h)
open a display of w x h pixels, or close it with GFX_TEXT
int allegro_init(void)
init the layer and Allegro 5
int install_timer(void)
no-op, timers are always available
void circle(BITMAP *bmp, int x, int y, int radius, int color)
draw a circle outline
void set_window_title(const char *name)
set the window title
int makecol(int r, int g, int b)
make an opaque colour
#define fixtoi(x)
fixed to int, rounded
void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height)
copy a rectangle
void ellipsefill(BITMAP *bmp, int x, int y, int rx, int ry, int color)
draw a filled ellipse
void textprintf_centre_ex(BITMAP *bmp, const FONT *f, int x, int y, int color, int bg, const char *format,...)
draw a formatted string centred on x
int getb(int c)
blue component
#define SCREEN_W
screen width
int getg(int c)
green component
void draw_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y)
draw a sprite
void rotate_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle)
rotate a sprite around its centre, angle in 256ths of a turn, clockwise
void stretch_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int w, int h)
draw a sprite scaled to w x h
void putpixel(BITMAP *bmp, int x, int y, int color)
write a pixel
void set_color_depth(int depth)
set the color depth, only 32 is honoured
void clear_to_color(BITMAP *bmp, int color)
clear to a colour
void rectfill(BITMAP *bmp, int x1, int y1, int x2, int y2, int color)
draw a filled rectangle
void triangle(BITMAP *bmp, int x1, int y1, int x2, int y2, int x3, int y3, int color)
draw a filled triangle
void pivot_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle)
rotate a sprite around (cx,cy) in the sprite, drawn at (x,y)
void rest(unsigned int ms)
sleep ms milliseconds
void circlefill(BITMAP *bmp, int x, int y, int radius, int color)
draw a filled circle
void draw_sprite_v_flip(BITMAP *bmp, BITMAP *sprite, int x, int y)
draw a sprite mirrored vertically
void draw_trans_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y)
draw a sprite with the current blender (set_alpha_blender / set_trans_blender)
int getpixel(BITMAP *bmp, int x, int y)
read a pixel, -1 outside the bitmap
void allegro_gl_flip(void)
show the screen bitmap
void rect(BITMAP *bmp, int x1, int y1, int x2, int y2, int color)
draw a rectangle outline
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
#define LOG_NOTICE
normal but significant condition
#define LOG_NULL
no log output
#define LOG_INFO
informational
Allegro 4 compatibility layer on top of Allegro 5.
Common headers and low-level functions & define.