Blit de surface avec SDL [problème d'affichage]

cyberlewis Messages postés 50 Date d'inscription samedi 4 janvier 2003 Statut Membre Dernière intervention 20 février 2005 - 22 déc. 2003 à 02:33
gros chichi Messages postés 1 Date d'inscription mercredi 12 mai 2004 Statut Membre Dernière intervention 12 mai 2004 - 12 mai 2004 à 01:16
Bonjour,

Voilà j'ai fait un code (jeu vidéo SDL),
j'arrive à afficher la partie que je veux (tiles, tiles.bmp) dans screen qui est affichée à l'écran, pas de problème pour ça ...

Mais je souhaites l'afficher dans la surface map :

DrawIMG(tiles, map, 0, 0, 1, 1, tilesWidth, tilesHeight);

Mais ensuite il faut que je blitte une partie de cette surface (c'est à cause d'un scrolling pour jeu 3d iso) vers screen qui sera ensuite affichée :

DrawIMG(screen, map, 0, 0, 0, 0, 640, 480);

SDL_Flip(screen);

Mais la RIEN ne s'affiche ...

Pouvez-vous m'aider à savoir pouquoi svp ???

PS : J'ai aussi essayé avec :

BlitSurface(map, NULL, screen, NULL);

Mais rien n' fait ...

CODE SOURCE :

#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>

SDL_Surface *tiles;
SDL_Surface *map;
SDL_Surface *screen;

int tilesWidth = 64;
int tilesHeight = 32;

int quitProgram = 0;
int i, x, y, z = 0;

int Map[10][10] = {
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,
0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01};

int InitImages()
{
tiles = SDL_LoadBMP("tiles.bmp");
SDL_SetColorKey(tiles, SDL_SRCCOLORKEY, 0xff00ff);

return 0;
}

void DrawIMG(SDL_Surface *src, SDL_Surface *dest, int x, int y)
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_BlitSurface(src, NULL, dest, &rect);
}

void DrawIMG(SDL_Surface *src, SDL_Surface *dest, int x, int y, int x2, int y2, int w, int h)
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_Rect rect2;
rect2.x = x2;
rect2.y = y2;
rect2.w = w;
rect2.h = h;
SDL_BlitSurface(src, &rect2, dest, &rect);
}

void DrawLevel()
{

DrawIMG(tiles, map, 0, 0, 1, 1, tilesWidth, tilesHeight);

SDL_Rect rect;
rect.x = 10;
rect.y = 10;

DrawIMG(screen, map, 0, 0, 0, 0, 640, 480);

SDL_Flip(screen);

}

int main(int argc, char *argv[])
{
Uint8* keys;

if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
printf("Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

screen=SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( screen == NULL )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}

InitImages();

while(quitProgram == 0)
{
SDL_Event event;

while ( SDL_PollEvent(&event) )
{ if ( event.type SDL_QUIT ) { quitProgram 1; }

if ( event.type == SDL_KEYDOWN )
{ if ( event.key.keysym.sym SDLK_ESCAPE ) { quitProgram 1; }
}
}
keys = SDL_GetKeyState(NULL);
// if ( keys[SDLK_UP] ) { ypos -= 1; }
// if ( keys[SDLK_DOWN] ) { ypos += 1; }
// if ( keys[SDLK_LEFT] ) { xpos -= 1; }
// if ( keys[SDLK_RIGHT] ) { xpos += 1; }

DrawLevel();
}

return 0;
}

Merci d'avance ...

http://www.realtuning.online.fr

1 réponse

gros chichi Messages postés 1 Date d'inscription mercredi 12 mai 2004 Statut Membre Dernière intervention 12 mai 2004
12 mai 2004 à 01:16
Salut

je pense que c'est qu'une invertion source destination

essaye :

DrawIMG(map, screen, 0, 0, 0, 0, 640, 480);
SDL_Flip(screen);

a+
0
Rejoignez-nous