The above is a problem I am having. I am using Visual Studio 2010, in C++, with the Allegro library for game development. I'm having an issue where my test program is always all-white, until I hit a button, in some cases. I don't really understand how to fix this, nor what's wrong. I know for a fact that it's not related to the code being used, as this never used to happen with some example code from a website; now it seems to happen all the time with this project. If someone could point me to a possible error fix, it would be much appreciated.
Below is the code:
#include <allegro5\allegro.h>
#include <allegro5\allegro_primitives.h> //Our primitive header file
int main(void)
{
int width = 640;
int height = 480;
bool done = false;
int pos_x = width / 2;
int pos_y = height / 2;
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
if(!al_init()) //initialize Allegro
return -1;
display = al_create_display(width, height); //create our display object
if(!display) //test display object
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:
pos_y -= 10;
break;
case ALLEGRO_KEY_DOWN:
pos_y += 10;
break;
case ALLEGRO_KEY_RIGHT:
pos_x += 10;
break;
case ALLEGRO_KEY_LEFT:
pos_x -= 10;
break;
}
}
else if(ev.type == ALLEGRO_EVENT_KEY_UP)
{
if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
done = true;
}
al_draw_filled_rectangle(pos_x, pos_y, pos_x + 30, pos_y + 30, al_map_rgb(255,0,255));
al_flip_display();
al_clear_to_color(al_map_rgb(0,0,0));
}
al_destroy_event_queue(event_queue);
al_destroy_display(display); //destroy our display object
return 0;
}
As I said, it is example code from an online tutorial.