Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » mac: allegro program does nothing

This thread is locked; no one can reply to it. rss feed Print
mac: allegro program does nothing
cutopia
Member #16,635
February 2017

I copied and pasted the following tutorial code and was able to compile it without any warnings/errors.
However, when I run it, it seems to go into a different video mode, but otherwise does absolutely nothing until I finally get bored and press escape which makes it all go away.
This is on a MacOS 10.12.2

I would expect this to make the screen red... but it's black.
I also tried 1,0,0 just in case it was expecting a 0-1 scale for the color.
But no... same result.

Please help. I feel very sad being stumped so badly before I've even begun.
Thanks

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, char **argv){

ALLEGRO_DISPLAY *display = NULL;

if (!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}

display = al_create_display(640, 480);
if (!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}

al_clear_to_color(al_map_rgb(255,0,0));

al_flip_display();

al_rest(10.0);

al_destroy_display(display);

return 0;
}

DragonDePlatino
Member #16,608
December 2016

Hmm...Your example is working for me. Maybe allegro isn't recognizing the window as the target bitmap? Try adding al_set_target_backbuffer(display) before al_clear_to_color(al_map_rgb(255,0,0)).

If that doesn't work, try tweaking some display options/flags before creating your display. You can bitwise-and together these flags before creating a display or set some of these options where each one is its own line of code. If none of these solutions work you'll have to wait for one of the devs to respond.

cutopia
Member #16,635
February 2017

Hmm I tried your suggestions and still no luck. Maybe I'm doing something fundamentally wrong at an even earlier stage. I'm building with gcc... and running the a.out from the command line. Is there anything inherently wrong with that?

Here is the compile command I'm using:

gcc allegromain.c -I /usr/local/include -lallegro -lallegro_main -L /usr/local/lib -lallegro_image -lallegro_primitives

some of those libs probably aren't needed... they were from other tutorials I was attempting before I realized that they were all silently failing to work as intended.

DragonDePlatino
Member #16,608
December 2016

I wouldn't recommend you compile via commands. It's already immensely difficult to link everything with a nice IDE so I can't imagine how hard it is with console. Maybe you could try the old Mac version of Code::Blocks? There's a nice tutorial on how to set up everything in that.

Felix-The-Ghost
Member #9,729
April 2008
avatar

I remember having difficulty with the Mac version of Code::Blocks, but there is a tutorial somewhere for setting it up with Xcode (as convoluted as the process was it works)

==========================
<--- The ghost with the most!
---------------------------
[Website] [Youtube]

SiegeLord
Member #7,827
October 2006
avatar

I'm curious that you say it does a mode switch, since the code you pasted should create a window.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

cutopia
Member #16,635
February 2017

So here's the code again with the modifications based on the first suggestions.
This code, when run, makes my whole screen go dark. After about 5 seconds the screen comes back a dark color with an extra large mouse pointer. It stays that way indefinitely. When I press escape, it exits and there is a message in the terminal:
2017-02-15 21:24:47.564 a.out[39301:4520130] void * _Nullable NSMapGet(NSMapTable * _Nonnull, const void * _Nullable): map table argument is NULL

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, char **argv){

ALLEGRO_DISPLAY *display = NULL;

if (!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
al_set_new_display_flags(ALLEGRO_WINDOWED);
display = al_create_display(320, 200);
if (!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
al_set_target_backbuffer(display);
al_clear_to_color(al_map_rgb(255,0,0));

al_flip_display();

al_rest(10.0);

al_destroy_display(display);

return 0;
}

Elias
Member #358
May 2000

How did you install Allegro? I just did this at work (on an OSX 10.12.2 with nothing installed on it):

brew install --HEAD allegro
cat > a.c (paste code from your post above)
gcc a.c -L/usr/local/lib -lallegro -lallegro_main
./a.out

It shows a tiny red window, both on the retina screen and an old external monitor.

Btw., thanks to whoever made it so extremely easy (less than 5 seconds!) to install Allegro in OSX nowadays - I remember times when it was much harder :)

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

cutopia
Member #16,635
February 2017

That list of steps allowed me to solve the issue...
But the exact step that solved the problem turned out to be horrifyingly simple:
Apparently there is another a.out somewhere on my system that was getting preferentially executed instead of the one in the current directory.

I can't believe it was that lame of a problem. :-[:-[:-[
But what a relief to finally be able to proceed with learning to use allegro.
Thanks so much

Go to: