|
Getting Started |
Neil Black
Member #7,867
October 2006
|
I'm working my way through the Allegro tutorials and every time I try to call al_draw_bitmap() the program crashes. I'm not sure why. After some further testing I've found that drawing primitives also crashes the program. I've created a bitmap and set it as the target bitmap, I'm not sure what else needs to be done before I can draw to it.
|
Ariesnl
Member #2,902
November 2002
|
post your code... Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
Arthur Kalliokoski
Second in Command
February 2005
|
I betcha a weeks supply of Pepsi(TM)(Nectar of the Godz)that you forgot to do al_init_image_addon(void). They all watch too much MSNBC... they get ideas. |
Chris Katko
Member #1,881
January 2002
|
I'm really starting to wonder if Allegro 5+/"6" should have a different API mentality. Ever since I learned about "the common case should be default/easy" for data-oriented design, it really makes sense. In my opinion, everything in Allegro should be defaulted unless you opt out. allegro_init() should give you every common case "for free". (Or at least have one new function that does that.) Graphics (at default desktop depth), primitives, jpeg/png/whatever input, sound, a single event queue with the mouse/keyboard/joysticks attached, and even a FPS timer occurring once a second with a variable you can send to print (or even have one that hijacks onto al_flip_display and overlays it automatically in the corner). And, when you want something different than the default, you override those defaults. Default depth is desktop depth, until you manually ask for it. etc. This would likely be easier in C++ with default arguments, but perhaps with some kind of C method/functioning chaining it could be done. The people who know what they're doing, are used to writing lines of code for "on the metal" features. The people who don't, should already be in an environment that lets them play around instead of a crash. Maybe the color depth "is wrong", and they can google it/ask about it. But there will still be pixels on the screen which will help them diagnose the problem. Also, one great thing about D (not suggesting we port it for everyone) is the built-in asserts that allow you to pack a message in. In debug mode, asserts catch a file missing, or a addon not initialized, and halts the program. But you also get a custom message with the assert. "You failed to initialize the addon!" Instead of just a line number in a piece of code. Maybe C supports that (with macros?), but IIRC it doesn't. -----sig: |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Eagle 5 does all this for you. It's super simple, and super easy. Here's the code it takes to display Hello World : 1#include "Eagle/backends/Allegro5Backend.hpp"
2
3int hello_main(int argc , char** argv) {
4
5 (void)argc;
6 (void)argv;
7
8 Allegro5System* a5sys = GetAllegro5System();
9
10 a5sys->Initialize(EAGLE_FULL_SETUP);
11
12 EagleGraphicsContext* win = a5sys->GetWindowManager()->CreateWindow("hello_main::win" , 800 , 600 , EAGLE_OPENGL | EAGLE_WINDOWED);
13
14 win->Clear(EagleColor(0,0,0));
15
16 win->DrawTextString(win->DefaultFont() , "Hello World" , win->Width()/2 , win->Height()/2 , EagleColor(255,255,255) , HALIGN_CENTER , VALIGN_CENTER);
17
18 win->FlipDisplay();
19
20 a5sys->Rest(3);
21
22 Eagle::EagleLibrary::ShutdownEagle();
23
24 return 0;
25}
Of course, this is overkill for hello world, but the thing is, it sets up and installs and registers every single input and addon there is for you without having to do it over and over again. There is a default system timer, queue, input handler, and window manager that does pretty much everything for you. 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 |
beoran
Member #12,636
March 2011
|
I think an official add-on with such an "easy" API would be a nice addition to Allegro5. Even with just C, there is quite a bit we could do. |
Neil Black
Member #7,867
October 2006
|
Edgar that Eagle 5 thing looks interesting. Where can I read up on it? Here's my code, which I'm modifying from a basic A5 sample I found somewhere. I did in fact do al_init_image_addon() on line 22. Or rather, the sample did. 1#include <allegro5/allegro.h>
2#include <allegro5/allegro_native_dialog.h>
3#include <allegro5/allegro_image.h>
4#include <allegro5/allegro_primitives.h>
5
6int main()
7{
8 ALLEGRO_DISPLAY *display;
9
10 if(!al_init())
11 {
12 al_show_native_message_box(NULL,NULL,NULL,"Could not initialize Allegro 5", NULL, 0);
13 }
14
15 display = al_create_display(800,600);
16
17 if(!display)
18 {
19 al_show_native_message_box(display, "Sample Title", "Display Settings", "Display Window Was Not Created", NULL, 0);
20 }
21
22 if(!al_init_image_addon())
23 {
24 al_show_native_message_box(NULL,NULL,NULL,"Could not initialize Image Addon", NULL, 0);
25 }
26
27 al_install_keyboard();
28
29 ALLEGRO_BITMAP* Square = NULL;
30 ALLEGRO_BITMAP* Screen = NULL;
31
32 ALLEGRO_COLOR Black = al_map_rgb(0,0,0);
33
34 Screen = al_create_bitmap(800,600);
35 Square = al_load_bitmap("Square.bmp");
36
37 al_set_target_bitmap(Screen);
38
39 //al_clear_to_color(Black);
40
41 ALLEGRO_EVENT_QUEUE* Queue = al_create_event_queue();
42 ALLEGRO_EVENT_SOURCE* KeySource = al_get_keyboard_event_source();
43 al_register_event_source(Queue, KeySource);
44
45 al_wait_for_event(Queue, NULL);
46
47 al_show_native_message_box(NULL,NULL,NULL,"Program Complete", NULL, 0);
48
49 //al_draw_rectangle(20, 20, 100, 100, al_map_rgb(255,255,255), 10);
50
51 //al_draw_bitmap(Square, 20, 20, ALLEGRO_FLIP_HORIZONTAL);
52
53
54
55 al_destroy_display(display);
56
57 return 0;
58}
|
Chris Katko
Member #1,881
January 2002
|
You don't check if Square is null. It you're on Linux, filenames are case sensitive too so make sure the name AND the extension match both in letters and case. And if you're on windows, sometimes the "Base" directory, isn't the one with your files. It could be my_project/bin/ or some other directory. It's called the "Working directory" in Windows. -----sig: |
Neil Black
Member #7,867
October 2006
|
The problem persists even if I comment out all the references to the Square variable.
|
Chris Katko
Member #1,881
January 2002
|
Are you sure running with the same version of the library you linked with? I had problems where they didn't match before and it exploded. Try compiling monolithic so there's no DLL/SO. -----sig: |
Elias
Member #358
May 2000
|
al_init_primitives_addon is required for al_draw_rectangle -- |
Neil Black
Member #7,867
October 2006
|
Success! I have it drawing a thing.
|
Chris Katko
Member #1,881
January 2002
|
Elias said: al_init_primitives_addon is required for al_draw_rectangle I thought we covered that already. -----sig: |
bamccaig
Member #7,536
July 2006
|
Also, free software debugger 101: 1. Find gdb on your system. Or if it didn't come with your toolchain you can find a download for it. You should get a function name in C, and a line number too if you have debugging symbols built in. C++ might be a mess unless you have debugging symbols due to name mangling though. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Neil Black
Member #7,867
October 2006
|
We did cover that Chris. But I tried adding it without the if statement and it worked.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
You can find Eagle here : http://members.allegro.cc/EdgarReynaldo/Eagle.html Some of the GUI functionality is still undone, but you can do many things with Eagle. Graphics, input, and event handling are all much simplified. Right now it takes CodeBlocks to build, with MinGW on Windows, gcc on Linux, and I haven't had the opportunity to try and build Eagle on OSX. I wanted to release binaries but I'm still working out a few bugs in the multi threaded aspect of Eagle, trying to make the essentials thread safe. It works fine for single window (thread) apps though. 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 |
|