Jump to content
  • Advertisement
Sign in to follow this  
Robbie Woods

Allegro Events - Nothing happening

This topic is 2365 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I'm new to allegro and I'm learning about event queues and stuff like that. My program compiles and runs but the event queue error pops up and I don't know why. Could you look through my code and tell me where I've gone wrong? Thanks



#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5\allegro_primitives.h>
int main(void)
{
int height = 480, width = 640;
bool done = false;
int posX = width / 2, posY = height / 2;

if (!al_init())
{
al_show_native_message_box(NULL,"Error", "Error", "Failed to initialise the Allegro library!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}

ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
if (!event_queue)
{
al_show_native_message_box(NULL, "Error", "Error", "Failed to create event queue!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
display = al_create_display(width, height);

if (!display)
{
al_show_native_message_box(display, "Error", "Error", "Failed to create display!", "Alright", ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
al_init_primitives_addon();
al_install_keyboard();
event_queue = al_create_event_queue();
al_register_event_source(event_queue, al_get_keyboard_event_source());
while(!done)
{
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);
if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
{
switch(ev.keyboard.keycode)
{
case ALLEGRO_KEY_UP:
posY -= 10;
break;
case ALLEGRO_KEY_DOWN:
posY += 10;
break;
case ALLEGRO_KEY_LEFT:
posX -= 10;
break;
case ALLEGRO_KEY_RIGHT:
posX += 10;
break;
}
}
al_draw_filled_rectangle(posX, posY, posX = 30, posY + 30, al_map_rgb(255, 0, 255));
al_flip_display();
al_clear_to_color(al_map_rgb(0, 0, 0));
}

al_destroy_display(display);
return 0;
}
Edited by robbiewoods05

Share this post


Link to post
Share on other sites
Advertisement
The display is blank because al_wait_for_event waits for an event if the event queue is emtpy. In other words, it would appear to "work" if you smashed your keyboard. You should poll the event queue and process events if there are any, then render. It looks like al_get_next_event is what you're looking for.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!