I have just downloaded the newest version of gimp, It alows you to save an
image as c-source code it gives bits per pixel, height, width, and of
course the pixels. I have included a sample file the image is 40x40 and is
a BMP in c-source code. Can you possibly give me a hint as how to use this
source code with SDL to display this image? Please see the attached source
file.
That is very cool. I didn’t know the GIMP could do that.
Here is code to view those images from within SDL.
-Sam Lantinga (slouken at devolution.com)
Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec
-------------- next part --------------
#include <stdio.h>
#include “SDL.h”
/* Include the GIMP created image */
#include “gimp_image.c”
main()
{
SDL_Surface *screen, *image;
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(gimp_image.width, gimp_image.height, 0, 0);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set video mode: %s\n",SDL_GetError());
exit(1);
}
/* A sneaky way of getting our image in a format SDL can use */
switch (gimp_image.bytes_per_pixel) {
case 3:
/* 24-bit RGB */
image = SDL_AllocSurface(SDL_SWSURFACE, 0, 0, 24, 0, 0, 0, 0);
break;
case 4:
/* 32-bit RGBA */
image = SDL_AllocSurface(SDL_SWSURFACE, 0, 0, 32,
0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
break;
default:
/* Um, guess. :) */
image = SDL_AllocSurface(SDL_SWSURFACE, 0, 0,
gimp_image.bytes_per_pixel*8, 0, 0, 0, 0);
break;
}
if ( image == NULL ) {
fprintf(stderr, "Couldn't create image: %s\n", SDL_GetError());
exit(1);
}
image->w = gimp_image.width;
image->h = gimp_image.height;
image->pitch = gimp_image.width * gimp_image.bytes_per_pixel;
image->pixels = (void *)gimp_image.pixel_data;
/* Show the image */
SDL_BlitSurface(image, NULL, screen, NULL);
SDL_UpdateRect(screen, 0, 0, 0, 0);
/* Wait for a keystroke or quit request */
while ( ! SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT,
SDL_KEYDOWNMASK|SDL_QUITMASK) ) {
SDL_Delay(100);
SDL_PumpEvents();
}
/* Free the gimp image
- be sure to set pixels NULL so SDL doesn't free them!
*/
image->pixels = NULL;
SDL_FreeSurface(image);
/* We're outta here! */
exit(0);
}