Wiki Diff allegromodules, revision #9 to tip

===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 [[http://www.connellybarnes.com/documents/quick_reference.html]] 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.
What you should do everytime.

<eucode>
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
ret = allegro_init() --initialise allegro
ret = install_keyboard() --if you want to use the keyboard routines
--to read the keyboard
ret = install_timer() --if you want to use the timer functions, but they are a
--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
--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.
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
--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
--switch to a safe mode instead
ret = set_gfx_mode(GFX_SAFE, 640, 480, 0, 0)
end if

</eucode>

and at the end
<eucode>
allegro_exit() -- closes allegro cleanly
allegro_exit() --will close allegro cleanly
</eucode>

The available graphics modes are\\
GFX_TEXT \\
GFX_AUTODETECT \\
GFX_AUTODETECT_FULLSCREEN\\
GFX_AUTODETECT_WINDOWED \\
GFX_SAFE \\
GFX_DIRECTX_WIN \\

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\\
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,\\
BUTTONS = 7,\\
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.

*[[http://openeuphoria.org/wiki/view/allegro.wc|Allegro home]]


Search



Quick Links

User menu

Not signed in.

Misc Menu