P. 1


|Views: 0|Likes:
Published by Avinash Tharwani

More info:

Published by: Avinash Tharwani on Aug 30, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less





Allegro Newbie Tutorial : Lesson 1 - Getting Started This lesson will initialize allegro, set up keyboard support, show

an empty scre en and wait for a keypress - then quit. Here is your first line. You must include the allegro header file or else nothin g will work! #include <allegro.h> // You must include the Allegro Header file Make sure your main always looks like the following. Don't worry if you aren't u sed to it, soon enough you will memorize this. int main(int argc, char *argv[]) { Next, we will initialize Allegro. This will set up all the components it needs i n order to run. This function basically does all the hard stuff for you. allegro_init(); // Initialize Allegro Now that Allegro is initialized we will want to set up an input device so the us er will be able to control how the program will execute. For this program we wan t to include support only for the keyboard. This function will set up all keyboa rd related functions and variables. install_keyboard(); // Initialize keyboard routines Ok. Almost everything is set up and ready to roll. There is one more part that n eeds to be done before we can process any kind of output to the user: setting up the screen. This next part can be a little tricky, and may take some time to ge t used to. 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 s creen. (We don't need to worry about these for the moment, so entering zeros wil l just create NO virtual screen.) set_gfx_mode(GFX_AUTODETECT, 640,480,0,0); // Change our graphics mode to 640x48 0 This almost concludes Lesson 1. Now the screen will change to the desired resolu tion. In order to see the effect, we need to stall the program for a moment. Thi s next function simply waits for any keypress from the keyboard. Once a key is p resed it will then continue through the program. readkey(); // Wait untill a key is pressed After the key is pressed, we must tell the program that everything executed with out error and then exit. return 0; // Exit with no errors } We are not done yet, however. There is still one more thing that needs to be don e. This part is very important. In every allegro program you write, you must inc lude this function. The following function is Allegro specific - and your progra ms will not work unless it is found right after the closing bracket of your main

function. . END_OF_MAIN() // This must be called right after the closing bracket of your MAI N function.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->