summaryrefslogtreecommitdiff
path: root/sdl-test
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2010-10-24 11:43:12 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2010-10-24 11:43:12 +0000
commit66932ab7a21b6c4b36542340ea143924da274834 (patch)
treefb53240b3bac2b4d475c530f08071b4303d42282 /sdl-test
parent295cb9e5df383d57b6a916679352e7766d202d16 (diff)
download2010-netlemmings-66932ab7a21b6c4b36542340ea143924da274834.tar.gz
2010-netlemmings-66932ab7a21b6c4b36542340ea143924da274834.tar.bz2
2010-netlemmings-66932ab7a21b6c4b36542340ea143924da274834.zip
Test à la con de transparence avec le problème de Gimp qui change la couleur de la couleur transparente dans la palette
git-svn-id: file:///var/svn/2010-netlemmings/trunk@111 077b3477-7977-48bd-8428-443f22f7bfda
Diffstat (limited to 'sdl-test')
-rw-r--r--sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/Makefile17
-rw-r--r--sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/brick_10.gifbin0 -> 1442 bytes
-rw-r--r--sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/brick_10_gimp.gifbin0 -> 719 bytes
-rw-r--r--sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/main.c178
-rw-r--r--sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/paysage_neige.pngbin0 -> 590730 bytes
5 files changed, 195 insertions, 0 deletions
diff --git a/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/Makefile b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/Makefile
new file mode 100644
index 0000000..6482586
--- /dev/null
+++ b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/Makefile
@@ -0,0 +1,17 @@
+# Makefile
+#PATH = /usr/include/SDL
+TARGET = transp
+OBJECTS = main.o
+
+CFLAGS = -O3 -Wall -g -I/usr/include/SDL -L/usr/lib
+LIBS = -lSDL -lSDL_image
+CC = gcc
+
+all: $(TARGET)
+
+$(TARGET): $(OBJECTS)
+ $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
+
+clean:
+ -rm *.o $(TARGET)
+
diff --git a/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/brick_10.gif b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/brick_10.gif
new file mode 100644
index 0000000..148268a
--- /dev/null
+++ b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/brick_10.gif
Binary files differ
diff --git a/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/brick_10_gimp.gif b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/brick_10_gimp.gif
new file mode 100644
index 0000000..645c820
--- /dev/null
+++ b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/brick_10_gimp.gif
Binary files differ
diff --git a/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/main.c b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/main.c
new file mode 100644
index 0000000..3803427
--- /dev/null
+++ b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/main.c
@@ -0,0 +1,178 @@
+/*******************************************************/
+/** Programme de PERRUCHON Romain pour developpez.com **/
+/** Chapitre IV : Transparence - SDL_Color_Key **/
+/*******************************************************/
+
+//Les fichiers d'entête
+//SDL_image pour utiliser IMG_load (chargement image autre que Bitmap : ici *.png
+#include "SDL/SDL.h"
+#include "SDL/SDL_image.h"
+
+//Les attributs de l'ecran (640 * 480)
+const int SCREEN_WIDTH = 640;
+const int SCREEN_HEIGHT = 480;
+const int SCREEN_BPP = 24;
+
+//Les surfaces
+SDL_Surface *background = NULL;
+SDL_Surface *gif1 = NULL;
+SDL_Surface *gif2 = NULL;
+SDL_Surface *screen = NULL;
+
+//La structure d'evenement
+SDL_Event event;
+
+SDL_Surface *load_image( char* filename )
+{
+ //L'image qui est chargée
+ SDL_Surface* loadedImage = NULL;
+
+ //L'image optimisée que nous utiliserons par la suite
+ SDL_Surface* optimizedImage = NULL;
+
+ //Chargement de l'image
+ loadedImage = IMG_Load( filename );
+
+/* //Si l'image est chargée
+ if( loadedImage != NULL )
+ {
+ //creation de l'image optimisée
+ optimizedImage = SDL_DisplayFormat( loadedImage );
+
+ //liberation de l'ancienne image
+ SDL_FreeSurface( loadedImage );
+
+ //si l'image optimisée créé est bonne
+ if( optimizedImage != NULL )
+ {
+ Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF );
+
+ //on met tout les pixel de couleur R 0, G 0xFF, B 0xFF transparent
+ SDL_SetColorKey( optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey );
+ }
+ }
+
+ //on retourne l'image optimisé
+ return optimizedImage;
+*/
+ return loadedImage;
+}
+
+void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
+{
+ //rectangle temporaire
+ SDL_Rect offset;
+
+ offset.x = x;
+ offset.y = y;
+
+ //on blit la surface
+ SDL_BlitSurface( source, NULL, destination, &offset );
+}
+
+int init()
+{
+ //initialisation de tout les sous-systemes de sdl
+ if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
+ {
+ return 1;
+ }
+
+ //on met en place l'ecran
+ screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
+
+ //Si il y a une erreur lors de la mise en place de l'ecran
+ if( screen == NULL )
+ {
+ return 1;
+ }
+
+ //on met en place la barre caption de la fenetre
+ SDL_WM_SetCaption( "\"Hello!\"", NULL );
+
+ //si tout s'est bien passé
+ return 1;
+}
+
+int load_files()
+{
+ //chargement du fond
+ background = load_image( "paysage_neige.png" );
+
+ //si le fond ne se charge pas
+ if( background == NULL )
+ {
+ return 0;
+ }
+
+ //on charge l'image qu'on va appliquer sur le fond
+ gif1 = load_image( "brick_10.gif" );
+ gif2 = load_image( "brick_10_gimp.gif" );
+
+ //si l'image se charge mal
+ if( (gif1 == NULL) || (gif2 == NULL) )
+ {
+ return 0;
+ }
+
+ return 1;
+}
+
+void clean_up()
+{
+ //Liberation des surfaces surfaces
+ SDL_FreeSurface( background );
+ SDL_FreeSurface( gif1 );
+
+ //On quitte SDL
+ SDL_Quit();
+}
+
+int main( int argc, char* args[] )
+{
+ //ce qui va nous permettre de quitter
+ int quit = 0;
+
+ //Initialisation
+ if( init() == 0 )
+ {
+ return 1;
+ }
+
+ //chargement des fichiers
+ if( load_files() == 0 )
+ {
+ return 1;
+ }
+
+ //Application des surfaces sur l'ecran
+ apply_surface( 0, 0, background, screen );
+ apply_surface( 270, 190, gif1, screen );
+ apply_surface( 270, 280, gif2, screen );
+
+ //mise à jour de l'ecran
+ if( SDL_Flip( screen ) == -1 )
+ {
+ return 1;
+ }
+
+ //Tant que l'utilisateur n'a pas quitter
+ while( quit == 0 )
+ {
+ //tant qu'il y a un evenement
+ while( SDL_PollEvent( &event ) )
+ {
+ //Si l'utilisateur ferme la fenetre avec le X
+ if( event.type == SDL_QUIT )
+ {
+ //On quitte le programme
+ quit = 1;
+ }
+ }
+ }
+
+ //liberation des surface et on quitte sdl
+ clean_up();
+
+ return 0;
+}
diff --git a/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/paysage_neige.png b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/paysage_neige.png
new file mode 100644
index 0000000..41c0f1b
--- /dev/null
+++ b/sdl-test/SDL_tuto/Chapitre_V_:_Transparence/test_gif/paysage_neige.png
Binary files differ