Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Upgrading from Allegro 4.x to Allegro 5.x

This thread is locked; no one can reply to it. rss feed Print
Upgrading from Allegro 4.x to Allegro 5.x
TeaRDoWN
Member #8,518
April 2007
avatar

I've decided that it's time to stop using Allegro 4(.2x) and upgrade to Allegro 5(.0.4). I've checked the examples and demos and everything seems pretty neat, however there are a few questions now when it comes to code upgrade:

1. Playing midi-files?
I don't see a midi-support in A5, no similar function to A4's load_midi(). Is midi no longer supported default? If so, is there a simple library to add to get midi-support?

2. Playing ogg-files?
Is there a built in ogg support in A5? In my A4 projects I used "logg" (or whatever it is called) but it doesn't seem to compile very well in A5.

3. al_flip_display()
Does this function replace blit(buffer, screen, 0,0, 0,0, w,h)?

4. voice_set_priority()
In A4 I used voice_set_priority() to set priority on samples when some samples were not to be stopped when too many samples were played at once. I don't see a similar function in A5, maybe there isn't since there isn't a problem of playing too many samples at once?

5. Sprite fonts
In A4 it was possible to load a font with multicolored characters, like a sprite font (don't know the correct naming of it). Is this still supported by A5? Haven't got as far as the fonts but something I was wondering about.

6. Reading mouse buttons and coordinates in A5
Is this a bad sollution to use as a global function for fetching wether a specific mouse button is pressed or not?

bool TD_mouseB(int button)
{
  ALLEGRO_MOUSE_STATE mouse_state;
  al_get_mouse_state(mouse_state);
  return al_mouse_button_down(mouse_state, button);
}

The mouse_state struct is local within the function and each time you want to check the mouse button you do a al_get_mouse_state() call.

7. key[KEY_ENTER] replaced by pressed_keys[ALLEGRO_KEY_ENTER]?
I've tried to replace all my old key[KEY_<id>] with pressed_keys[ALLEGRO_KEY_<id>] but I get build errors on all pressed_keys. I read the Allegro manual and as far as I can see this is how it is supposed to be? Or?

That's all...for now. I'll add more questions as I go on updating my finished A4 project. Someone told me to not upgrade a project but when starting on a new one do the transition from A4 to A5. Starting to see why but I guess this is a good way in learning the new names and parameters of the used functions. :)

Evert
Member #794
November 2000
avatar

TeaRDoWN said:

1. Playing midi-files?
I don't see a midi-support in A5, no similar function to A4's load_midi(). Is midi no longer supported default? If so, is there a simple library to add to get midi-support?

No midi support. It could conceivably be added (as an addon) very easily if someone is willing to put in the work.

Quote:

2. Playing ogg-files?
Is there a built in ogg support in A5? In my A4 projects I used "logg" (or whatever it is called) but it doesn't seem to compile very well in A5.

Yes, A5 comes with ogg support (but it needs to find the required support libraries at compile time; shouldn't be a problem if you use precompiled binaries).

Quote:

3. al_flip_display()
Does this function replace blit(buffer, screen, 0,0, 0,0, w,h)?

In a sense. You do all your drawing operations to the screen, which is double buffered by default.

Quote:

5. Sprite fonts
In A4 it was possible to load a font with multicolored characters, like a sprite font (don't know the correct naming of it). Is this still supported by A5? Haven't got as far as the fonts but something I was wondering about.

Yes. In fact, it internally uses pretty much the same code as A4 did.

Elias
Member #358
May 2000

1. MIDI is not supported. When I ported things myself I just rendered the .mid files as .ogg.

2. It's built-in, yes. (In the official windows binaries - otherwise you need the right dependencies of course.)

3. Basically. You don't have a buffer or screen any longer - you just create a display (which has an OpenGL context or the DirectX equivalent) and al_flip_display simply translates to the OpenGL/DirectX command to render the frame.

4. The problem is the same as in A4 and it's just not supported in A5. However instead of using the "simple" API with al_play_sample and al_reserve_samples you can use the lower level al_play_sample_instance and manage priority yourself (works like A4 voices). I don't know why priorities were left out.

5. Yes, al_load_font will happily load any colored bitmap fonts.

[EDIT: I'm too slow... but then I also had to research question 4 :P]

--
"Either help out or stop whining" - Evert

TeaRDoWN
Member #8,518
April 2007
avatar

1. If anyone has a midi-sollution for A5 (usable with VS 2010 v9.x) I would be super happy if I could get my hands on it too. :)

Added two new questions (#6 and #7) in first post.

Regarding #4 I guess I just have to code my own priority system. I so need it since player's samples should always be played and not interupted by 100s of enemies trying to play samples too. :)

Evert
Member #794
November 2000
avatar

TeaRDoWN said:

Added two new questions (#6 and #7) in first post.

I'd not bother with the state-based API; just set up an event queue and look for mouse/keyboard events.

Elias said:

[EDIT: I'm too slow... but then I also had to research question 4 :P]

Indeed, I had no idea, so decided to leave it blank. :P

LordHolNapul
Member #3,619
June 2003
avatar

about midi support....
"when the progress is not a progress... "

::);D

AMCerasoli
Member #11,955
May 2010
avatar

"when the progress is not a progress... "

If currently (2011) I run a game and start playing a MIDI song, I would immediately delete the game, blow out my computer, burn down my house, and move of country...

TeaRDoWN
Member #8,518
April 2007
avatar

Anyone got an answer/sollution on #7? Would be handy right now since I have about 200-300 build errors. :P

Regarding Midi-support or not, true in a new game. But when making a remake of a 90s game it bring back the right feeling. But I'll convert my midis to another format if it is possible.

raynebc
Member #11,908
May 2010

If currently (2011) I run a game and start playing a MIDI song, I would immediately delete the game, blow out my computer, burn down my house, and move of country...

There are instances where the MIDI is used to track data and not music itself, such as with rhythm gaming. I work on one such project where we'll either have to port the MIDI load function or write our own code to replace it.

AMCerasoli
Member #11,955
May 2010
avatar

That's is because Allegro 5 doesn't use an array of flags anymore, but just a simple enum.

I think you need to create it now, as the manual says:

Quote:

The constant ALLEGRO_KEY_MAX is always one higher than the highest key code. So if you want to use the key code as array index you can do something like this:

bool pressed_keys[ALLEGRO_KEY_MAX];
...
pressed_keys[key_code] = true;

But a better way would be to use the al_key_down() function.

ALLEGRO_KEYBOARD_STATE key;

while(1){
   al_get_keyboard_state(&key);
   if (al_key_down(&key, ALLEGRO_KEY_LEFT))
      // Do something  
}

But events are better.

raynebc said:

There are instances where the MIDI is used to track data and not music itself, such as with rhythm gaming. I work on one such project where we'll either have to port the MIDI load function or write our own code to replace it.

In such case it's acceptable, "tell me when to play the instruments, but please don't use yours" ;D.

TeaRDoWN
Member #8,518
April 2007
avatar

Ah, thought the bool array existed but as usual I read too quickly. :)

Go to: