![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Allegro 4 compatibility layer on top of Allegro 5. More...
#include <stdint.h>#include <stdio.h>Go to the source code of this file.
Data Structures | |
| struct | BITMAP |
| Allegro 4 bitmap. More... | |
| struct | RGB |
| palette entry, unused in 32 bit mode More... | |
Macros | |
| #define | ALLEGRO_ERROR_SIZE 256 |
| size of the allegro_error buffer | |
| #define | ALLEGTTF_NOSMOOTH 0 |
| no anti aliasing | |
| #define | ALLEGTTF_REALSMOOTH 2 |
| anti aliased | |
| #define | ALLEGTTF_TTFSMOOTH 1 |
| anti aliased | |
| #define | bmp_write15(addr, c) |
| write a pixel at addr, only 32 bit bitmaps exist | |
| #define | bmp_write16(addr, c) |
| write a pixel at addr, only 32 bit bitmaps exist | |
| #define | bmp_write24(addr, c) |
| write a pixel at addr, only 32 bit bitmaps exist | |
| #define | bmp_write32(addr, c) |
| write a 32 bit pixel at addr | |
| #define | bmp_write8(addr, c) |
| write a pixel at addr, only 32 bit bitmaps exist | |
| #define | BPM_TO_TIMER(x) |
| convert beats per minute to timer ticks | |
| #define | BPS_TO_TIMER(x) |
| convert beats per second to timer ticks | |
| #define | DIGI_AUTODETECT -1 |
| any digital driver | |
| #define | DIGI_NONE 0 |
| no digital sound | |
| #define | DRAW_MODE_SOLID 0 |
| drawing mode: plain copy | |
| #define | DRAW_MODE_TRANS 5 |
| drawing mode: blend with the current blender | |
| #define | END_OF_FUNCTION(x) |
| no-op | |
| #define | END_OF_MAIN() |
| no-op, Allegro 5 programs need no END_OF_MAIN | |
| #define | END_OF_STATIC_FUNCTION(x) |
| no-op | |
| #define | fixtof(x) |
| fixed to double | |
| #define | fixtoi(x) |
| fixed to int, rounded | |
| #define | ftofix(x) |
| double to fixed | |
| #define | GET 4321 |
| gfx_status() action: read the status (same value as n_common.h's) | |
| #define | get_keyboard a4_get_keyboard |
| the old nilorea name of a4_get_keyboard() | |
| #define | GFX_AUTODETECT 0 |
| any mode, windowed here | |
| #define | GFX_AUTODETECT_FULLSCREEN 1 |
| fullscreen | |
| #define | GFX_AUTODETECT_WINDOWED 2 |
| windowed | |
| #define | GFX_DIRECTX 4 |
| DirectX fullscreen, mapped to fullscreen. | |
| #define | GFX_DIRECTX_WIN 5 |
| DirectX windowed, mapped to windowed. | |
| #define | GFX_OPENGL 8 |
| AllegroGL, windowed. | |
| #define | GFX_OPENGL_FULLSCREEN 7 |
| AllegroGL fullscreen: screen is shown on allegro_gl_flip() only. | |
| #define | GFX_OPENGL_WINDOWED 6 |
| AllegroGL windowed: screen is shown on allegro_gl_flip() only. | |
| #define | GFX_SAFE 3 |
| windowed | |
| #define | GFX_TEXT -1 |
| leave graphics mode | |
| #define | GL_COLOR_BUFFER_BIT 0x00004000 |
| no-op: screen is redrawn whole on every flip | |
| #define | glClear(mask) |
| no-op: screen is redrawn whole on every flip | |
| #define | itofix(x) |
| int to fixed | |
| #define | KEY_0 27 |
| key code | |
| #define | KEY_1 28 |
| key code | |
| #define | KEY_2 29 |
| key code | |
| #define | KEY_3 30 |
| key code | |
| #define | KEY_4 31 |
| key code | |
| #define | KEY_5 32 |
| key code | |
| #define | KEY_6 33 |
| key code | |
| #define | KEY_7 34 |
| key code | |
| #define | KEY_8 35 |
| key code | |
| #define | KEY_9 36 |
| key code | |
| #define | KEY_A 1 |
| key code | |
| #define | KEY_ALT 219 |
| key code | |
| #define | KEY_ALTGR 220 |
| key code | |
| #define | KEY_B 2 |
| key code | |
| #define | KEY_BACKSPACE 63 |
| key code | |
| #define | KEY_C 3 |
| key code | |
| #define | KEY_D 4 |
| key code | |
| #define | KEY_DEL 77 |
| key code | |
| #define | KEY_DOWN 85 |
| key code | |
| #define | KEY_E 5 |
| key code | |
| #define | KEY_END 79 |
| key code | |
| #define | KEY_ENTER 67 |
| key code | |
| #define | KEY_ENTER_PAD 91 |
| key code | |
| #define | KEY_ESC 59 |
| key code | |
| #define | KEY_F 6 |
| key code | |
| #define | KEY_F1 47 |
| key code | |
| #define | KEY_F10 56 |
| key code | |
| #define | KEY_F11 57 |
| key code | |
| #define | KEY_F12 58 |
| key code | |
| #define | KEY_F2 48 |
| key code | |
| #define | KEY_F3 49 |
| key code | |
| #define | KEY_F4 50 |
| key code | |
| #define | KEY_F5 51 |
| key code | |
| #define | KEY_F6 52 |
| key code | |
| #define | KEY_F7 53 |
| key code | |
| #define | KEY_F8 54 |
| key code | |
| #define | KEY_F9 55 |
| key code | |
| #define | KEY_G 7 |
| key code | |
| #define | KEY_H 8 |
| key code | |
| #define | KEY_HOME 78 |
| key code | |
| #define | KEY_I 9 |
| key code | |
| #define | KEY_INSERT 76 |
| key code | |
| #define | KEY_J 10 |
| key code | |
| #define | KEY_K 11 |
| key code | |
| #define | KEY_L 12 |
| key code | |
| #define | KEY_LCONTROL 217 |
| key code | |
| #define | KEY_LEFT 82 |
| key code | |
| #define | KEY_LSHIFT 215 |
| key code | |
| #define | KEY_M 13 |
| key code | |
| #define | KEY_MAX 227 |
| number of entries in key[] | |
| #define | KEY_N 14 |
| key code | |
| #define | KEY_O 15 |
| key code | |
| #define | KEY_P 16 |
| key code | |
| #define | KEY_PGDN 81 |
| key code | |
| #define | KEY_PGUP 80 |
| key code | |
| #define | KEY_Q 17 |
| key code | |
| #define | KEY_R 18 |
| key code | |
| #define | KEY_RCONTROL 218 |
| key code | |
| #define | KEY_RIGHT 83 |
| key code | |
| #define | KEY_RSHIFT 216 |
| key code | |
| #define | KEY_S 19 |
| key code | |
| #define | KEY_SPACE 75 |
| key code | |
| #define | KEY_T 20 |
| key code | |
| #define | KEY_TAB 64 |
| key code | |
| #define | KEY_U 21 |
| key code | |
| #define | KEY_UP 84 |
| key code | |
| #define | KEY_V 22 |
| key code | |
| #define | KEY_W 23 |
| key code | |
| #define | KEY_X 24 |
| key code | |
| #define | KEY_Y 25 |
| key code | |
| #define | KEY_Z 26 |
| key code | |
| #define | LEX_MENU_NORMAL 0 |
| item state for lexMenuGetBitmap(): normal | |
| #define | LEX_MENU_OVER 1 |
| item state for lexMenuGetBitmap(): under the pointer | |
| #define | LOCK_FUNCTION(x) |
| no-op | |
| #define | LOCK_VARIABLE(x) |
| no-op | |
| #define | MIDI_AUTODETECT -1 |
| any MIDI driver | |
| #define | MIDI_NONE 0 |
| no MIDI | |
| #define | MODE_OGL 1 |
| gfx_status() value: an AllegroGL mode | |
| #define | MODE_STD 0 |
| gfx_status() value: a non OpenGL mode | |
| #define | MSEC_TO_TIMER(x) |
| convert milliseconds to timer ticks | |
| #define | SCREEN_H (screen ? screen->h : 0) |
| screen height | |
| #define | SCREEN_W (screen ? screen->w : 0) |
| screen width | |
| #define | SECS_TO_TIMER(x) |
| convert seconds to timer ticks | |
| #define | SET 1234 |
| gfx_status() action: set the status (same value as n_common.h's) | |
| #define | TIMERS_PER_SECOND 1193181L |
| ticks per second of install_int_ex() speeds | |
| #define | U_ASCII 0x41534338 |
| unicode format id, ignored | |
| #define | U_UTF8 0x55544638 |
| unicode format id, ignored | |
Typedefs | |
| typedef int32_t | fixed |
| 16.16 fixed point number | |
Functions | |
| 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) | |
| 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. | |
| 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 | 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 | allegro_exit (void) |
| shut everything down | |
| void | allegro_gl_flip (void) |
| show the screen bitmap | |
| void | allegro_gl_set_allegro_mode (void) |
| no-op | |
| void | allegro_gl_unset_allegro_mode (void) |
| no-op | |
| int | allegro_init (void) |
| init the layer and Allegro 5 | |
| void | allegro_message (const char *format,...) |
| show a message: a box over the screen, or stderr without a display | |
| int | bitmap_color_depth (BITMAP *bmp) |
| always 32 | |
| int | bitmap_mask_color (BITMAP *bmp) |
| the mask colour, magenta | |
| 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 | |
| uintptr_t | bmp_read_line (BITMAP *bmp, int y) |
| lock the bitmap and return the address of line y, 32 bit ARGB pixels | |
| void | bmp_select (BITMAP *bmp) |
| no-op | |
| void | bmp_unwrite_line (BITMAP *bmp) |
| no-op, the bitmap is unlocked when next drawn with the GPU | |
| uintptr_t | bmp_write_line (BITMAP *bmp, int y) |
| lock the bitmap and return the address of line y, 32 bit ARGB pixels | |
| void | circle (BITMAP *bmp, int x, int y, int radius, int color) |
| draw a circle outline | |
| void | circlefill (BITMAP *bmp, int x, int y, int radius, int color) |
| draw a filled circle | |
| void | clear (BITMAP *bmp) |
| clear to black | |
| void | clear_bitmap (BITMAP *bmp) |
| clear to black | |
| void | clear_keybuf (void) |
| empty the readkey() buffer | |
| void | clear_to_color (BITMAP *bmp, int color) |
| clear to a colour | |
| BITMAP * | create_bitmap (int width, int height) |
| create a w x h bitmap | |
| BITMAP * | create_bitmap_ex (int depth, int width, int height) |
| same as create_bitmap(), depth is ignored | |
| BITMAP * | create_video_bitmap (int width, int height) |
| same as create_bitmap() | |
| void | destroy_bitmap (BITMAP *bmp) |
| free a bitmap | |
| void | destroy_font (FONT *f) |
| free a font loaded with load_ttf_font() | |
| void | destroy_midi (MIDI *midi) |
| free a MIDI song, stopping it if it plays | |
| void | destroy_sample (SAMPLE *spl) |
| free a sample, stopping it | |
| void | draw_sprite (BITMAP *bmp, BITMAP *sprite, int x, int y) |
| draw a sprite | |
| void | draw_sprite_h_flip (BITMAP *bmp, BITMAP *sprite, int x, int y) |
| draw a sprite mirrored horizontally | |
| void | draw_sprite_v_flip (BITMAP *bmp, BITMAP *sprite, int x, int y) |
| draw a sprite mirrored vertically | |
| void | draw_sprite_vh_flip (BITMAP *bmp, BITMAP *sprite, int x, int y) |
| draw a sprite mirrored both ways | |
| 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 | drawing_mode (int mode, BITMAP *pattern, int x_anchor, int y_anchor) |
| set the drawing mode of primitives, pattern arguments are ignored | |
| void | ellipse (BITMAP *bmp, int x, int y, int rx, int ry, int color) |
| draw an ellipse outline | |
| void | ellipsefill (BITMAP *bmp, int x, int y, int rx, int ry, int color) |
| draw a filled ellipse | |
| void | fill_str (char *str, int c, size_t len) |
| fill len bytes of str with c | |
| int | get_color_depth (void) |
| return the color depth (always 32) | |
| void | get_mouse_mickeys (int *mickeyx, int *mickeyy) |
| movement since the last call | |
| int | geta (int c) |
| alpha component, 255 for an opaque colour | |
| int | getb (int c) |
| blue component | |
| int | getg (int c) |
| green component | |
| int | getpixel (BITMAP *bmp, int x, int y) |
| read a pixel, -1 outside the bitmap | |
| int | getr (int c) |
| red component | |
| 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 | gfx_status (int action, int value) |
| with GET, MODE_OGL when the current mode is an AllegroGL one, else MODE_STD | |
| void | hline (BITMAP *bmp, int x1, int y, int x2, int color) |
| draw a horizontal line | |
| int | install_allegro_gl (void) |
| no-op, the layer always uses Allegro 5's own driver | |
| int | install_int (void(*proc)(void), int speed) |
| call proc every speed milliseconds, from the timer thread | |
| int | install_int_ex (void(*proc)(void), long speed) |
| call proc every speed timer ticks, from the timer thread | |
| int | install_keyboard (void) |
| start the input thread for the keyboard | |
| int | install_mouse (void) |
| start the input thread for the mouse | |
| int | install_sound (int digi, int midi, const char *cfg_path) |
| start the audio, cfg_path is ignored | |
| int | install_timer (void) |
| no-op, timers are always available | |
| int | is_memory_bitmap (BITMAP *bmp) |
| always FALSE: pixels are reached through bmp_write_line() | |
| int | keypressed (void) |
| TRUE if a key is waiting in the readkey() buffer. | |
| LexMenu * | lexLoadMenuFromFile (const char *file, const char *section) |
| load menu section from INI file file, NULL on error | |
| LexMenu * | lexMenuDestroy (LexMenu *menu) |
| free a menu, returns NULL | |
| BITMAP * | lexMenuGetBitmap (LexMenu *menu, int item, int state) |
| the image of item item in state state, NULL if there is none | |
| int | lexMenuRun (LexMenu *menu, BITMAP *buf) |
| run the menu, drawing into buf: the chosen item index, -1 on escape | |
| void | line (BITMAP *bmp, int x1, int y1, int x2, int y2, int color) |
| draw a line | |
| BITMAP * | load_bitmap (const char *filename, RGB *pal) |
| load a BMP, PCX, TGA, PNG or JPG file, pal is ignored | |
| MIDI * | load_midi (const char *filename) |
| load a MIDI file | |
| SAMPLE * | load_sample (const char *filename) |
| load a WAV, OGG, FLAC or VOC file | |
| FONT * | load_ttf_font (const char *filename, int points, int smooth) |
| load a TrueType font at the given pixel size | |
| FONT * | load_ttf_font_mem (const char *filename, int points, int smooth) |
| same as load_ttf_font() | |
| int | makeacol (int r, int g, int b, int a) |
| make a colour with alpha | |
| int | makeacol32 (int r, int g, int b, int a) |
| make a colour with alpha | |
| int | makecol (int r, int g, int b) |
| make an opaque colour | |
| int | makecol32 (int r, int g, int b) |
| make an opaque colour | |
| 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 | |
| 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 | midi_pause (void) |
| pause the MIDI song | |
| void | midi_resume (void) |
| resume the MIDI song | |
| 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 | 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) | |
| int | play_midi (MIDI *midi, int loop) |
| play a MIDI song, replacing the current one, NULL stops | |
| 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 | poll_keyboard (void) |
| no-op, input is updated by a thread | |
| int | poll_mouse (void) |
| no-op, input is updated by a thread | |
| void | position_mouse (int x, int y) |
| move the mouse pointer | |
| void | putpixel (BITMAP *bmp, int x, int y, int color) |
| write a pixel | |
| int | readkey (void) |
| wait for a key: (scancode << 8) | ascii | |
| void | rect (BITMAP *bmp, int x1, int y1, int x2, int y2, int color) |
| draw a rectangle outline | |
| void | rectfill (BITMAP *bmp, int x1, int y1, int x2, int y2, int color) |
| draw a filled rectangle | |
| void | remove_int (void(*proc)(void)) |
| stop calling proc | |
| void | remove_sound (void) |
| stop the audio | |
| void | rest (unsigned int ms) |
| sleep ms milliseconds | |
| 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 | 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 | |
| int | save_bitmap (const char *filename, BITMAP *bmp, const RGB *pal) |
| save a bitmap | |
| void | set_alpha_blender (void) |
| blend with the alpha channel of the source colour or sprite | |
| int | set_close_button_callback (void(*proc)(void)) |
| call proc when the window close button is pressed | |
| void | set_color_depth (int depth) |
| set the color depth, only 32 is honoured | |
| 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_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 | set_uformat (int type) |
| no-op, kept for source compatibility | |
| void | set_volume (int digi_volume, int midi_volume) |
| set the volumes (0-255), a negative value leaves one unchanged | |
| void | set_window_title (const char *name) |
| set the window title | |
| void | show_mouse (BITMAP *bmp) |
| show the system cursor (bmp != NULL) or hide it (NULL) | |
| void | solid_mode (void) |
| same as drawing_mode(DRAW_MODE_SOLID, ...) | |
| void | stop_midi (void) |
| stop the MIDI song | |
| void | stop_sample (const SAMPLE *spl) |
| stop every playing instance of a sample | |
| 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 | stretch_sprite (BITMAP *bmp, BITMAP *sprite, int x, int y, int w, int h) |
| draw a sprite scaled to w x h | |
| int | text_height (const FONT *f) |
| height of the font in pixels | |
| int | text_length (const FONT *f, const char *str) |
| width of str in pixels | |
| 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 | |
| void | textout_ex (BITMAP *bmp, const FONT *f, const char *s, int x, int y, int color, int bg) |
| draw a string | |
| 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 | 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 | textprintf_ex (BITMAP *bmp, const FONT *f, int x, int y, int color, int bg, const char *format,...) |
| draw a formatted string | |
| 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 | triangle (BITMAP *bmp, int x1, int y1, int x2, int y2, int x3, int y3, int color) |
| draw a filled triangle | |
| int | ustricmp (const char *s1, const char *s2) |
| case insensitive string compare | |
| void | vline (BITMAP *bmp, int x, int y1, int y2, int color) |
| draw a vertical line | |
Variables | |
| char | allegro_error [256] |
| last error message, as in Allegro 4 | |
| FONT * | font |
| the default 8x8 font, valid after allegro_init() | |
| volatile char | key [227] |
| TRUE while the key is held. | |
| volatile int | key_shifts |
| modifier flags, unused | |
| volatile int | mouse_b |
| button flags: 1 left, 2 right, 4 middle | |
| volatile int | mouse_x |
| mouse x in screen coordinates | |
| volatile int | mouse_y |
| mouse y in screen coordinates | |
| volatile int | mouse_z |
| mouse wheel position | |
| BITMAP * | screen |
| the screen, valid after set_gfx_mode() | |
Allegro 4 compatibility layer on top of Allegro 5.
Lets old Allegro 4 / AllegroGL / AllegTTF programs build and run on Allegro 5 with their drawing, input, timer and sound calls unchanged: replace the <allegro.h>, <alleggl.h>, <winalleg.h> and "allegttf.h" includes with this header and link the program with nilorea.
This header deliberately exposes Allegro 4 names (BITMAP, screen, key, clear(), line(), rest(), font, ...) at global scope, which is the whole point of it and also why it is NOT included by nilorea.h: include it only from a program that wants the Allegro 4 API. It does not include any Allegro 5 header, so a translation unit sees one API only.
Model:
Definition in file n_allegro_4.h.