![]() |
|
al_map_rgb() only works after al_init() contrary to the documentation |
BitCruncher
Member #11,279
August 2009
![]() |
Am I right? I'm getting a black screen. Ubuntu 20.04.5 1#include <iostream>
2#include <allegro5/allegro.h>
3
4
5
6const int WINDOW_RES_X = 1280;
7const int WINDOW_RES_Y = 720;
8
9
10
11void initialize_keyboard()
12{
13 if(!al_is_keyboard_installed()) {
14 std::cout << "Initializing keyboard...";
15 if(!al_install_keyboard()) {
16 std::cout << "\nCould not initialize keyboard...aborting.\n";
17 abort();
18 }
19 else {
20 std::cout << "done.\n";
21 }
22 }
23}
24
25
26
27int main()
28{
29 ALLEGRO_COLOR COLOR_BLUE = al_map_rgb(0, 0, 255); // Does not work here
30 al_init();
31 ALLEGRO_DISPLAY *window = al_create_display(WINDOW_RES_X, WINDOW_RES_Y);
32 initialize_keyboard();
33 ALLEGRO_EVENT_SOURCE *keyboard_event_source = al_get_keyboard_event_source();
34 ALLEGRO_EVENT_QUEUE *keypress_queue = al_create_event_queue();
35 al_register_event_source(keypress_queue, keyboard_event_source);
36
37 al_set_target_bitmap(al_get_backbuffer(window));
38 al_clear_to_color(COLOR_BLUE);
39 al_flip_display();
40
41 // Wait for any keypress
42 bool exit = false;
43 while(!exit) {
44 if(!al_event_queue_is_empty(keypress_queue)) {
45 exit = true;
46 }
47 }
48
49 // Quit
50 al_unregister_event_source(keypress_queue, keyboard_event_source);
51 al_destroy_event_queue(keypress_queue);
52 al_uninstall_keyboard();
53 al_destroy_display(window);
54 al_uninstall_system();
55
56 return 0;
57}
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
I think the behavior was changed in a recent version of allegro. I could be wrong. But, most things won't work until you call al_init anyway. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
amarillion
Member #940
January 2001
![]() |
Indeed this was changed only recently. What is your allegro version? -- |
BitCruncher
Member #11,279
August 2009
![]() |
According to my package manager, looks like 5.2.6.0-1.
|
amarillion
Member #940
January 2001
![]() |
The latest version is 5.2.8.0. Your version is about 2 years old. I couldn't find back when this was introduced exactly, but it's quite possible that your version is too old. -- |
Mark Oates
Member #1,146
March 2001
![]() |
Could be your version. I found this commit from about ~1 year ago: Quote: "Allow calling al_map_* color functions before Allegro is initialized." https://github.com/liballeg/allegro5/commit/3e412a09eb060033b7c8bcf17a55095eeec07439 -- |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Elementary, my dear Watson... {"name":"watson1.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/a\/4ad3c43c040f3f1e781f3bdf80a91bdc.png","w":850,"h":784,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/a\/4ad3c43c040f3f1e781f3bdf80a91bdc"} My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
BitCruncher
Member #11,279
August 2009
![]() |
The only reason I came across this was I had moved some code from my Windows installation (with MSVC) over to Linux to rebuild, and all of a sudden the code stopped working right. Update: So I'm on my Windows installation now and checked the Allegro NuGet package, and the version on here is 5.2.7. The version on my Linux is indeed too old. It's strange since I did update my apt package repository beforehand. I wonder why it fetched a super old version?
|
|