5 Module ALLEGRO4
gullradriel edited this page 2026-10-29 20:54:40 +01:00

GRAPHICS: Allegro 4 compatibility layer

Structures

Name
struct RGB
palette entry, unused in 32 bit mode
struct BITMAP
Allegro 4 bitmap.

Types

Name
typedef int32_t fixed
16.16 fixed point number

Functions

Name
void vline(BITMAP * bmp, int x, int y1, int y2, int color)
draw a vertical line
int ustricmp(const char * s1, const char * s2)
case insensitive string compare
void triangle(BITMAP * bmp, int x1, int y1, int x2, int y2, int x3, int y3, int color)
draw a filled triangle
void textprintf_right_ex(BITMAP * bmp, const FONT * f, int x, int y, int color, int bg, const char * format, ... )
draw a formatted string ending at x
void textprintf_ex(BITMAP * bmp, const FONT * f, int x, int y, int color, int bg, const char * format, ... )
draw a formatted string
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
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
void textout_ex(BITMAP * bmp, const FONT * f, const char * s, int x, int y, int color, int bg)
draw a string
void textout_centre_ex(BITMAP * bmp, const FONT * f, const char * s, int x, int y, int color, int bg)
draw a string centred on x
int text_length(const FONT * f, const char * str)
width of str in pixels
int text_height(const FONT * f)
height of the font in pixels
void stretch_sprite(BITMAP * bmp, BITMAP * sprite, int x, int y, int w, int h)
draw a sprite scaled to w x h
void stretch_blit(BITMAP * source, BITMAP * dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height)
copy and scale a rectangle
void stop_sample(const SAMPLE * spl)
stop every playing instance of a sample
void stop_midi(void )
stop the MIDI song
void solid_mode(void )
same as drawing_mode(DRAW_MODE_SOLID, ...)
void show_mouse(BITMAP * bmp)
show the system cursor (bmp != NULL) or hide it (NULL)
void set_window_title(const char * name)
set the window title
void set_volume(int digi_volume, int midi_volume)
set the volumes (0-255), a negative value leaves one unchanged
void set_uformat(int type)
no-op, kept for source compatibility
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
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
void set_color_depth(int depth)
set the color depth, only 32 is honoured
int set_close_button_callback(void(*)(void) proc)
call proc when the window close button is pressed
void set_alpha_blender(void )
blend with the alpha channel of the source colour or sprite
int save_bitmap(const char * filename, BITMAP * bmp, const RGB * pal)
save a bitmap
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 rotate_scaled_sprite(BITMAP * bmp, BITMAP * sprite, int x, int y, fixed angle, fixed scale)
rotate and scale a sprite around its centre
void rest(unsigned int ms)
sleep ms milliseconds
void remove_sound(void )
stop the audio
void remove_int(void(*)(void) proc)
stop calling proc
void rectfill(BITMAP * bmp, int x1, int y1, int x2, int y2, int color)
draw a filled rectangle
void rect(BITMAP * bmp, int x1, int y1, int x2, int y2, int color)
draw a rectangle outline
int readkey(void )
wait for a key: (scancode << 8)
void putpixel(BITMAP * bmp, int x, int y, int color)
write a pixel
void position_mouse(int x, int y)
move the mouse pointer
int poll_mouse(void )
no-op, input is updated by a thread
int poll_keyboard(void )
no-op, input is updated by a thread
int play_sample(const SAMPLE * spl, int vol, int pan, int freq, int loop)
play a sample: vol and pan 0-255, freq 1000 = normal speed
int play_midi(MIDI * midi, int loop)
play a MIDI song, replacing the current one, NULL stops
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 pivot_scaled_sprite(BITMAP * bmp, BITMAP * sprite, int x, int y, int cx, int cy, fixed angle, fixed scale)
rotate and scale a sprite around (cx,cy) in the sprite, drawn at (x,y)
void midi_resume(void )
resume the MIDI song
void midi_pause(void )
pause the MIDI song
void masked_stretch_blit(BITMAP * source, BITMAP * dest, int source_x, int source_y, int source_w, int source_h, int dest_x, int dest_y, int dest_w, int dest_h)
copy and scale a rectangle, skipping mask colour pixels
void masked_blit(BITMAP * source, BITMAP * dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height)
copy a rectangle, skipping mask colour pixels
int makecol32(int r, int g, int b)
make an opaque colour
int makecol(int r, int g, int b)
make an opaque colour
int makeacol32(int r, int g, int b, int a)
make a colour with alpha
int makeacol(int r, int g, int b, int a)
make a colour with alpha
FONT * load_ttf_font_mem(const char * filename, int points, int smooth)
same as load_ttf_font()
FONT * load_ttf_font(const char * filename, int points, int smooth)
load a TrueType font at the given pixel size
SAMPLE * load_sample(const char * filename)
load a WAV, OGG, FLAC or VOC file
MIDI * load_midi(const char * filename)
load a MIDI file
BITMAP * load_bitmap(const char * filename, RGB * pal)
load a BMP, PCX, TGA, PNG or JPG file, pal is ignored
void line(BITMAP * bmp, int x1, int y1, int x2, int y2, int color)
draw a line
int lexMenuRun(LexMenu * menu, BITMAP * buf)
run the menu, drawing into buf: the chosen item index, -1 on escape
BITMAP * lexMenuGetBitmap(LexMenu * menu, int item, int state)
the image of item item in state state, NULL if there is none
LexMenu * lexMenuDestroy(LexMenu * menu)
free a menu, returns NULL
LexMenu * lexLoadMenuFromFile(const char * file, const char * section)
load menu section from INI file file, NULL on error
int keypressed(void )
TRUE if a key is waiting in the readkey() buffer.
int is_memory_bitmap(BITMAP * bmp)
always FALSE: pixels are reached through bmp_write_line()
int install_timer(void )
no-op, timers are always available
int install_sound(int digi, int midi, const char * cfg_path)
start the audio, cfg_path is ignored
int install_mouse(void )
start the input thread for the mouse
int install_keyboard(void )
start the input thread for the keyboard
int install_int_ex(void(*)(void) proc, long speed)
call proc every speed timer ticks, from the timer thread
int install_int(void(*)(void) proc, int speed)
call proc every speed milliseconds, from the timer thread
int install_allegro_gl(void )
no-op, the layer always uses Allegro 5's own driver
void hline(BITMAP * bmp, int x1, int y, int x2, int color)
draw a horizontal line
int gfx_status(int action, int value)
with GET, MODE_OGL when the current mode is an AllegroGL one, else MODE_STD
int gfx_mode(int mode, int w, int h, int v_w, int v_h, int depth, double r, double g, double b, double a)
set the color depth and the graphics mode in one go, clearing the screen to (r,g,b), components in 0-1 or 0-255; TRUE or FALSE
int getr(int c)
red component
int getpixel(BITMAP * bmp, int x, int y)
read a pixel, -1 outside the bitmap
int getg(int c)
green component
int getb(int c)
blue component
int geta(int c)
alpha component, 255 for an opaque colour
void get_mouse_mickeys(int * mickeyx, int * mickeyy)
movement since the last call
int get_color_depth(void )
return the color depth (always 32)
void fill_str(char * str, int c, size_t len)
fill len bytes of str with c
void ellipsefill(BITMAP * bmp, int x, int y, int rx, int ry, int color)
draw a filled ellipse
void ellipse(BITMAP * bmp, int x, int y, int rx, int ry, int color)
draw an ellipse outline
void drawing_mode(int mode, BITMAP * pattern, int x_anchor, int y_anchor)
set the drawing mode of primitives, pattern arguments are ignored
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)
void draw_sprite_vh_flip(BITMAP * bmp, BITMAP * sprite, int x, int y)
draw a sprite mirrored both ways
void draw_sprite_v_flip(BITMAP * bmp, BITMAP * sprite, int x, int y)
draw a sprite mirrored vertically
void draw_sprite_h_flip(BITMAP * bmp, BITMAP * sprite, int x, int y)
draw a sprite mirrored horizontally
void draw_sprite(BITMAP * bmp, BITMAP * sprite, int x, int y)
draw a sprite
void destroy_sample(SAMPLE * spl)
free a sample, stopping it
void destroy_midi(MIDI * midi)
free a MIDI song, stopping it if it plays
void destroy_font(FONT * f)
free a font loaded with load_ttf_font()
void destroy_bitmap(BITMAP * bmp)
free a bitmap
BITMAP * create_video_bitmap(int width, int height)
same as create_bitmap()
BITMAP * create_bitmap_ex(int depth, int width, int height)
same as create_bitmap(), depth is ignored
BITMAP * create_bitmap(int width, int height)
create a w x h bitmap
void clear_to_color(BITMAP * bmp, int color)
clear to a colour
void clear_keybuf(void )
empty the readkey() buffer
void clear_bitmap(BITMAP * bmp)
clear to black
void clear(BITMAP * bmp)
clear to black
void circlefill(BITMAP * bmp, int x, int y, int radius, int color)
draw a filled circle
void circle(BITMAP * bmp, int x, int y, int radius, int color)
draw a circle outline
uintptr_t bmp_write_line(BITMAP * bmp, int y)
lock the bitmap and return the address of line y, 32 bit ARGB pixels
void bmp_unwrite_line(BITMAP * bmp)
no-op, the bitmap is unlocked when next drawn with the GPU
void bmp_select(BITMAP * bmp)
no-op
uintptr_t bmp_read_line(BITMAP * bmp, int y)
lock the bitmap and return the address of line y, 32 bit ARGB pixels
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
int bitmap_mask_color(BITMAP * bmp)
the mask colour, magenta
int bitmap_color_depth(BITMAP * bmp)
always 32
void allegro_message(const char * format, ... )
show a message: a box over the screen, or stderr without a display
int allegro_init(void )
init the layer and Allegro 5
void allegro_gl_unset_allegro_mode(void )
no-op
void allegro_gl_set_allegro_mode(void )
no-op
void allegro_gl_flip(void )
show the screen bitmap
void allegro_exit(void )
shut everything down
int alert(const char * s1, const char * s2, const char * s3, const char * b1, const char * b2, int c1, int c2)
a box with up to three lines and one or two buttons (b2 may be NULL), chosen with the mouse, the c1 / c2 shortcut keys, Enter (first) or Escape (second): 1 or 2
void adjust_sample(const SAMPLE * spl, int vol, int pan, int freq, int loop)
change the settings of the playing instances of a sample
int a4_get_keyboard(char * keybuf, int * cur, int flags, int max)
read the typed keys into keybuf at *cur (printable ASCII, backspace erases), keeping it nul terminated within max bytes; flags is ignored.
uint32_t _a4_pixel_from_color(int color)
store a colour as it is kept in a bitmap (opaque when its alpha byte is 0)

Attributes

Name
BITMAP * screen
the screen, valid after set_gfx_mode()
volatile int mouse_z
mouse wheel position
volatile int mouse_y
mouse y in screen coordinates
volatile int mouse_x
mouse x in screen coordinates
volatile int mouse_b
button flags: 1 left, 2 right, 4 middle
volatile int key_shifts
modifier flags, unused
volatile char[227] key
TRUE while the key is held.
FONT * font
the default 8x8 font, valid after allegro_init()
char[256] allegro_error
last error message, as in Allegro 4
const char * SAMPLE
Every block kind at once, so one measure covers the lot.

Defines

Name
itofix(x)
int to fixed
glClear(mask)
no-op: screen is redrawn whole on every flip
get_keyboard
the old nilorea name of a4_get_keyboard()
ftofix(x)
double to fixed
fixtoi(x)
fixed to int, rounded
fixtof(x)
fixed to double
bmp_write8(addr, c)
write a pixel at addr, only 32 bit bitmaps exist
bmp_write32(addr, c)
write a 32 bit pixel at addr
bmp_write24(addr, c)
write a pixel at addr, only 32 bit bitmaps exist
bmp_write16(addr, c)
write a pixel at addr, only 32 bit bitmaps exist
bmp_write15(addr, c)
write a pixel at addr, only 32 bit bitmaps exist
U_UTF8
unicode format id, ignored
U_ASCII
unicode format id, ignored
TIMERS_PER_SECOND
ticks per second of install_int_ex() speeds
SET
gfx_status() action: set the status (same value as n_common.h's)
SECS_TO_TIMER(x)
convert seconds to timer ticks
SCREEN_W
screen width
SCREEN_H
screen height
MSEC_TO_TIMER(x)
convert milliseconds to timer ticks
MODE_STD
gfx_status() value: a non OpenGL mode
MODE_OGL
gfx_status() value: an AllegroGL mode
MIDI_NONE
no MIDI
MIDI_AUTODETECT
any MIDI driver
LOCK_VARIABLE(x)
no-op
LOCK_FUNCTION(x)
no-op
LEX_MENU_OVER
item state for lexMenuGetBitmap(): under the pointer
LEX_MENU_NORMAL
item state for lexMenuGetBitmap(): normal
KEY_Z
key code
KEY_Y
key code
KEY_X
key code
KEY_W
key code
KEY_V
key code
KEY_UP
key code
KEY_U
key code
KEY_TAB
key code
KEY_T
key code
KEY_SPACE
key code
KEY_S
key code
KEY_RSHIFT
key code
KEY_RIGHT
key code
KEY_RCONTROL
key code
KEY_R
key code
KEY_Q
key code
KEY_PGUP
key code
KEY_PGDN
key code
KEY_P
key code
KEY_O
key code
KEY_N
key code
KEY_MAX
number of entries in key[]
KEY_M
key code
KEY_LSHIFT
key code
KEY_LEFT
key code
KEY_LCONTROL
key code
KEY_L
key code
KEY_K
key code
KEY_J
key code
KEY_INSERT
key code
KEY_I
key code
KEY_HOME
key code
KEY_H
key code
KEY_G
key code
KEY_F9
key code
KEY_F8
key code
KEY_F7
key code
KEY_F6
key code
KEY_F5
key code
KEY_F4
key code
KEY_F3
key code
KEY_F2
key code
KEY_F12
key code
KEY_F11
key code
KEY_F10
key code
KEY_F1
key code
KEY_F
key code
KEY_ESC
key code
KEY_ENTER_PAD
key code
KEY_ENTER
key code
KEY_END
key code
KEY_E
key code
KEY_DOWN
key code
KEY_DEL
key code
KEY_D
key code
KEY_C
key code
KEY_BACKSPACE
key code
KEY_B
key code
KEY_ALTGR
key code
KEY_ALT
key code
KEY_A
key code
KEY_9
key code
KEY_8
key code
KEY_7
key code
KEY_6
key code
KEY_5
key code
KEY_4
key code
KEY_3
key code
KEY_2
key code
KEY_1
key code
KEY_0
key code
GL_COLOR_BUFFER_BIT
no-op: screen is redrawn whole on every flip
GFX_TEXT
leave graphics mode
GFX_SAFE
windowed
GFX_OPENGL_WINDOWED
AllegroGL windowed: screen is shown on allegro_gl_flip() only.
GFX_OPENGL_FULLSCREEN
AllegroGL fullscreen: screen is shown on allegro_gl_flip() only.
GFX_OPENGL
AllegroGL, windowed.
GFX_DIRECTX_WIN
DirectX windowed, mapped to windowed.
GFX_DIRECTX
DirectX fullscreen, mapped to fullscreen.
GFX_AUTODETECT_WINDOWED
windowed
GFX_AUTODETECT_FULLSCREEN
fullscreen
GFX_AUTODETECT
any mode, windowed here
GET
gfx_status() action: read the status (same value as n_common.h's)
END_OF_STATIC_FUNCTION(x)
no-op
END_OF_MAIN()
no-op, Allegro 5 programs need no END_OF_MAIN
END_OF_FUNCTION(x)
no-op
DRAW_MODE_TRANS
drawing mode: blend with the current blender
DRAW_MODE_SOLID
drawing mode: plain copy
DIGI_NONE
no digital sound
DIGI_AUTODETECT
any digital driver
BPS_TO_TIMER(x)
convert beats per second to timer ticks
BPM_TO_TIMER(x)
convert beats per minute to timer ticks
ALLEGTTF_TTFSMOOTH
anti aliased
ALLEGTTF_REALSMOOTH
anti aliased
ALLEGTTF_NOSMOOTH
no anti aliasing
ALLEGRO_ERROR_SIZE
size of the allegro_error buffer

Types Documentation

typedef fixed

typedef int32_t fixed;

16.16 fixed point number

Functions Documentation

function vline

void vline(
    BITMAP * bmp,
    int x,
    int y1,
    int y2,
    int color
)

draw a vertical line

function ustricmp

int ustricmp(
    const char * s1,
    const char * s2
)

case insensitive string compare

function triangle

void triangle(
    BITMAP * bmp,
    int x1,
    int y1,
    int x2,
    int y2,
    int x3,
    int y3,
    int color
)

draw a filled triangle

function textprintf_right_ex

void textprintf_right_ex(
    BITMAP * bmp,
    const FONT * f,
    int x,
    int y,
    int color,
    int bg,
    const char * format,
    ... 
)

draw a formatted string ending at x

function textprintf_ex

void textprintf_ex(
    BITMAP * bmp,
    const FONT * f,
    int x,
    int y,
    int color,
    int bg,
    const char * format,
    ... 
)

draw a formatted string

function textprintf_centre_ex

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

function textout_right_ex

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

function textout_ex

void textout_ex(
    BITMAP * bmp,
    const FONT * f,
    const char * s,
    int x,
    int y,
    int color,
    int bg
)

draw a string

function textout_centre_ex

void textout_centre_ex(
    BITMAP * bmp,
    const FONT * f,
    const char * s,
    int x,
    int y,
    int color,
    int bg
)

draw a string centred on x

function text_length

int text_length(
    const FONT * f,
    const char * str
)

width of str in pixels

function text_height

int text_height(
    const FONT * f
)

height of the font in pixels

function stretch_sprite

void stretch_sprite(
    BITMAP * bmp,
    BITMAP * sprite,
    int x,
    int y,
    int w,
    int h
)

draw a sprite scaled to w x h

function stretch_blit

void stretch_blit(
    BITMAP * source,
    BITMAP * dest,
    int source_x,
    int source_y,
    int source_width,
    int source_height,
    int dest_x,
    int dest_y,
    int dest_width,
    int dest_height
)

copy and scale a rectangle

function stop_sample

void stop_sample(
    const SAMPLE * spl
)

stop every playing instance of a sample

function stop_midi

void stop_midi(
    void 
)

stop the MIDI song

function solid_mode

void solid_mode(
    void 
)

same as drawing_mode(DRAW_MODE_SOLID, ...)

function show_mouse

void show_mouse(
    BITMAP * bmp
)

show the system cursor (bmp != NULL) or hide it (NULL)

function set_window_title

void set_window_title(
    const char * name
)

set the window title

function set_volume

void set_volume(
    int digi_volume,
    int midi_volume
)

set the volumes (0-255), a negative value leaves one unchanged

function set_uformat

void set_uformat(
    int type
)

no-op, kept for source compatibility

function set_trans_blender

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

function set_gfx_mode

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

function set_color_depth

void set_color_depth(
    int depth
)

set the color depth, only 32 is honoured

function set_close_button_callback

int set_close_button_callback(
    void(*)(void) proc
)

call proc when the window close button is pressed

function set_alpha_blender

void set_alpha_blender(
    void 
)

blend with the alpha channel of the source colour or sprite

function save_bitmap

int save_bitmap(
    const char * filename,
    BITMAP * bmp,
    const RGB * pal
)

save a bitmap

function rotate_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

function rotate_scaled_sprite

void rotate_scaled_sprite(
    BITMAP * bmp,
    BITMAP * sprite,
    int x,
    int y,
    fixed angle,
    fixed scale
)

rotate and scale a sprite around its centre

function rest

void rest(
    unsigned int ms
)

sleep ms milliseconds

function remove_sound

void remove_sound(
    void 
)

stop the audio

function remove_int

void remove_int(
    void(*)(void) proc
)

stop calling proc

function rectfill

void rectfill(
    BITMAP * bmp,
    int x1,
    int y1,
    int x2,
    int y2,
    int color
)

draw a filled rectangle

function rect

void rect(
    BITMAP * bmp,
    int x1,
    int y1,
    int x2,
    int y2,
    int color
)

draw a rectangle outline

function readkey

int readkey(
    void 
)

wait for a key: (scancode << 8) | ascii

function putpixel

void putpixel(
    BITMAP * bmp,
    int x,
    int y,
    int color
)

write a pixel

function position_mouse

void position_mouse(
    int x,
    int y
)

move the mouse pointer

function poll_mouse

int poll_mouse(
    void 
)

no-op, input is updated by a thread

function poll_keyboard

int poll_keyboard(
    void 
)

no-op, input is updated by a thread

function play_sample

int play_sample(
    const SAMPLE * spl,
    int vol,
    int pan,
    int freq,
    int loop
)

play a sample: vol and pan 0-255, freq 1000 = normal speed

function play_midi

int play_midi(
    MIDI * midi,
    int loop
)

play a MIDI song, replacing the current one, NULL stops

function pivot_sprite

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)

function pivot_scaled_sprite

void pivot_scaled_sprite(
    BITMAP * bmp,
    BITMAP * sprite,
    int x,
    int y,
    int cx,
    int cy,
    fixed angle,
    fixed scale
)

rotate and scale a sprite around (cx,cy) in the sprite, drawn at (x,y)

function midi_resume

void midi_resume(
    void 
)

resume the MIDI song

function midi_pause

void midi_pause(
    void 
)

pause the MIDI song

function masked_stretch_blit

void masked_stretch_blit(
    BITMAP * source,
    BITMAP * dest,
    int source_x,
    int source_y,
    int source_w,
    int source_h,
    int dest_x,
    int dest_y,
    int dest_w,
    int dest_h
)

copy and scale a rectangle, skipping mask colour pixels

function masked_blit

void masked_blit(
    BITMAP * source,
    BITMAP * dest,
    int source_x,
    int source_y,
    int dest_x,
    int dest_y,
    int width,
    int height
)

copy a rectangle, skipping mask colour pixels

function makecol32

int makecol32(
    int r,
    int g,
    int b
)

make an opaque colour

function makecol

int makecol(
    int r,
    int g,
    int b
)

make an opaque colour

function makeacol32

int makeacol32(
    int r,
    int g,
    int b,
    int a
)

make a colour with alpha

function makeacol

int makeacol(
    int r,
    int g,
    int b,
    int a
)

make a colour with alpha

function load_ttf_font_mem

FONT * load_ttf_font_mem(
    const char * filename,
    int points,
    int smooth
)

same as load_ttf_font()

function load_ttf_font

FONT * load_ttf_font(
    const char * filename,
    int points,
    int smooth
)

load a TrueType font at the given pixel size

function load_sample

SAMPLE * load_sample(
    const char * filename
)

load a WAV, OGG, FLAC or VOC file

function load_midi

MIDI * load_midi(
    const char * filename
)

load a MIDI file

function load_bitmap

BITMAP * load_bitmap(
    const char * filename,
    RGB * pal
)

load a BMP, PCX, TGA, PNG or JPG file, pal is ignored

function line

void line(
    BITMAP * bmp,
    int x1,
    int y1,
    int x2,
    int y2,
    int color
)

draw a line

function lexMenuRun

int lexMenuRun(
    LexMenu * menu,
    BITMAP * buf
)

run the menu, drawing into buf: the chosen item index, -1 on escape

function lexMenuGetBitmap

BITMAP * lexMenuGetBitmap(
    LexMenu * menu,
    int item,
    int state
)

the image of item item in state state, NULL if there is none

function lexMenuDestroy

LexMenu * lexMenuDestroy(
    LexMenu * menu
)

free a menu, returns NULL

function lexLoadMenuFromFile

LexMenu * lexLoadMenuFromFile(
    const char * file,
    const char * section
)

load menu section from INI file file, NULL on error

function keypressed

int keypressed(
    void 
)

TRUE if a key is waiting in the readkey() buffer.

function is_memory_bitmap

int is_memory_bitmap(
    BITMAP * bmp
)

always FALSE: pixels are reached through bmp_write_line()

function install_timer

int install_timer(
    void 
)

no-op, timers are always available

function install_sound

int install_sound(
    int digi,
    int midi,
    const char * cfg_path
)

start the audio, cfg_path is ignored

function install_mouse

int install_mouse(
    void 
)

start the input thread for the mouse

function install_keyboard

int install_keyboard(
    void 
)

start the input thread for the keyboard

function install_int_ex

int install_int_ex(
    void(*)(void) proc,
    long speed
)

call proc every speed timer ticks, from the timer thread

function install_int

int install_int(
    void(*)(void) proc,
    int speed
)

call proc every speed milliseconds, from the timer thread

function install_allegro_gl

int install_allegro_gl(
    void 
)

no-op, the layer always uses Allegro 5's own driver

function hline

void hline(
    BITMAP * bmp,
    int x1,
    int y,
    int x2,
    int color
)

draw a horizontal line

function gfx_status

int gfx_status(
    int action,
    int value
)

with GET, MODE_OGL when the current mode is an AllegroGL one, else MODE_STD

function gfx_mode

int gfx_mode(
    int mode,
    int w,
    int h,
    int v_w,
    int v_h,
    int depth,
    double r,
    double g,
    double b,
    double a
)

set the color depth and the graphics mode in one go, clearing the screen to (r,g,b), components in 0-1 or 0-255; TRUE or FALSE

function getr

int getr(
    int c
)

red component

function getpixel

int getpixel(
    BITMAP * bmp,
    int x,
    int y
)

read a pixel, -1 outside the bitmap

function getg

int getg(
    int c
)

green component

function getb

int getb(
    int c
)

blue component

function geta

int geta(
    int c
)

alpha component, 255 for an opaque colour

function get_mouse_mickeys

void get_mouse_mickeys(
    int * mickeyx,
    int * mickeyy
)

movement since the last call

function get_color_depth

int get_color_depth(
    void 
)

return the color depth (always 32)

function fill_str

void fill_str(
    char * str,
    int c,
    size_t len
)

fill len bytes of str with c

function ellipsefill

void ellipsefill(
    BITMAP * bmp,
    int x,
    int y,
    int rx,
    int ry,
    int color
)

draw a filled ellipse

function ellipse

void ellipse(
    BITMAP * bmp,
    int x,
    int y,
    int rx,
    int ry,
    int color
)

draw an ellipse outline

function drawing_mode

void drawing_mode(
    int mode,
    BITMAP * pattern,
    int x_anchor,
    int y_anchor
)

set the drawing mode of primitives, pattern arguments are ignored

function draw_trans_sprite

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)

function draw_sprite_vh_flip

void draw_sprite_vh_flip(
    BITMAP * bmp,
    BITMAP * sprite,
    int x,
    int y
)

draw a sprite mirrored both ways

function draw_sprite_v_flip

void draw_sprite_v_flip(
    BITMAP * bmp,
    BITMAP * sprite,
    int x,
    int y
)

draw a sprite mirrored vertically

function draw_sprite_h_flip

void draw_sprite_h_flip(
    BITMAP * bmp,
    BITMAP * sprite,
    int x,
    int y
)

draw a sprite mirrored horizontally

function draw_sprite

void draw_sprite(
    BITMAP * bmp,
    BITMAP * sprite,
    int x,
    int y
)

draw a sprite

function destroy_sample

void destroy_sample(
    SAMPLE * spl
)

free a sample, stopping it

function destroy_midi

void destroy_midi(
    MIDI * midi
)

free a MIDI song, stopping it if it plays

function destroy_font

void destroy_font(
    FONT * f
)

free a font loaded with load_ttf_font()

function destroy_bitmap

void destroy_bitmap(
    BITMAP * bmp
)

free a bitmap

function create_video_bitmap

BITMAP * create_video_bitmap(
    int width,
    int height
)

same as create_bitmap()

function create_bitmap_ex

BITMAP * create_bitmap_ex(
    int depth,
    int width,
    int height
)

same as create_bitmap(), depth is ignored

function create_bitmap

BITMAP * create_bitmap(
    int width,
    int height
)

create a w x h bitmap

function clear_to_color

void clear_to_color(
    BITMAP * bmp,
    int color
)

clear to a colour

function clear_keybuf

void clear_keybuf(
    void 
)

empty the readkey() buffer

function clear_bitmap

void clear_bitmap(
    BITMAP * bmp
)

clear to black

function clear

void clear(
    BITMAP * bmp
)

clear to black

function circlefill

void circlefill(
    BITMAP * bmp,
    int x,
    int y,
    int radius,
    int color
)

draw a filled circle

function circle

void circle(
    BITMAP * bmp,
    int x,
    int y,
    int radius,
    int color
)

draw a circle outline

function bmp_write_line

uintptr_t bmp_write_line(
    BITMAP * bmp,
    int y
)

lock the bitmap and return the address of line y, 32 bit ARGB pixels

function bmp_unwrite_line

void bmp_unwrite_line(
    BITMAP * bmp
)

no-op, the bitmap is unlocked when next drawn with the GPU

function bmp_select

void bmp_select(
    BITMAP * bmp
)

no-op

function bmp_read_line

uintptr_t bmp_read_line(
    BITMAP * bmp,
    int y
)

lock the bitmap and return the address of line y, 32 bit ARGB pixels

function blit

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

function bitmap_mask_color

int bitmap_mask_color(
    BITMAP * bmp
)

the mask colour, magenta

function bitmap_color_depth

int bitmap_color_depth(
    BITMAP * bmp
)

always 32

function allegro_message

void allegro_message(
    const char * format,
    ... 
)

show a message: a box over the screen, or stderr without a display

function allegro_init

int allegro_init(
    void 
)

init the layer and Allegro 5

function allegro_gl_unset_allegro_mode

void allegro_gl_unset_allegro_mode(
    void 
)

no-op

function allegro_gl_set_allegro_mode

void allegro_gl_set_allegro_mode(
    void 
)

no-op

function allegro_gl_flip

void allegro_gl_flip(
    void 
)

show the screen bitmap

function allegro_exit

void allegro_exit(
    void 
)

shut everything down

function alert

int alert(
    const char * s1,
    const char * s2,
    const char * s3,
    const char * b1,
    const char * b2,
    int c1,
    int c2
)

a box with up to three lines and one or two buttons (b2 may be NULL), chosen with the mouse, the c1 / c2 shortcut keys, Enter (first) or Escape (second): 1 or 2

function adjust_sample

void adjust_sample(
    const SAMPLE * spl,
    int vol,
    int pan,
    int freq,
    int loop
)

change the settings of the playing instances of a sample

function a4_get_keyboard

int a4_get_keyboard(
    char * keybuf,
    int * cur,
    int flags,
    int max
)

read the typed keys into keybuf at *cur (printable ASCII, backspace erases), keeping it nul terminated within max bytes; flags is ignored.

Returns the number of keys taken. Old nilorea code calls it get_keyboard(), which the macro below keeps working; the linked symbol is a4_get_keyboard because n_allegro5.h already has a get_keyboard() with another signature, and both live in the same library

function _a4_pixel_from_color

uint32_t _a4_pixel_from_color(
    int color
)

store a colour as it is kept in a bitmap (opaque when its alpha byte is 0)

Attributes Documentation

variable screen

BITMAP * screen;

the screen, valid after set_gfx_mode()

variable mouse_z

volatile int mouse_z;

mouse wheel position

variable mouse_y

volatile int mouse_y;

mouse y in screen coordinates

variable mouse_x

volatile int mouse_x;

mouse x in screen coordinates

variable mouse_b

volatile int mouse_b;

button flags: 1 left, 2 right, 4 middle

variable key_shifts

volatile int key_shifts;

modifier flags, unused

variable key

volatile char[227] key;

TRUE while the key is held.

variable font

FONT * font;

the default 8x8 font, valid after allegro_init()

variable allegro_error

char[256] allegro_error;

last error message, as in Allegro 4

variable SAMPLE

static const char * SAMPLE                      =
"# A heading\n"
"\n"
"A paragraph with **bold**, *italic*, `code` and a\n"
"[link](https://example.com/page) in it, hard wrapped by whoever wrote it\n"
"and re-wrapped by the renderer.\n"
"\n"
"## A smaller heading\n"
"\n"
"> a quoted line\n"
"\n"
"```\n"
"a fenced code block\n"
"keeping its own line breaks\n"
"```\n"
"\n"
"- a list item\n"
"- one that carries on\n"
"  onto a second line\n"
"\n"
"| Key | Effect |\n"
"|:----|-------:|\n"
"| `G` | back to the grid |\n"
"| Escape | close a dialog, otherwise go back to the grid |\n";

Every block kind at once, so one measure covers the lot.

a sound sample

Macros Documentation

define itofix

#define itofix(
    x
)
((fixed)((x) * 65536))

int to fixed

define glClear

#define glClear(
    mask
)
((void)(mask))

no-op: screen is redrawn whole on every flip

define get_keyboard

#define get_keyboard a4_get_keyboard

the old nilorea name of a4_get_keyboard()

define ftofix

#define ftofix(
    x
)
((fixed)((x) * 65536.0 + ((x) < 0 ? -0.5 : 0.5)))

double to fixed

define fixtoi

#define fixtoi(
    x
)
((int)(((x) + 0x8000) >> 16))

fixed to int, rounded

define fixtof

#define fixtof(
    x
)
((double)(x) / 65536.0)

fixed to double

define bmp_write8

#define bmp_write8(
    addr,
    c
)
bmp_write32(addr, c)

write a pixel at addr, only 32 bit bitmaps exist

define bmp_write32

#define bmp_write32(
    addr,
    c
)
(*((uint32_t*)(uintptr_t)(addr)) = _a4_pixel_from_color(c))

write a 32 bit pixel at addr

define bmp_write24

#define bmp_write24(
    addr,
    c
)
bmp_write32(addr, c)

write a pixel at addr, only 32 bit bitmaps exist

define bmp_write16

#define bmp_write16(
    addr,
    c
)
bmp_write32(addr, c)

write a pixel at addr, only 32 bit bitmaps exist

define bmp_write15

#define bmp_write15(
    addr,
    c
)
bmp_write32(addr, c)

write a pixel at addr, only 32 bit bitmaps exist

define U_UTF8

#define U_UTF8 0x55544638

unicode format id, ignored

define U_ASCII

#define U_ASCII 0x41534338

unicode format id, ignored

define TIMERS_PER_SECOND

#define TIMERS_PER_SECOND 1193181L

ticks per second of install_int_ex() speeds

define SET

#define SET 1234

gfx_status() action: set the status (same value as n_common.h's)

define SECS_TO_TIMER

#define SECS_TO_TIMER(
    x
)
((long)(x) * TIMERS_PER_SECOND)

convert seconds to timer ticks

define SCREEN_W

#define SCREEN_W (screen ? screen->w : 0)

screen width

define SCREEN_H

#define SCREEN_H (screen ? screen->h : 0)

screen height

define MSEC_TO_TIMER

#define MSEC_TO_TIMER(
    x
)
((long)(x) * (TIMERS_PER_SECOND / 1000))

convert milliseconds to timer ticks

define MODE_STD

#define MODE_STD 0

gfx_status() value: a non OpenGL mode

define MODE_OGL

#define MODE_OGL 1

gfx_status() value: an AllegroGL mode

define MIDI_NONE

#define MIDI_NONE 0

no MIDI

define MIDI_AUTODETECT

#define MIDI_AUTODETECT -1

any MIDI driver

define LOCK_VARIABLE

#define LOCK_VARIABLE(
    x
)

no-op

define LOCK_FUNCTION

#define LOCK_FUNCTION(
    x
)

no-op

define LEX_MENU_OVER

#define LEX_MENU_OVER 1

item state for lexMenuGetBitmap(): under the pointer

define LEX_MENU_NORMAL

#define LEX_MENU_NORMAL 0

item state for lexMenuGetBitmap(): normal

define KEY_Z

#define KEY_Z 26

key code

define KEY_Y

#define KEY_Y 25

key code

define KEY_X

#define KEY_X 24

key code

define KEY_W

#define KEY_W 23

key code

define KEY_V

#define KEY_V 22

key code

define KEY_UP

#define KEY_UP 84

key code

define KEY_U

#define KEY_U 21

key code

define KEY_TAB

#define KEY_TAB 64

key code

define KEY_T

#define KEY_T 20

key code

define KEY_SPACE

#define KEY_SPACE 75

key code

define KEY_S

#define KEY_S 19

key code

define KEY_RSHIFT

#define KEY_RSHIFT 216

key code

define KEY_RIGHT

#define KEY_RIGHT 83

key code

define KEY_RCONTROL

#define KEY_RCONTROL 218

key code

define KEY_R

#define KEY_R 18

key code

define KEY_Q

#define KEY_Q 17

key code

define KEY_PGUP

#define KEY_PGUP 80

key code

define KEY_PGDN

#define KEY_PGDN 81

key code

define KEY_P

#define KEY_P 16

key code

define KEY_O

#define KEY_O 15

key code

define KEY_N

#define KEY_N 14

key code

define KEY_MAX

#define KEY_MAX 227

number of entries in key[]

define KEY_M

#define KEY_M 13

key code

define KEY_LSHIFT

#define KEY_LSHIFT 215

key code

define KEY_LEFT

#define KEY_LEFT 82

key code

define KEY_LCONTROL

#define KEY_LCONTROL 217

key code

define KEY_L

#define KEY_L 12

key code

define KEY_K

#define KEY_K 11

key code

define KEY_J

#define KEY_J 10

key code

define KEY_INSERT

#define KEY_INSERT 76

key code

define KEY_I

#define KEY_I 9

key code

define KEY_HOME

#define KEY_HOME 78

key code

define KEY_H

#define KEY_H 8

key code

define KEY_G

#define KEY_G 7

key code

define KEY_F9

#define KEY_F9 55

key code

define KEY_F8

#define KEY_F8 54

key code

define KEY_F7

#define KEY_F7 53

key code

define KEY_F6

#define KEY_F6 52

key code

define KEY_F5

#define KEY_F5 51

key code

define KEY_F4

#define KEY_F4 50

key code

define KEY_F3

#define KEY_F3 49

key code

define KEY_F2

#define KEY_F2 48

key code

define KEY_F12

#define KEY_F12 58

key code

define KEY_F11

#define KEY_F11 57

key code

define KEY_F10

#define KEY_F10 56

key code

define KEY_F1

#define KEY_F1 47

key code

define KEY_F

#define KEY_F 6

key code

define KEY_ESC

#define KEY_ESC 59

key code

define KEY_ENTER_PAD

#define KEY_ENTER_PAD 91

key code

define KEY_ENTER

#define KEY_ENTER 67

key code

define KEY_END

#define KEY_END 79

key code

define KEY_E

#define KEY_E 5

key code

define KEY_DOWN

#define KEY_DOWN 85

key code

define KEY_DEL

#define KEY_DEL 77

key code

define KEY_D

#define KEY_D 4

key code

define KEY_C

#define KEY_C 3

key code

define KEY_BACKSPACE

#define KEY_BACKSPACE 63

key code

define KEY_B

#define KEY_B 2

key code

define KEY_ALTGR

#define KEY_ALTGR 220

key code

define KEY_ALT

#define KEY_ALT 219

key code

define KEY_A

#define KEY_A 1

key code

define KEY_9

#define KEY_9 36

key code

define KEY_8

#define KEY_8 35

key code

define KEY_7

#define KEY_7 34

key code

define KEY_6

#define KEY_6 33

key code

define KEY_5

#define KEY_5 32

key code

define KEY_4

#define KEY_4 31

key code

define KEY_3

#define KEY_3 30

key code

define KEY_2

#define KEY_2 29

key code

define KEY_1

#define KEY_1 28

key code

define KEY_0

#define KEY_0 27

key code

define GL_COLOR_BUFFER_BIT

#define GL_COLOR_BUFFER_BIT 0x00004000

no-op: screen is redrawn whole on every flip

define GFX_TEXT

#define GFX_TEXT -1

leave graphics mode

define GFX_SAFE

#define GFX_SAFE 3

windowed

define GFX_OPENGL_WINDOWED

#define GFX_OPENGL_WINDOWED 6

AllegroGL windowed: screen is shown on allegro_gl_flip() only.

define GFX_OPENGL_FULLSCREEN

#define GFX_OPENGL_FULLSCREEN 7

AllegroGL fullscreen: screen is shown on allegro_gl_flip() only.

define GFX_OPENGL

#define GFX_OPENGL 8

AllegroGL, windowed.

define GFX_DIRECTX_WIN

#define GFX_DIRECTX_WIN 5

DirectX windowed, mapped to windowed.

define GFX_DIRECTX

#define GFX_DIRECTX 4

DirectX fullscreen, mapped to fullscreen.

define GFX_AUTODETECT_WINDOWED

#define GFX_AUTODETECT_WINDOWED 2

windowed

define GFX_AUTODETECT_FULLSCREEN

#define GFX_AUTODETECT_FULLSCREEN 1

fullscreen

define GFX_AUTODETECT

#define GFX_AUTODETECT 0

any mode, windowed here

define GET

#define GET 4321

gfx_status() action: read the status (same value as n_common.h's)

define END_OF_STATIC_FUNCTION

#define END_OF_STATIC_FUNCTION(
    x
)

no-op

define END_OF_MAIN

#define END_OF_MAIN(
    
)

no-op, Allegro 5 programs need no END_OF_MAIN

define END_OF_FUNCTION

#define END_OF_FUNCTION(
    x
)

no-op

define DRAW_MODE_TRANS

#define DRAW_MODE_TRANS 5

drawing mode: blend with the current blender

define DRAW_MODE_SOLID

#define DRAW_MODE_SOLID 0

drawing mode: plain copy

define DIGI_NONE

#define DIGI_NONE 0

no digital sound

define DIGI_AUTODETECT

#define DIGI_AUTODETECT -1

any digital driver

define BPS_TO_TIMER

#define BPS_TO_TIMER(
    x
)
(TIMERS_PER_SECOND / (long)(x))

convert beats per second to timer ticks

define BPM_TO_TIMER

#define BPM_TO_TIMER(
    x
)
((60 * TIMERS_PER_SECOND) / (long)(x))

convert beats per minute to timer ticks

define ALLEGTTF_TTFSMOOTH

#define ALLEGTTF_TTFSMOOTH 1

anti aliased

define ALLEGTTF_REALSMOOTH

#define ALLEGTTF_REALSMOOTH 2

anti aliased

define ALLEGTTF_NOSMOOTH

#define ALLEGTTF_NOSMOOTH 0

no anti aliasing

define ALLEGRO_ERROR_SIZE

#define ALLEGRO_ERROR_SIZE 256

size of the allegro_error buffer