Original Post
I'm trying to write a program that draws a Pole Position-like landscape using a bitmap. The problem is I'm getting a Segmentation Fault error when I run the program. I've narrowed down the problem to to this chunk of code: I copied some of it from the SDL documentation but I did modify this line. pixel=*((Uint32*)map->pixels + y*map->pitch/4 + x); which used to be pixel=*((Uint32*)map->pixels); in an attempt to read the pixel data from a single pixel in the bitmap but I don't think I did that right. If this is wrong, does somebody know the right way to read data from a single pixel in a bitmap?
if(!(TexelX < 0 || TexelX > map->w) && !(TexelY < 0 || TexelY > map->h))
{
fmt=map->format;
SDL_LockSurface(map);
pixel=*((Uint32*)map->pixels + y*map->pitch/4 + x);
SDL_UnlockSurface(map);
/* Get Red component */
temp=pixel&fmt->Rmask; /* Isolate red component */
temp=temp>>fmt->Rshift;/* Shift it down to 8-bit */
temp=temp<<fmt->Rloss; /* Expand to a full 8-bit number */
red=(Uint8)temp;
/* Get Green component */
temp=pixel&fmt->Gmask; /* Isolate green component */
temp=temp>>fmt->Gshift;/* Shift it down to 8-bit */
temp=temp<<fmt->Gloss; /* Expand to a full 8-bit number */
green=(Uint8)temp;
/* Get Blue component */
temp=pixel&fmt->Bmask; /* Isolate blue component */
temp=temp>>fmt->Bshift;/* Shift it down to 8-bit */
temp=temp<<fmt->Bloss; /* Expand to a full 8-bit number */
blue=(Uint8)temp;
SDL_LockSurface(screen);
DrawPixel(screen, x, y, red, green, blue);
SDL_UnlockSurface(screen);
}