|
allegro newbie, need help on my frst program |
vlad417
Member #8,720
June 2007
|
i have just started using the allegro library and i'm already confused why my program won't run properly. #include <allegro.h> using namespace std; int main(){ allegro_init(); install_keyboard(); install_timer(); do{ BITMAP *bmp = create_bitmap(800,640); clear_bitmap(bmp); int blue = makecol(0,0,256); putpixel(screen,100,100, blue); }while(!key[KEY_ESC]); allegro_exit(); } END_OF_MAIN(); code is free to edit. all i want this to do is open a window 800,640 and draw a blue pixel at (100,100). the program compiles and links, put when i open the .exe the concole opens and then windows says "pixels.exe has encountered a problem and needs to close. We are sorry for the inconvenience. blah blah blah" how do i get this baby to run the way i want it? thx. |
kazzmir
Member #1,786
December 2001
|
You didnt call set_gfx_mode, the function that creates the graphics window. int main(){ allegro_init(); install_keyboard(); install_timer(); set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 640, 0, 0 ); // add this ... } Also the lines BITMAP *bmp = create_bitmap(800,640); clear_bitmap(bmp); don't do anything. Maybe you want them to do something later but in this program they do nothing. |
vlad417
Member #8,720
June 2007
|
thx EDIT:
what happens is it opens a white window and i can draw simply by dragging |
LennyLen
Member #5,313
December 2004
|
You need to set the color depth before setting the gfx mode. This should fix the last two problems.
|
kazzmir
Member #1,786
December 2001
|
Oh yea, the default color depth is 8 but it looks like you want 32. You don't really need nor should use _putpixel32 unless you really know what you are doing. int main(){ ... set_color_depth( 32 ); set_gfx_mode( ... ); ... int blue = makecol( 0, 0, 255 ); ... putpixel( screen, x, y, blue ); ... }
|
Jonatan Hedborg
Member #4,886
July 2004
|
As for the rectangular thing; what resolution is your desktop at? If it's not the same ratio as your monitor (4:3 usually 16:9 for widescreen monitors), or, all pixels will be rectangular. Though it's probably because you are trying to draw a 32 bit integer to 8 bit surface.
|
vlad417
Member #8,720
June 2007
|
thx guys, ya the solution was to set the color depth and not use _putpixel32() it solved all 3 problems |
James Stanley
Member #7,275
May 2006
|
Why 800x640? |
|