ゲームエンジン Allegro バージョン 5.0 のインストールとサンプルプログラム
Allegro バージョン 5.0 の概要
- C/C++ 言語を使用
- 種々の言語から使える: https://liballeg.org/bindings.html
- Allegro バージョン 5.0 系列は, Unix/Linux, Windows (MSVC, MinGW), MacOS X, iPhone で動く.
 
ダウンロードとインストール
- 前準備として前提ソフトウェアをインストール
◆ Ubuntu での操作手順例
sudo apt -y update sudo apt -y install flac libflac++-dev libflac-dev sudo apt -y install libdump sudo apt -y install libvorbis-dev sudo apt -y install libogg-dev sudo apt -y install libxxf86dga-dev oss4-dev x11proto-xf86dga-dev
- Allegro の Web ページを開く
- 「Latest version」をクリック
- ダウンロード
- 解凍
cd /tmp tar -xvzof allegro-5.0.8.tar.gz cd allegro-5.0.8
- ccmake でオプションを確認
次の手順でオプションを確認
- 「ccmake . 」を実行
- 次の画面で c キーを押す.警告は無視
- 次に e キーを押すと、オプションに関する画面が現れる(下記)
- 終了したい時は q キー
- 「ccmake . 」を実行
- ビルド
cmake . make
※ cmake のあとには半角スペースと、半角のピリオド
- make の結果の確認
- インストール
sudo make install
- インストールの結果の確認
サンプルプログラム
ftp://ftp.pucmg.br/Computacao/Mais_Utilizados/Programacao_Software/C_-_C++/CodeBlocks/allegro/allegro/examples/ex_ttf.c
ごく簡単なサンプル (textout)
#define ALLEGRO_STATICLINK
#include<stdio.h>
#include<allegro.h>
#include<allegro_ttf.h>
#include<allegro_primitives.h>
static ALLEGRO_FONT *font24;
int doit()
{
al_draw_textf(font24, al_map_rgb(128, 100, 20), 50, 50, ALLEGRO_ALIGN_CENTRE, "hoge");
return 0;
}
int main()
{
/* you should always do this at the start of Allegro programs */
if(!al_init()) {
return -1;
}
/* set up the keyboard handler */
al_install_keyboard();
/* set up the mouse handler */
al_install_mouse();
/* set up fonts */
al_init_font_addon();
al_init_ttf_addon();
/* set a graphics mode sized 800x640 */
ALLEGRO_DISPLAY *display = NULL;
display = al_create_display(800, 640);
if(!display) {
return -1;
}
/* load font */
font24 = al_load_font("/usr/share/fonts/truetype/freefont/FreeSans.ttf",24,0);
al_clear_to_color(al_map_rgb(0,0,0)); // clears the screen to the selected color
doit();
ALLEGRO_EVENT_QUEUE *EventQueue;
ALLEGRO_EVENT Event;
bool Exit = false;
EventQueue = al_create_event_queue();
al_register_event_source(EventQueue, al_get_display_event_source(display));
al_register_event_source(EventQueue, al_get_keyboard_event_source());
al_register_event_source(EventQueue, al_get_mouse_event_source());
while(Exit == false) {
al_flip_display();
al_wait_for_event(EventQueue, &Event);
if(Event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
Exit = true;
}
}
al_destroy_display(display);
return 0;
}
次の手順でコンパイル
g++ hoge.cc -I/usr/local/include/allegro5 -L/usr/local/lib -lallegro -lallegro_font -lallegro_ttf -lm
次の手順で実行
./a.out
