0

Just installed Allegro 4.2.2, and I'm trying to run a simple program.

When launched, screen is totally black, but input normally reacts to keys. I found that screen is 0x00000000 (a nullptr). Anyway, set_gfx_mode returns no error.

MinGW doesn't yell at all, no warnings, nothing. Code Blocks has linked only liballeg.a and liballeg_s.a with other options:

-lalleg_s -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound

Here's the code:

#include <stdio.h>
#include <stdlib.h>

#include <allegro.h>

#include <time.h>


int main() {
    srand( time( NULL ) );
    allegro_init();
    // screen
    set_color_depth( 32 );
    if ( set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ) < 0 ) {
        printf( "Error set_gfx_mode: %s\n", allegro_error );
    }
    BITMAP* buffer = create_bitmap_ex( 32, SCREEN_W, SCREEN_H );
    printf( "Screen location: %p\n", screen );
    // keyboard and mouse
    install_keyboard();
    install_mouse();
    show_os_cursor( 1 );
    // main loop
    bool done = false;
    while ( !done ) {
        // keys
        if ( keypressed() ) {
            int keyID = readkey() & 0xFF;
            switch ( keyID ) {
                case 27: { // escape
                    done = true;
                    break;
                }
            }
        }
        // rendering
        clear_bitmap( buffer );
        rectfill( buffer, 50, 50, 150, 150, 0x00FFFFFF );
        blit( buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H );
    }
    destroy_bitmap( buffer );
    allegro_exit();
    return 0;
}

END_OF_MAIN()

1 Answers1

0

It is a very simple error, you are not defining anywhere on your code what is the value of SCREEN_W nor SCREEN_H.

Add this after the #include lines:

#define SCREEN_W 640
#define SCREEN-h 480

Of course, you can change the value to whatever screen size you want, as long as the graphics driver/card supports it.

rlam12
  • 603
  • 5
  • 16
  • OK so I forgot Allegro 4 defines those as globals already... so that is not the issue... Will leave the answer anyways to avoid someone else answering the same wrong answer – rlam12 Oct 27 '15 at 02:16