could someone write me a sample allegro program in C++
just a spuare or a triangle just enough to get me going
Printable View
could someone write me a sample allegro program in C++
just a spuare or a triangle just enough to get me going
This is a newb question but what is Allegro?
>>This is a newb question but what is Allegro?
It is kind of like an addition to C++ meant for game programming.
they have plenty of demos at www.allegro.cc this is more of a game programming question should be moved to the game fourm people in there know allegro a bit more. The easiest way to use graphics in allegro is to use bitmaps and blits IMHO. drawing lines and such isn't what the library is designed for. So sample code for a triangle?
Code:#include <allegro.h>
const int scrx = 1024;
const int scry = 768;
const int BSIZE = 960;
BITMAP *TRI;
RGB *TRIPAL;
int main(int argc, char *argv[])
{
if (allegro_init())
{
allegro_message("Cannot initalize Allegro.\n");
return 1;
}
if (install_keyboard())
{
allegro_message("Cannot initalize keyboard input.\n");
return 1;
}
if (!install_mouse())
{
allegro_message("Cannot initalize mouse input.\n");
return 1;
}
set_mouse_sprite(NULL);
//set graphics mode, trying all acceptable depths
set_color_depth(32);
if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) {
set_color_depth(24);
if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) {
set_color_depth(16);
if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) {
set_color_depth(15);
if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) {
allegro_message("Video Error: %s.\n", allegro_error);
return 1;
}
}
}
}
TRI = load_bitmap("triangle.bmp",TRIPAL);//make a bitmap in paint or whatever and save it as triangle
blit(TRI,screen,0,0,0,0,50,50); // change 50's to max X and max Y of the bitmap
while(!key[KEY_ESC){}
}