Hi, I am new to "Allegro", I have the following code to display some text in the allegro window, although the program does not show errors, the text is not displayed in the window.
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>
int main() {
// Inicialización de Allegro
if (!al_init()) {
fprintf(stderr, "Failed to initialize Allegro.\n");
return -1;
}
// Inicialización del addon de fuentes
if (!al_init_font_addon()) {
fprintf(stderr, "Failed to initialize font addon.\n");
return -1;
}
// Inicialización del addon de imágenes (necesario para algunas fuentes)
if (!al_init_image_addon()) {
fprintf(stderr, "Failed to initialize image addon.\n");
return -1;
}
// Crear una ventana
ALLEGRO_DISPLAY *display = al_create_display(800, 600);
if (!display) {
fprintf(stderr, "Failed to create display.\n");
return -1;
}
// Cargar una fuente
ALLEGRO_FONT *font = al_load_font("arial.ttf", 36, 0); // Asegúrate de tener arial.ttf en tu directorio
if (!font) {
fprintf(stderr, "Failed to load font.\n");
al_destroy_display(display);
return -1;
}
// Limpiar la pantalla con un color blanco
al_clear_to_color(al_map_rgb(255, 255, 255));
// Configurar el color del texto
ALLEGRO_COLOR text_color = al_map_rgb(0, 0, 0); // Color negro
// Dibujar el texto en la pantalla
al_draw_text(font, text_color, 400, 300, ALLEGRO_ALIGN_CENTRE, "¡Hola, Allegro!");
// Mostrar el contenido del buffer
al_flip_display();
// Esperar 5 segundos
al_rest(5.0);
// Liberar recursos
al_destroy_font(font);
al_destroy_display(display);
return 0;
}
I appreciate your help.
Thank you.
How you know it doesn't show errors, are you running it on the command line?
You can put your code between <code> </code> tags to give it better formatting here.
Miloarias,
I got the code running and found one issue really. You initialize font but not ttf. I added it and also added cstdio header. Worked fine. I had to use a font I had on my computer, PressStart2P.tff. Just change back to arial.ttf
Congratulations, AceBlkwell, you've earned your first kill! Consider that bug squashed!
Thanks Edgar. You are too kind. I guess even a blind squirrel can find a nut once in a while .
Or maybe it's the Allegro company I keep that is starting to wear off on me.
In any case thanks again.