can someone explain this? SDL tutorial...

Started by
-1 comments, last by DyDx 21 years, 5 months ago
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!

This topic is closed to new replies.

Advertisement