1
\$\begingroup\$

I'm very interested in game programming and I'm taking my first steps alone. So I installed allegro. Although Dev-C++ didn't work, Code::Blocks compiled successfully. I started out with this basic program:

#include <allegro.h>


int main(){

    allegro_init();
    install_keyboard();
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

    readkey();

    return 0;

}   
END_OF_MAIN();

The problem comes in when I try to run it. It opens the little window as always, but rapidly blacks out my whole screen. I press any key and it takes me back to the little window telling me that it finished, which means the program worked. But I try any other program with allegro, like:

#include <allegro.h>

int x = 10;
int y = 10;

int main(){

    allegro_init();
    install_keyboard();
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

    while ( !key[KEY_ESC] ){

        clear_keybuf();

        acquire_screen();

        textout_ex( screen, font, " ", x, y, makecol( 0, 0, 0), makecol( 0, 0, 0) );

        if (key[KEY_UP]) --y;        
        else if (key[KEY_DOWN]) ++y;    
        else if (key[KEY_RIGHT]) ++x;
        else if (key[KEY_LEFT]) --x;

        textout_ex( screen, font, "@", x, y, makecol( 255, 0, 0), makecol( 0, 0, 0) );

        release_screen();

        rest(50);

    }    

    return 0;

}   
END_OF_MAIN();

And the same thing happens over and over again! Is there something I'm doing wrong?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Okay, I entered -lalleg in the Project/Project Options/Parameters/Compiler and added the lalleg.dll.a library in the Linker and everything turned out alright. Leftium helped with the GFX_AUTODETECT_WINDOWED. The solution was probably made by creating a diffferent project for every individual source code though.

\$\endgroup\$
1
  • \$\begingroup\$ Yep, that was my second guess: allegro.cc/forums/thread/611484. You can't have more than one main() function in a single project. Looks like you figured it out... \$\endgroup\$
    – Leftium
    Dec 2, 2012 at 11:53
0
\$\begingroup\$

It is difficult to understand what the problem is from your question:

  1. What results are you expecting?
  2. What are the actual results you are getting?

Nevertheless, I'll take a guess: Modern versions of Windows (XP and later?) don't support Allegro full-screen mode very well. You are probably seeing the unwanted effects of this.

Changing GFX_AUTODETECT to GFX_AUTODETECT_WINDOWED will cause Allegro to start your program in a window instead of fullscreen.

Related Allegro documentation

\$\endgroup\$
3
  • \$\begingroup\$ Thank you, I'm expecting the program to run successfully and show the text(in the second case). But, the actual results I'm getting is my whole screen blacking out and not showing anything. Even though the compiler(code::blocks) can compile it without any errors. \$\endgroup\$ Nov 21, 2012 at 3:47
  • \$\begingroup\$ I tried all those changes, and it helps only in not making the whole screen black out. Instead of opening one little window, it opens two. Neither showing the "@" i want. By clicking any key both windows close as if the program finished. \$\endgroup\$ Nov 22, 2012 at 4:33
  • 1
    \$\begingroup\$ @ArmandoOrtiz: I think your first program (and not your second program) is getting executed. Easy way to confirm: use GFX_AUTODETECT in the first file, and GFX_AUTODETECT_WINDOWED in the second file. If the whole screen goes black again, you are running the wrong program! \$\endgroup\$
    – Leftium
    Nov 23, 2012 at 1:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .