====== Différences ====== Ci-dessous, les différences entre deux révisions de la page.
allegro:display [2011/12/04 23:21] mrhide [Displays] |
allegro:display [2012/08/08 03:47] (Version actuelle) mrhide [Détails] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ===== Displays ===== | + | ===== Allegro — Displays ===== |
Dans cet article nous détaillerons un exemple simple sur la création d'un display et la définition de paramètres pour ce display. | Dans cet article nous détaillerons un exemple simple sur la création d'un display et la définition de paramètres pour ce display. | ||
- | ==== Basic Example ==== | + | ==== Exemple basique ==== |
- | Here we demonstrate how to create a display, clear the display, display it for 10 seconds, and exit. | + | |
- | === Code === | + | Ce code montre comment créer un display, nettoyer le display et attend 10 secondes. |
- | <file c main> | + | |
+ | <file c main.c> | ||
#include <stdio.h> | #include <stdio.h> | ||
#include <allegro5/allegro.h> | #include <allegro5/allegro.h> | ||
Ligne 38: | Ligne 38: | ||
</file> | </file> | ||
- | === Walk through === | + | ==== Détails ==== |
- | + | ||
- | These walk throughs will explain important lines of code in the examples. | + | |
<code c>#include <stdio.h> | <code c>#include <stdio.h> | ||
#include <allegro5/allegro.h></code> | #include <allegro5/allegro.h></code> | ||
- | Here we include the headers necessary for this example. **stdio.h** is required for the **fprintf** function, and **allegro5/allegro.h** is necessary for all of the allegro functions that are used in this example. | + | **stdio.h** est nécessaire pour la fonction **fprintf** et **allegro5/allegro.h** est nécessaire pour utiliser allegro ! |
<code c>int main(int argc, char **argv) | <code c>int main(int argc, char **argv) | ||
{</code> | {</code> | ||
- | A standard main function, with the argument count and argument vector parameters. | + | Une fonction **main** standard avec le nombre et le tableau de ses paramètres. |
<code c>if(!al_init()) { | <code c>if(!al_init()) { | ||
Ligne 57: | Ligne 55: | ||
}</code> | }</code> | ||
- | Here we initialize the Allegro library. If it should fail, it will return false, and the <code>if()</code> block will execute, printing a message to standard error, and then exit. | + | Ici on initialise la lib allegro. En cas d'échec cette fonction renvoit **false** et un message est affiché sur stderr. |
<code c>display = al_create_display(640, 480);</code> | <code c>display = al_create_display(640, 480);</code> | ||
- | **al_create_display** will create a display with the given width and height. Should **al_create_display** fail to create a display for some reason, it will return **NULL**. | + | **al_create_display** crée un display avec la taille spécifiée. En cas d'échec cette fonction renvoi **NULL**. |
- | + | ||
- | <code c> if(!display) { | + | |
- | fprintf(stderr, "failed to create display!\n"); | + | |
- | return -1; | + | |
- | } | + | |
- | </code> | + | |
- | + | ||
- | Should **al_create_display** fail, we trigger this if block, print a failure message, and then exit. | + | |
<code c>al_clear_to_color(al_map_rgb(0,0,0));</code> | <code c>al_clear_to_color(al_map_rgb(0,0,0));</code> | ||
- | **al_map_rgb** takes three arguments, the value for the red, green, and blue components of the color respectively, and will return a **ALLEGRO_COLOR** structure. | + | **al_map_rgb** attend 3 paramètres, les valeurs pour les composantes rouge, verte et bleu de la couleur voulue, elle renvoi une structure **ALLEGRO_COLOR**. |
- | **al_clear_to_color** clears the current display //the one we just created// to a given color. | + | **al_clear_to_color** efface le display //celui que l'on vient juste de créer// avec la couleur donnée. |
<code c>al_flip_display();</code> | <code c>al_flip_display();</code> | ||
- | Allegro, by default, creates two image buffers -- the one being displayed on the screen, and the one being drawn on in the code. When you have finished drawing to one of the image buffers for one loop, then you are ready to display its result to the screen for the user. <code>al_flip_display</code> is called to swap the two image buffers around so that the first image buffer is now displayed to the user while the second image buffer becomes the one you will draw on. Failing to call this function will result in only the single, blank image buffer being shown on the screen. | + | Par défaut Allegro crée deux buffers image -- celui affiché sur l'écran, et celui sur lequel on dessine. Une fois que vous avez fini de dessiner sur le buffer, vous êtes prêt à afficher le résultat sur l'écran.\\ |
+ | **al_flip_display** est appelé pour imprimer l'image du buffer de dessin à l'écran. l'échec de l'appel à cette fonction affichera une fenêtre blanche. | ||
<code c>al_rest(10.0);</code> | <code c>al_rest(10.0);</code> | ||
- | Here we rest the program for 10 seconds. **al_rest** takes a floating point integer specifying how many seconds to sleep. Using any valid floating point number is valid, including numbers less than 1.0. Allegro will attempt to sleep for the amount of time specified, but it does not have perfect accuracy. | + | Ici on demande au programme d'attendre pendant 10 secondes. **al_rest** attend en paramètre des secondes, néanmoins selon l'environnement cette fonction aura une précision jusqu'à une dizaine de milliseconde. |
<code c>al_destroy_display(display);</code> | <code c>al_destroy_display(display);</code> | ||
- | This function destroys our display and frees the memory and should be called when you are about to shut down the program. | + | Cette fonction détruit notre display et libère la mémoire, elle doit être appelée quand vous vous apprêtez à fermer le programme. |
- | And that concludes our basic introduction to Allegro 5 displays. | + | C'est la fin de notre introduction aux displays avec Allegro 5. |
- | [[allegro:start|Sommaire]] >> [[allegro:events|suite]] | + | [[allegro:Intro|Précédent]] << [[allegro:start#articles|Sommaire]] >> [[allegro:events|Suivant]] |