#### Archived

This topic is now archived and is closed to further replies.

# can someone explain this? SDL tutorial...

## Recommended Posts

Hey all, I''m reading "Linux Game Programming" (now available online for free in PDF and DVI formats), but am confused by something that the author fails to explain well (IMHO).
quote:
SDL often emulates nonstandard screen resolutions with higher resolutions, and the pitch member of the pixel format structure indicates the actual width of the framebuffer. You should always use pitch instead of w for calculating offsets into the pixels buffer or else your application might not work on some configurations
Then it goes on into an example... (this is just part of it)
/* We can now safely write to the video surface. We''ll draw a niec gradient pattern by varying our red and blue components along the X and Y axes. Notice the formula used to calculate the offset into the framebuffer for each pixel. (The pitch is the number of bytes per scanline in memory.) */
for(x = 0; x < 256; x++){
for(y = 0; y < 256; y++){
Uint16 pixel_color;
int offset;
pixel_color = CreateHicolorPixel(screen->format,x,0,y);
offset = (screen->pitch / 2 * y + x);
raw_pixels[offset] = pixel_color;

CreateHiColorPixel''s prototype is - Uint16 CreateHicolorPixel(SDL_PixelFormat *fmt, Uint8 red, Uint8 green, Uint8 blue) Could someone please explain this code? Specifically, the offset and pitch parts of it. The author of this book seems to assume more than he says he does... "Thanks!

• ### Forum Statistics

• Total Topics
628332
• Total Posts
2982120

• 22
• 9
• 9
• 13
• 11