我有這樣的問題:我想顯示消息「你好!」在比賽開始之前,在Allegro屏幕的中心附近。不知道爲什麼在我編譯程序之後總是隻有全窗口的白色,而不是消息「你好!」。我不知道爲什麼它不顯示消息「你好!」 。但是,如果我刪除註釋行之間的代碼// *****程序顯示消息「你好!」好。有人能告訴我如何解決這個問題嗎?Allegro5顯示文本不起作用
#include<allegro5\allegro5.h>
#include<allegro5\allegro_native_dialog.h>
#include<allegro5\allegro_font.h>
#include<allegro5\allegro_ttf.h>
#include<allegro5\allegro_primitives.h>
#include<iostream>
using namespace std;
int main(){
int ScreenWidth = 800, ScreenHeight = 600;
if (!al_init())
{
al_show_native_message_box(NULL, NULL, NULL, "Could not initialize Allegro 5", NULL, NULL);
return -1;
}
al_set_new_display_flags(ALLEGRO_WINDOWED);
ALLEGRO_DISPLAY *display = al_create_display(ScreenWidth, ScreenHeight);//creating window with dimensions: 800:600 px
al_set_window_position(display, 200, 100);//place from left top positioning the frame of display
al_set_window_title(display, "Try to catch me!");
if (!display)//show this message if sth wrong with display
{
al_show_native_message_box(display, "Sample Title", "Display Settings", "Display window was not created succesfully", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
al_init_font_addon();//initialization font addon
al_init_ttf_addon();//initialization ttf(true type font) addon
//INTRO
ALLEGRO_FONT *fontOrbionBlack36 = al_load_font("fonts/Orbitron Black.ttf", 36, NULL);
al_draw_text(fontOrbionBlack36, al_map_rgb(44, 117, 255), ScreenWidth/2, ScreenHeight/2, ALLEGRO_ALIGN_CENTRE, "Hello!");
al_rest(5.0);
//********************************************************************************
al_init_primitives_addon();
al_install_keyboard();
ALLEGRO_COLOR electricBlue = al_map_rgb(44, 117, 255);
ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
al_register_event_source(event_queue, al_get_keyboard_event_source());
bool done = false;
int x = 10, y = 10;
int moveSpeed = 5;
while (!done)
{
ALLEGRO_EVENT events;
al_wait_for_event(event_queue, &events);
if (events.type = ALLEGRO_EVENT_KEY_DOWN)
{
switch (events.keyboard.keycode)
{
case ALLEGRO_KEY_DOWN:
y += moveSpeed;
break;
case ALLEGRO_KEY_UP:
y -= moveSpeed;
break;
case ALLEGRO_KEY_ESCAPE:
done = true;
break;
}
}
al_draw_rectangle(x, y, x + 20, y + 20, electricBlue, 2.0);
al_flip_display();
al_clear_to_color(al_map_rgb(0, 0, 0));
}
//*****************************************************************************************
al_flip_display();
al_rest(10.0);//rest is very simmilar to Sleep() it is waitg function, waiting 3s then close the allegro display
//al_destroy_font(fontOrbionBlack18);
al_destroy_font(fontOrbionBlack36);
al_destroy_display(display);//destroy the display at the end of the programm
return 0;
}