Simple background scrolling program.
It works almost fine on Ubuntu:
http://stackoverflow.com/questions/33064135/allegro-5-ubuntu-drawing-bitmap-from-system-memory-part-of-image-is-deformed
I am trying to make it work on Windows.
When I comment line al_draw_bitmap_region out game loop works. But with this function it freezes.
I am using windows binaries from here http://liballeg.org/download.html
I tried to link with allegro.lib and allegro.dll, allegro_image.lib and allegro_image.dll; and only with allegro_monolith.lib allegro_monolith.dll
Also I just noticed. There are many weird things about Visual Studio. And here is one. Usually unless you explicitly state that you are ok with fprintf Visual Studio doesn't allow it. It says use fprintf_s instead. This time I just used fprintf_s everywhere. But in quit(const char *) function I used just fprintf and it said nothing.
Before using binaries I compiled from source. Basic programs worked. But when I tried al_load_bitmap Visual Studio showed NULL on top of the call stack. It wasn't that the function returned NULL. The issue was that next function on the stack was NULL. al_load_bitmap called two more functions. As I remember they were find_bitmap_flags and find_handler.
While I desperately was trying to please visual studio when it hit me with "access violation ... trying to execute 00000000" I wrote this line
if (!(dm = al_get_display_mode(al_get_num_display_modes() - 1, &ldm)))
with two variables dm and ldm instead of one.
and then I accessed display width like dm->width. But al_get_display_mode does not return valid display mode, therefore dm->width contained rubbish. I changed code to have only global ALLEGRO_DISPLAY_MODE and now I don't assign returned value to it. Also I access width with dot: dm.width
But documentation states that on success function returns pointer to its parameter and NULL on failure... Now I understand. ldm was local variable, although dm was global ldm was deleted when init finished. Therefore dm was pointing on garbage.
... That's a shame. I made such a mess in a simple program. It's not even a game, just a little test. I still wonder why would compiled from source version of allegro try to execute NULL when calling al_load_bitmap; and why there is this little glitch on Ubuntu.
Works fine for me.
But one thing I can see you're forgetting is
Also here if you want it, it's a base you can use which I think is pretty neat;
Main function
initializeAllegro function
checkInput function
cleanUp function
But one thing I can see you're forgetting is al_clear_to_color(al_map_rgb(0,0,0));
Well, when drawing something to full screen size, al_clear_to_color() isn't necessarily needed. Since you're redrawing each pixel every frame, anyways, a clear is optional. In fact, you're saving a small amout of performance by skipping the clear. It's probably a neglectible amount, but I'm just saying.
ALLEGRO_DISPLAY_MODE ldm;
This is a local variable which gets destroyed when the init function returns. So any behavior after that is undefined, program crashes or other weird things are expected. This is the joy of C++, always be careful about memory allocation and lifetime, for every single variable you use
Anyway, it could explain both the Linux and Windows issues.
Well, when drawing something to full screen size, al_clear_to_color() isn't necessarily needed. Since you're redrawing each pixel every frame, anyways, a clear is optional. In fact, you're saving a small amout of performance by skipping the clear. It's probably a neglectible amount, but I'm just saying.
Oh, well that is good to know!