SDL_CreateRGBSurfaceFrom problem!

Please, can someone explain me where is the problem in my tiny piece of
code?? I really think it has to do with how I use the
SDL_CreateRGBSurfaceFrom function…

Here is the code:------------------------------------------------

#include
#include
#include “SDL.h”
#include "SDL_timer.h"
using namespace std;

void CatchError(void)
{
cout << SDL_GetError(); exit(1);
}

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

SDL_Surface *screen, *image;
SDL_Rect dstrect;
char *buffer;
char *rawbuffer;

//-------ALL-THE-FILE-IN-MY-RAWBUFFER-------
long size;
ifstream infile(“imagetoload.raw”, ios::in|ios::binary|ios::ate);
size = infile.tellg();
infile.seekg(0, ios::beg);
rawbuffer = new char[size];
infile.read(rawbuffer, size);
infile.close();
//-------------------------

SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);

SDL_Color colors[256];
int i;

for(i=0;i<256;i++)
{
colors[i].r=i;
colors[i].g=i;
colors[i].b=i;
}

//------------------------------------------------------------------
screen = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE|SDL_FULLSCREEN);
SDL_SetPalette(screen, SDL_PHYSPAL, colors, 0, 256);
buffer = (char *)screen->pixels;
image = SDL_CreateRGBSurfaceFrom(rawbuffer, 320, 240, 8, 0, 0, 0, 0, 0);
//------------------------------------------------------------------

/* Blit the image to the center of the screen */
dstrect.x = (screen->w-image->w)/2;
dstrect.y = (screen->h-image->h)/2;
dstrect.w = image->w;
dstrect.h = image->h;

if ( SDL_BlitSurface(image, NULL, screen, &dstrect) < 0 )
{
SDL_FreeSurface(image);
CatchError();
}

SDL_FreeSurface(image);

/* Update the screen */
SDL_UpdateRects(screen, 1, &dstrect);

/* Wait 5 seconds */
SDL_Delay(5000);

delete[] rawbuffer;
return 0;
}


Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Please, can someone explain me where is the problem in my tiny piece of
code?? I really think it has to do with how I use the
SDL_CreateRGBSurfaceFrom function…

image = SDL_CreateRGBSurfaceFrom(rawbuffer, 320, 240, 8, 0, 0, 0, 0, 0);

You have ignored the pitch parameter. Basically the pitch is the number
of bytes from the beginning of one scanline to the beginning of the next
scanline. Usually this is equal to width*bytes-per-pixel, but there are
situations where images are not in contiguous blocks where that isn’t the
case.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software