0

This is a piece of code I copied from a tutorial of allegro.
When I changed the window width and height to 800, the program just crash, what happened?

set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 800, 0, 0);

buffer = create_bitmap( 800, 800);

#include <allegro.h>
#include <cstdlib>
#include <time.h>


int x = 100;
int y = 100;

int tempX = 100;
int tempY = 100;

int dir = 1; //This will keep track of the circles direction
            //1= up and left, 2 = down and left, 3 = up and right, 4 = down and right

BITMAP *buffer; //This will be our temporary bitmap for double buffering

void setupboard(){

    tempX = x;
    tempY = y;

    if (dir == 1 && x != 20 && y != 20){
     
        --x;
        --y;
              
    } else if (dir == 2 && x != 20 && y != 460){

        --x;
        ++y;

    } else if (dir == 3 && x != 620 && y != 20){

        ++x;
        --y;

    } else if (dir == 4 && x != 620 && y != 460){

        ++x;
        ++y;

    } else { 

        dir = rand() % 4 + 1;

    }    
    
    acquire_screen();
    circlefill ( buffer, tempX, tempY, 20, makecol( 0, 0, 0));
    circlefill ( buffer, x, y, 20, makecol( 128, 255, 0));
    draw_sprite( screen, buffer, 0, 0);
    release_screen();
    
    rest(10);

}    

int main(){

    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
    
    buffer = create_bitmap( 640, 480); 
    
    while( !key[KEY_ESC]){
     
        setupboard();
   
    }    
    
    return 0;

}
END_OF_MAIN();
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by gunbuster363
0

I'm not really sure why it would do this. But i'd suggest using standard resolutions like 800x600, instead of custom resolutions like what you just did there with 800x800. Also check to make sure that your program's color depth is equal to your desktop's color depth.

From my expereience with allegro, the way you write the program is what affect's it's ability to run in either full screen or windowed mode. Your program is almost guaranteed to run in full screen mode, but might now work in windowed mode.

0

I heard ppl said the dimension got to be a mutiiple of 4,
but i am never able to test it

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.