Hi guy,
I don’t know if you remember my problem with the copy of surface.
Anyway, I have resolved the problem but now I have another one.
At the end of program I copy the tiles into a new bitmap, this’s
completely blank, but the dimension of image is right.
Why?
Tnx at all
PS
Following you can find the unfinished work
int main ( int argc, char* argv[] )
{
SDL_Surface bmp, **a_tiles, finalbmp;
SDL_Rect src, dst;
Uint32 rmask, gmask, bmask, amask;
Uint32 a_map, n_square;
Uint8 r[3232], g[3232], b[3232], a[3232], R[3232], G[3232],
B[3232], A[32*32];
int img_w, img_h ,n_tile, x, y, i;
//////////////////////////////////////////////////////////////////////
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
//////////////////////////////////////////////////////////////////////
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, “Impossibile abilitare le SDL: %s.\n”, SDL_GetError());
return(1);
}
bmp = SDL_LoadBMP(“penguin.bmp”);
if ( bmp == NULL )
{
fprintf(stderr, “Impossibile caricare l’immagine: penguin.bmp.\n”);
return(1);
}
img_w = bmp->w / 32;
img_h = bmp->h / 32;
n_square = img_w * img_h;
a_tiles = calloc( n_square, sizeof(SDL_Surface*) );
a_map = calloc( n_square, sizeof(Uint32) );
src.w = 32;
src.h = 32;
dst.w = 32;
dst.h = 32;
dst.x = 0;
dst.y = 0;
for ( x = 0, n_tile = 0; x < img_w; x++, n_tile++ )
{
for ( y = 0; y < img_h; y++ )
{
src.x = x * 32;
src.y = y * 32;
a_tiles[n_tile] = SDL_CreateRGBSurface(SDL_HWSURFACE, 32, 32, 32,
rmask, gmask, bmask, amask);
if ( a_tiles[n_tile] == NULL )
{
fprintf(stderr, "Impossibile creare la surface: %s.\n",
SDL_GetError());
return(1);
}
SDL_BlitSurface(bmp, &src, a_tiles[n_tile], &dst);
/*
*/
}
}
finalbmp = SDL_CreateRGBSurface(SDL_HWSURFACE, 32, 32*n_tile, 32, rmask,
gmask, bmask, amask);
src.x = 0;
src.y = 0;
for (i = 0; i < n_tile; i++)
{
dst.y = i * 32;
SDL_BlitSurface (a_tiles[i], &src, finalbmp, &dst);
}
SDL_SaveBMP(finalbmp, “prova.bmp”);
SDL_FreeSurface(bmp);
SDL_FreeSurface(finalbmp);
free(a_map);
free(a_tiles);
return(0);
}