Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
    
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... –  Leftium Dec 2 '12 at 11:53

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

share|improve this answer
    
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. –  Armando Ortiz Nov 21 '12 at 3:47
    
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. –  Armando Ortiz Nov 22 '12 at 4:33
1  
@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! –  Leftium Nov 23 '12 at 1:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.