SDL_CreateRGBSurfaceFrom example needed

Hi,
I’ve been trying to use SDL_CreateRGBSurfaceFrom in 8 bit mode and can’t get
it to work. My code is something like this:

SDL_Rect src, dest;
SDL_Surface *screen;
SDL_Surface *image;
char pix[0x100];

// set video mode, etc…

// set some colors
for(i = 0; i < 0x100; i++) {
pix[i] = (char)i;
}

// create a surface
image = SDL_CreateRGBSurfaceFrom(pix, 16, 16, 8, 16 * 1, 0, 0, 0, 0);

// blit to screen
src.x = 0;
src.y = 0;
src.w = image->w;
src.h = image->h;
dest.x = 0;
dest.y = 0;
dest.w = image->w;
dest.h = image->h;

SDL_BlitSurface(image, &src, screen, &dest);
SDL_UpdateRect(screen, 0, 0, 0, 0);

Nothing is displayed on the screen. Am I missing something vital?
Thanks!
–Gabor.

Gabor Torok <gabor.torok at transactplus.com> wrote:

I’ve been trying to use SDL_CreateRGBSurfaceFrom in 8 bit mode and can’t get
it to work.

you forgot to set a palette for the surface (use SDL_SetColors()); the
default is all black

(I’ll add a note to the docs about this)