The modules of allegro

Modules is probably a bit of a misnomer, as there aren't individual modules, but we can group then together to get a set of functions to create a game. Look at for a quick reference to several of them, and the allegro help file in the downloads.

The function groups can be broken down to

  • Video and graphic routines
  • Input routines
  • Sound and music routines

Which basically sums up what you need to do for a game.

What can you do with modules? Anything you want! You should always do some things to set allegro up, and close it down properly, but apart from that have a look through the examples for what's possible.

What you should do every time.

ret = allegro_init()                                             -- initialise allegro            
ret = install_keyboard()                                         -- to use the keyboard routines 
ret = install_timer()                                            -- to use the timer functions (unreliable at the moment) 
ret = install_mouse()                                            -- if you want to use the mouse 
ret = install_sound(DIGI_AUTODETECT, MIDI_NONE, "")              -- if you want to use allegro's sound functions 
set_color_depth(32)                                              -- optional - see below 
ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 200, 0, 0)      -- set a video mode 
-- each of these returns -1 if unsuccessful, so you could test for success at this stage 
-- note - you don't //have// to use set_color_depth(), but if you do, always use it before set_gfx_mode(). 
-- If you don't it will default to 8 bit color depth. Some monitors can't cope with some color depths. 
-- Valid color depths are 8, 15, 16, 24 or 32. 
-- some monitors / graphics cards can't cope with allegro's fullscreen graphics modes, so what I do is 
ret = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640,480, 0, 0) 
if ret = -1 then 
    -- switch to a safe mode instead 
    ret = set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) 
end if 

and at the end

allegro_exit()                                                   -- closes allegro cleanly 

The available graphics modes are

and the available resolutions are 320*240, 640*480, 1025*768 - this may seem restrictive for modern computers, but for what allegro does, it is more than adequate.

You do not need to initialise the joystick - we aren't using allegro's joystick functions, just include joy.ew, create a sequence, and use the global variables
XPOS = 1,
YPOS = 2,
ZPOS = 3,
RPOS = 4,
UPOS = 5,
VPOS = 6,
POV = 8
to reference it - see joytest for details.

If you want to read mp3, then you have to use fmod, include the fmod.ew wrapper - like allegro you need to initialise it - I will add another page for this.

Once you've done this, you can get on with playing samples, drawing lines and circles, loading sprites and bitmaps, and blitting them left right and centre.


Quick Links

User menu

Not signed in.

Misc Menu