-1

I am developping a game with allegro library. I wrote a starter C code then I compile the program on Ubuntu Terminal.After that When I open the output program,the program open but not closed.Cancel Button(X) is not working.

Here is my starter code:

#include <allegro.h>

void Baslat();
void Bitir();

int main(){
        Baslat();
        while(!key[KEY_ESC]){

        }
        Bitir();
        return 0;
}

END_OF_MAIN()

void Baslat(){
        int depth,res;
        allegro_init();
        depth = desktop_color_depth();
        if(depth == 0) depth=32;
        set_color_depth(depth);
        res=set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640,480,0,0);
        if(res!=0){
                allegro_message("%s\n", allegro_error);                  exit(-1);
        }
        install_timer();
        install_keyboard();
        install_mouse();

}


void Bitir(){
  clear_keybuf();

}
Passer By
  • 19,325
  • 6
  • 49
  • 96
  • 1
    Tried debugging? Run your app in the debugger and hit Ctrl+C when it hangs on exit. – arrowd Jul 29 '17 at 11:44
  • I answered for `allegro5` based on the tag, but it looks like you are actually using `allegro4`. Which version of allegro are you interested in? – rcorre Jul 29 '17 at 16:34

1 Answers1

0

To respond to a user pressing the X button in allegro5, you must catch ALLEGRO_EVENT_DISPLAY_CLOSE. This tutorial provides an example of responding to that event.

rcorre
  • 6,477
  • 3
  • 28
  • 33
  • Yes I use allegro4 but I can't understand your answer. Which allegro release should I use? Is there a way for solving my problem at allegro4? – Tarkan Genç Jul 29 '17 at 19:41
  • Which release to use is a personal decision, but I would use the most recent release unless you have a compelling reason to use an old version. I don't use `allegro4` so I don't know how to solve your problem with it. If you are using `allegro5`, the tutorial I linked gives a code sample and explanation for exactly what you want. – rcorre Jul 31 '17 at 17:25