Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_draw_filled_rect not drawing

Credits go to Elias for helping out!
This thread is locked; no one can reply to it. rss feed Print
al_draw_filled_rect not drawing
Magemaster
Member #10,856
April 2009

Line 125 below is causing me some issues. The rectangle is not being drawn and I'm not sure why. No errors are thrown. Any help would be appreciated.

#SelectExpand
1 2#include <allegro5/allegro.h> 3#include <stdio.h> 4 5#define WIDTH 640 6#define HEIGHT 480 7#define SIZE 10.0 8 9//Environmental Globals 10ALLEGRO_DISPLAY *display = NULL; 11ALLEGRO_EVENT_QUEUE *events = NULL; 12ALLEGRO_TIMER *timer; 13 14//Graphics Globals 15ALLEGRO_COLOR red; // = al_map_rgb(184,22,22); 16ALLEGRO_COLOR blue; // = al_map_rgb(22,22,184); 17ALLEGRO_COLOR green; // = al_map_rgb(22,184,22); 18 19void init_allegro() 20{ 21 //Colors 22 red=al_map_rgb(184,22,22); 23 blue=al_map_rgb(22,22,184); 24 green=al_map_rgb(22,184,22); 25 26 //Initialization 27 if(!al_init()) 28 { 29 fprintf(stderr,"Failed to init Allegro!\n"); 30 exit(0); 31 } 32 33 //Keyboard 34 if(!al_install_keyboard()) 35 { 36 fprintf(stderr,"Could not connect keyboard!\n"); 37 exit(0); 38 } 39 40 //create the display 41 display = al_create_display(WIDTH,HEIGHT); 42 if(!display) 43 { 44 fprintf(stderr,"Could not create display!\n"); 45 exit(0); 46 } 47 48 //initialize the event queue 49 events=al_create_event_queue(); 50 if(!events) 51 { 52 fprintf(stderr,"Could not create events\n"); 53 exit(0); 54 } 55 56 //Set the timer 57 timer = al_create_timer(1.0/60); 58 if(!timer) 59 { 60 fprintf(stderr,"Could not create timer\n"); 61 exit(0); 62 } 63 64 //Initialize the primitives addon 65 if(!al_init_primitives_addon()) 66 { 67 fprintf(stderr,"Primitives failed to load\n"); 68 } 69 70 //Register display, timer, keyboard to events 71 al_register_event_source(events,al_get_display_event_source(display)); 72 al_register_event_source(events,al_get_keyboard_event_source()); 73 al_register_event_source(events,al_get_timer_event_source(timer)); 74 75 //Initially Clear the Display 76 al_clear_to_color(al_map_rgb(0,0,0)); 77 al_flip_display(); 78 79 80 //Start the timer 81 al_start_timer(timer); 82} 83 84void exit_allegro() 85{ 86 al_destroy_display(display); 87 al_destroy_event_queue(events); 88 al_destroy_timer(timer); 89 al_shutdown_primitives_addon(); 90} 91 92void main() 93{ 94 //The event holder 95 ALLEGRO_EVENT event; 96 //The done 97 int done=0; 98 int redraw=1; 99 100 //init allegro 101 init_allegro(); 102 103 //The While Loop 104 while(!done) 105 { 106 al_wait_for_event(events,&event); 107 108 //Fires 60 times a second 109 if(event.type == ALLEGRO_EVENT_TIMER) 110 { 111 redraw=1; 112 } 113 else if(event.type == ALLEGRO_EVENT_KEY_DOWN) 114 { 115 if(event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) 116 { 117 done = 1; 118 } 119 } 120 //Start drawing 121 if(redraw && al_is_event_queue_empty(events)) 122 { 123 redraw=0; 124 al_clear_to_color(al_map_rgb(60,100,10)); 125 al_draw_filled_rectangle(10.0,20.0,30.0,60.0,red); 126 //printf("Rect Drawn!\n"); 127 al_flip_display(); 128 } 129 } 130 //Shutdown 131 exit_allegro(); 132}

Elias
Member #358
May 2000

al_map_rgb (or any other Allegro functions) cannot work before al_init was called.

--
"Either help out or stop whining" - Evert

Magemaster
Member #10,856
April 2009

Ah, thanks Elias.

I also wasn't including allegro5/allegro_primitives.h

Go to: