Outils pour utilisateurs

Outils du site


allegro:bitmaps

====== Différences ====== Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

allegro:bitmaps [2011/10/31 15:55]
127.0.0.1 modification externe
allegro:bitmaps [2012/06/29 17:02] (Version actuelle)
mrhide [Bitmaps]
Ligne 1: Ligne 1:
-===== Bitmaps =====+===== Allegro — Bitmaps =====
  
 +Dans cet article nous allons voir comment créer des bitmaps et comment dessiner dessus.
  
-In this section we learn how to create and draw bitmaps.+//Note importante : Allegro 5 utilise un backend OpenGL ou DirectX pour ses Bitmaps, ce qui impose certaines contraintes :\\ 
 +Les bitmaps ​trop grands(dépend du matériel) ne pourront être créés, et souvent les bitmaps ne pourrons pas être de taille inférieure à 16*16.\\ 
 +De plus la plupart des systèmes n'​acceptent que des bitmaps dont la taille est une puissance de 2.\\ 
 +Si on demande à Allegro de créer un Bitmap d'une taille qui ne convient pas au matériel, Allegro renvoie un bitmaps de la première taille au dessus qui correspond.//
  
-==== Current Display/​Target ​====+//Pour toutes ces raisons faites attention quand vous dessinez sur votre Bitmap, il se pourrait bien qu'il soit plus grand que vous ne le pensiez !// 
 +==== Buffer de dessin ​====
  
-Allegro 5 has the concept ​that of the current displayand drawing target. They are related, but the target needs not be the current display.+Allegro 5 introduit le concept ​de buffer de dessinle buffer de dessin n'est pas affiché.
  
-When creating a display, ​it is made the current display, and its backbuffer is made the drawing target.+Quand on crée un display, ​on crée automatiquement un buffer de dessin.
  
-All drawing operations draw to the drawing target, which in most cases, is probably also the current ​display's backbuffer.+Toutes les opérations de dessin doivent se faire sur le buffer de dessin du display ​actuel.
  
-==== Basic Example ​====+==== Exemple basique ​====
  
-Building on the previous example, we will add a bouncing bitmap.+Encore une fois il est basé sur l'​exemple de l'​article précédent.
  
 <file c main.c> <file c main.c>
Ligne 130: Ligne 135:
 </​file>​ </​file>​
  
-=== Walk through ​=== +==== Détails ==== 
- +On ajoute une image rebondissanteOn détaillera les nouveautés et modifications.
-Building on the last example we have added a silly bouncing bitmapWe will only cover the new and changed bits.+
  
 <code c>const int SCREEN_W = 640; <code c>const int SCREEN_W = 640;
 const int SCREEN_H = 480; const int SCREEN_H = 480;
 const int BOUNCER_SIZE = 32;</​code>​ const int BOUNCER_SIZE = 32;</​code>​
-Here we've defined a few constants to make our lives a little easierTwo to define the size of the displayand one for the dimensions ​of the bouncing box.+ 
 +On définit des constantes afin de nous rendre la vie plus facileLes deux premières définissent la taille du Displayet la troisième définit les deux dimensions ​de l'​image.
  
 <code c>   ​bouncer = al_create_bitmap(BOUNCER_SIZE,​ BOUNCER_SIZE);​ <code c>   ​bouncer = al_create_bitmap(BOUNCER_SIZE,​ BOUNCER_SIZE);​
Ligne 146: Ligne 151:
       return -1;       return -1;
    ​}</​code>​    ​}</​code>​
-Here we create our bitmap using **al_create_bitmap** ​with a width and height ​of **BOUNCER_SIZE**. ​On failure, **al_create_bitmap** will return ​**NULL**, ​and our failure handling code will clean up previously created objects, and then exit the program.+On crée notre image avec **al_create_bitmap** ​les paramètres sont la largeur(width) et la hauteur(height), ici c'​est ​**BOUNCER_SIZE**. ​En cas d'​échec cette fonction renvoie ​**NULL**, ​dans ce cas on nettoie les objets précédemment crées et on quitte le programme.
  
 <code c>   ​al_set_target_bitmap(bouncer);</​code>​ <code c>   ​al_set_target_bitmap(bouncer);</​code>​
-Here's a new concept. ​The target bitmap ​is the bitmap in which all drawing functions currently draw toThis is normally handled by allegro, ​but should you need to draw directly to a bitmap ​(rather than loading one)you call **al_set_target_bitmap** ​and then use the drawing functions as normal.+Ici on introduit un nouveau ​concept. ​Le target bitmap ​est le buffer de dessin dans lequel toutes les fonctions de dessin dessinentC'est normalement géré par allegro, ​mais si vous devez dessiner directement dans un bitmap, ​vous appelez ​**al_set_target_bitmap** ​puis utilisez les fonctions de dessin normalement.
  
 <code c>   ​al_clear_to_color(al_map_rgb(255,​ 0, 255));</​code>​ <code c>   ​al_clear_to_color(al_map_rgb(255,​ 0, 255));</​code>​
-Like beforeexcept now **al_clear_to_color** ​clears our bitmap, ​instead of the display. ​+Comme précédemmentexcepté que **al_clear_to_color** ​va éditer notre bitmap, ​au lieu du display. ​
  
 <​code> ​  ​al_set_target_bitmap(al_get_backbuffer(display));</​code>​ <​code> ​  ​al_set_target_bitmap(al_get_backbuffer(display));</​code>​
-Change the drawing target back to the display ​we created.+Remet la cible des fonctions de dessin sur le display.
  
 <code c> <code c>
Ligne 168: Ligne 173:
          ​bouncer_x += bouncer_dx;          ​bouncer_x += bouncer_dx;
          ​bouncer_y += bouncer_dy;</​code>​          ​bouncer_y += bouncer_dy;</​code>​
-Not particularly interestingBut here is the bouncing logicIf the square hits the display's bordersreverse ​direction. ​We put the logic in the timer event, ​so that the bouncing ​bitmap ​moves at the same rate on any computer.+Pas particulièrement intéressantC'est le code pour faire le rebondissementSi le carré touche un bord du display, ​il change de direction. ​Ce code est appelé à la suite d'​un ​event de Timerainsi le bitmap ​se déplacera à la même vitesse sur toutes les machines.
  
 <code c>         ​al_draw_bitmap(bouncer,​ bouncer_x, bouncer_y, 0);</​code>​ <code c>         ​al_draw_bitmap(bouncer,​ bouncer_x, bouncer_y, 0);</​code>​
-Now draw our bitmap ​to the display.+dessine notre bitmap ​sur le display.
  
 <code c>   ​al_destroy_bitmap(bouncer);</​code>​ <code c>   ​al_destroy_bitmap(bouncer);</​code>​
-Destroy the bouncer ​bitmap.+Détruit un objet de type bitmap
 + 
 +==== Charger des bitmaps depuis le disque ==== 
 + 
 +Voici la méthode utilisant les fonctions path d'​allegro afin de garantir un code portable 
 + 
 +<code c> 
 +ALLEGRO_BITMAP * get_resource_image(const char * filename) { 
 +   ​ALLEGRO_PATH *path; 
 +   ​ALLEGRO_BITMAP *image; 
 + 
 +   path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);​ 
 +   ​al_append_path_component(path,​ "​images"​);​ 
 +   ​al_set_path_filename(path,​ filename);​ 
 + 
 +   image = al_load_bitmap(al_path_cstr(path,​ '/'​));​ 
 +   ​al_destroy_path(path);​ 
 +   ​return image; 
 +
 +</​code>​ 
 + 
 +Dans ce cas de figure, les ressources de notre jeu sont placées dans le dossier **image** relativement à l'​exécutable.\\ 
 +Ce code fait pointer path sur le dossier contenant le fichier exécutable de notre jeu grâce au paramètre **ALLEGRO_RESOURCES_PATH**,​ puis ajoute le dossier **"​images"​** et enfin le nom de notre fichier au path.
  
-That concludes the basic Bitmap use in Allegro 5.+**al_path_cstr(path,​ '/'​)** permet de rendre notre path valide sur tous les OS.
  
-==== Intermediate Example ====+La fonction **al_load_bitmap** va chercher la fonction capable de charger l'​image en fonction de son extension (.jpg, .bmp ...), et renvoit NULL si elle ne la trouve pas ou si la fonction a échouée à charger l'​image.
  
- FIXME Loading bitmaps using the allegro-image addon Example will go here.+**Par défaut ​allegro ​ne gère aucun format d'image**, il faut utiliser le greffon [[allegro:​addon_image|ImageIO]] afin de pouvoir charger quelques formats.
  
 +Nous en avons fini avec les bitmaps d'​Allegro 5.
  
-[[allegro:​timers|Précédent]] << [[allegro:​start|Sommaire]] >> [[allegro:​input|Suivant]]+[[allegro:​timers|Précédent]] << [[allegro:​start#articles|Sommaire]] >> [[allegro:​input|Suivant]]
allegro/bitmaps.txt · Dernière modification: 2012/06/29 17:02 par mrhide