1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
{
Uint32 color;
unsigned char *buf = terraintxt->pixels;
/* Creer une surface pour la texture, pour la passer a OpenGL */
SDL_Surface *ttxt = SDL_CreateRGBSurface(SDL_HWSURFACE, 1024, 1024, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000FF,
0x0000FF00,
0x00FF0000,
0xFF000000
#else
0xFF000000,
0x00FF0000,
0x0000FF00,
0x000000FF
#endif
);
for(i=0;i<1024;i++) {
for(j=0;j<1024;j++) {
int tmp = 3*1024*i + 3*j;
color = SDL_MapRGB(ttxt->format, buf[tmp], buf[tmp+1], buf[tmp+2]);
SetPixel(ttxt, i, j, color);
}
}
if(SDL_SaveBMP(ttxt, "txtmap.bmp") != 0) {
fprintf(stderr, "Problem saving texture\n");
exit(EXIT_FAILURE);
}
SDL_FreeSurface(ttxt);
} |
Partager