Allegro does not perform anything graphic

Asked

Viewed 51 times

1

It simply does not appear anything graphic, the functional (close the window) works perfectly, but the graphic (background color and "ship") do not work.

#include <allegro5\allegro.h>
#include <allegro5\allegro_native_dialog.h>
#include <allegro5\allegro_primitives.h>
#include "objetos.h"

const int height = 800;
const int width = 600;

void InitNave(NaveEspacial &nave);
void DesenhaNave(NaveEspacial &nave);


int main(void)
{
        ALLEGRO_DISPLAY *display = NULL;
        ALLEGRO_EVENT_QUEUE *fila_eventos = NULL;

        bool end = false;

        NaveEspacial nave;

        if(!al_init())
        {
                al_show_native_message_box(NULL, "AVISO!", NULL, "FALHA AO CARREGAR ALLEGRO", NULL, NULL);
                return -1;
        }

        display = al_create_display(height, width);

        al_init_primitives_addon();

        fila_eventos = al_create_event_queue();

        al_register_event_source(fila_eventos, al_get_display_event_source(display));

        if(!display)
        {
                al_show_native_message_box(NULL, "AVISO!", NULL, "FALHA AO CARREGAR O DISPLAY", NULL, NULL);
                return -1;
        }

        InitNave(nave);

        while(!end)
        {
                ALLEGRO_EVENT ev;
                al_wait_for_event(fila_eventos, &ev);

                if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
                {
                        end = true;
                }

                DesenhaNave(nave);

                al_flip_display;
                al_clear_to_color(al_map_rgb(0, 0, 0));
        }

        al_destroy_display(display);
        al_destroy_event_queue(fila_eventos);

        return 0;
}

void InitNave(NaveEspacial &nave)
{
        nave.x = 20;
        nave.y = height / 2;
        nave.ID = JOGADOR;
        nave.vidas = 3;
        nave.velocidade = 7;
        nave.borda_x = 6;
        nave.borda_y = 7;
        nave.pontos = 0;
}
void DesenhaNave(NaveEspacial &nave)
{
        al_draw_filled_rectangle(nave.x, nave.y - 9, nave.x + 10, nave.y - 7, al_map_rgb(255, 0, 0));
        al_draw_filled_rectangle(nave.x, nave.y + 9, nave.x + 10, nave.y + 7, al_map_rgb(255, 0, 0));
        al_draw_filled_triangle(nave.x - 12, nave.y - 17, nave.x + 12, nave.y, nave.x - 12, nave.y + 17, al_map_rgb(0, 255, 0));
        al_draw_filled_rectangle(nave.x - 12, nave.y - 2, nave.x + 15 , nave.y + 2, al_map_rgb(0, 0, 255));
}
  • It seems to me that you reversed the width with the height. Your logic within the while You’re acting weird, because it seems to me that that means he won’t draw until he receives some event, including the closing event. In fact, what’s in the "objetos.h"?

1 answer

0


You have forgotten the parentheses in al_flip_display(). So the display will never be updated with each iteration (And you will never see the ship (Nothing)).

  • 1

    It worked, thank you

  • You’re welcome to :). Add me there later (My Facebook is in my profile here in the stack). I also develop with Allegro, and am creating a C++ engine for it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.