Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Allegro Events - Nothing happening


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Shenaynay   Members   -  Reputation: 134

Like
0Likes
Like

Posted 02 May 2012 - 11:24 AM

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, 02 May 2012 - 11:32 AM.


Ad:

#2 fastcall22   Members   -  Reputation: 1869

Like
0Likes
Like

Posted 02 May 2012 - 11:26 AM

ALLEGRO_EVENT_QUEUE *event_queue = NULL;
if (!event_queue)

You're not creating the event_queue?

#3 Shenaynay   Members   -  Reputation: 134

Like
0Likes
Like

Posted 02 May 2012 - 12:00 PM

Yeah, that's true. Let me try re ordering it.

#4 Shenaynay   Members   -  Reputation: 134

Like
0Likes
Like

Posted 02 May 2012 - 12:08 PM

Re ordered it and nothing happens, just a black allegro window.

#5 fastcall22   Members   -  Reputation: 1869

Like
0Likes
Like

Posted 02 May 2012 - 12:22 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS