This lesson will initialize allegro, set up keyboard support, show an empty screen and wait for a keypress - then quit.
Here is the first line. You must include the allegro header file or else nothing will work!
#include <allegro.h> // You must include the Allegro Header file
Make sure that main always looks like the following. Don't worry if you aren't used to it, soon enough you will memorize this.
int main(int argc, char *argv[])
{allegro_init(); // Initialize Allegro
Now that Allegro is initialized we will want to set up an input device so the user will be able to control how the program will execute. For this program we want to include support only for the keyboard. This function will set up all keyboard related functions and variables.install_keyboard(); // Initialize keyboard routines
set_gfx_mode will set the graphics mode that you will use in your program. Here is what each paramater is:
set_gfx_mode(GRAPHICS MODE, Width, Height, Virtual Width, Virtual Height);
- Using GFX_AUTODETECT for a graphics mode will set everything for you, using the machine's preinstalled drivers.
- The width and the height are simple that, the width and the height of the screen.
- The V_Width and V_Height are the virtual (not visible) width and height of the screen. (We don't need to worry about these for the moment, so entering zeros will just create NO virtual screen.)
set_gfx_mode(GFX_AUTODETECT, 640,480,0,0); // Change our graphics mode to 640x480
readkey(); // Wait untill a key is pressed
return 0; // Exit with no errors
}
END_OF_MAIN() // This must be called right after the closing bracket of your MAIN function.
Complete Code:
1: #include <allegro.h> // You must include the Allegro Header file
2: int main(int argc, char *argv[])
3: {
4: allegro_init(); // Initialize Allegro
5: install_keyboard(); // Initialize keyboard routines
6: set_gfx_mode(GFX_AUTODETECT, 640,480,0,0);
7: readkey(); // Wait untill a key is pressed
8: return 0; // Exit with no errors
9: }
10: END_OF_MAIN()
Back to Allegro Menu
Next –> Lesson 2 - Bitmaps