1 /*
2 * Example program for the Allegro library, by Shawn Hargreaves.
3 *
4 * This is a very simple program showing how to get into graphics
5 * mode and draw text onto the screen.
6 */
7
8
9 #include <allegro.h>
10
11
12
main(void)13 int main(void)
14 {
15 /* you should always do this at the start of Allegro programs */
16 if (allegro_init() != 0)
17 return 1;
18
19 /* set up the keyboard handler */
20 install_keyboard();
21
22 /* set a graphics mode sized 320x200 */
23 if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
24 if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
25 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
26 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
27 return 1;
28 }
29 }
30
31 /* set the color palette */
32 set_palette(desktop_palette);
33
34 /* clear the screen to white */
35 clear_to_color(screen, makecol(255, 255, 255));
36
37 /* you don't need to do this, but on some platforms (eg. Windows) things
38 * will be drawn more quickly if you always acquire the screen before
39 * trying to draw onto it.
40 */
41 acquire_screen();
42
43 /* write some text to the screen with black letters and transparent background */
44 textout_centre_ex(screen, font, "Hello, world!", SCREEN_W/2, SCREEN_H/2, makecol(0,0,0), -1);
45
46 /* you must always release bitmaps before calling any input functions */
47 release_screen();
48
49 /* wait for a key press */
50 readkey();
51
52 return 0;
53 }
54
55 END_OF_MAIN()
56