Saturday, 14 March 2015


Hello, It's me again. If you have read my post's from previous articles by now we have installed Allegro 5 library inside Visual C++ 2008/10. Therefore we can write our first Allegro 5 program inside Visual C++ 2008.

_________________________________________

//First Allegro program
//© Amar Tufo & Mike Gaig 2015
//http://www.amartufointeractive.blogspot.com


#include <allegro5\allegro.h>
#include <allegro5\allegro_native_dialog.h>
int main()
{
 //create a display
 ALLEGRO_DISPLAY *display = NULL;

 //check if Allegro is initialized else
 if(!al_init())
 {
  al_show_native_message_box(NULL, NULL, NULL, "Failed to initialize Allegro", NULL, NULL);
  return -1;
 }

 //create a window
 display = al_create_display(640, 480);

 //check if display is created else
 if(!display)
 {
   al_show_native_message_box(NULL, NULL, NULL, "Failed to initialize display", NULL, NULL);

  return -1;
 }
 //Show magenta color on display
 al_clear_to_color(al_map_rgb(255,0,255));
 al_flip_display();
 al_rest(5.0); //Wait for 5 secunds and then close the program


 //Destroy the display
 al_destroy_display(display);

 return 0;
}
____________________________________________

Ok, here we have the source code of our very first Allegro 5 program which was written inside Visual C++ 2008. What it does? Basically, this program does not do anything special instead to check weather you have installed your Allegro 5 library properly or not. But there's one part of program that does something. Take a look at this few lines of code.

//Show magenta color on display
 al_clear_to_color(al_map_rgb(255,0,255));
 al_flip_display();
 al_rest(5.0); //Wait for 5 secunds and then close the program

So in the code above we have initialize the Allegro library so that we can use it. I have comment the code lines in the source code so that you can see what the each of that code line does. Now in this very few lines of code is only working part of our very first Allegro 5 program. This few lines of code actually creates a window of our program which is filled with magenta color. The window is appearing for about 5 seconds and than program closes. Now if you have copied my source code given above and If you have write it exactly as I did, than you should get exactly the same output as I. Take a look at picture down bellow. 


Figure1: Output of our first Allegro 5 program with magenta color

There's only one thing that I would like to explain to you. Weather you know what RGB stands for or not. It represents the three colors, red, green and blue or better known as RGB. It means that every color has a unique code with which we can represent it. For example the red color in RGB code will be: 255, 0, 0. Ok, let's change the color from magenta to red in our window trough the code. 

//Show magenta color on display
 al_clear_to_color(al_map_rgb(255,0, 0));
 al_flip_display();
 al_rest(5.0); //Wait for 5 secunds and then close the program

Now let's see what is going to happen. If you have change the RGB color from magenta to red than you should get something like this.


Figure1.1: Output of our first Allegro 5 program with red color

Ok, now you now how to set and configure Allegro 5 library. So far you have write the very first Allegro 5 program and learn how to manipulate the RGB colors as well as how to represent the colors inside Allegro 5 trough the code. That's all from me. Please see the full video tutorial about writing your very first Allegro 5 program by Mike Geig. 
Vid1: Your first Allegro 5 program by Mike Geig

Ass I promised before I'm gonna upload the source code of every single Allegro 5 course program that we made and the slightly the same code is available at Mike Geig official web site which you can download and see it in action.


_____________

The resources list:

[1] Your first Allegro 5 program

[2] Wanna learn more, than see MikeGeig TV on YouTube

[3] See more about Allegro at:

Reakcije:

0 komentari:

Post a Comment

Weather

Advertisement

Follow me on Facebook:

Popular Posts