Bonjour,
j'essai actuellement de separer une image en 4 sprite comme expliquer sur un site internet ( je ne sais pas si je peux le citer) mais il se trouve que j'arrive juste a afficher un fond blanc et, l'image n'apparait pas et n'est pas afficher en étant " eclater " sur ce fond. voici le code peut être comprendrez vous mieux merci d'avance pour votre aide :)
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL_image.h>
#include <string>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
const int SHEET_WIDTH = 200;
const int SHEET_HEIGHT = 200;
SDL_Surface *faces = NULL;
SDL_Surface *screen = NULL;
SDL_Event event;
SDL_Rect clip[ 4 ];
SDL_Surface *load_image( std::string filename ) {
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = SDL_LoadBMP( filename.c_str() );
if( loadedImage != NULL ) {
optimizedImage = SDL_DisplayFormat( loadedImage );
SDL_FreeSurface( loadedImage );
}
return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ,SDL_Rect*clip=NULL) {
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface( source, clip, destination, &offset );
}
int main( int argc, char* args[] ) {
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ,SDL_Rect*clip=NULL);
SDL_Init( SDL_INIT_VIDEO);
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format,255,255,255));
SDL_WM_SetCaption( "Hello World", NULL );
clip[ 0 ].x = 0;
clip[ 0 ].y = 0;
clip[ 0 ].w = SHEET_WIDTH/2;
clip[ 0 ].h = SHEET_HEIGHT/2;
//On coupe la partie en haut à droite (second sprite)
clip[ 1 ].x = SHEET_WIDTH/2;
clip[ 1 ].y = 0;
clip[ 1 ].w = SHEET_WIDTH/2;
clip[ 1 ].h = SHEET_HEIGHT/2;
//On coupe la partie en bas à gauche (troisième sprite)
clip[ 2 ].x = 0;
clip[ 2 ].y = SHEET_HEIGHT/2;
clip[ 2 ].w = SHEET_WIDTH/2;
clip[ 2 ].h = SHEET_HEIGHT/2;
//On coupe la partie en bas à droite (quatrième sprite)
clip[ 3 ].x = SHEET_WIDTH/2;
clip[ 3 ].y = SHEET_HEIGHT/2;
clip[ 3 ].w = SHEET_WIDTH/2;
clip[ 3 ].h = SHEET_HEIGHT/2;
apply_surface( 0, 0, faces, screen, &clip[ 0 ] );
apply_surface( SCREEN_WIDTH-(SHEET_WIDTH/2), 0, faces, screen, &clip[ 1 ] );
apply_surface( 0, SCREEN_HEIGHT-(SHEET_HEIGHT/2), faces, screen, &clip[ 2 ] );
apply_surface( SCREEN_WIDTH-(SHEET_WIDTH/2), SCREEN_HEIGHT-(SHEET_HEIGHT/2), faces, screen, &clip[ 3 ] );
SDL_Flip(screen);
SDL_Delay(3000);
SDL_Quit();
return EXIT_SUCCESS;
}
Configuration: Windows Vista Internet Explorer 7.0