[SDL] programming linux games - pitch vs w

John R. Hall overcode at overcode.net
Thu Nov 20 13:36:00 PST 2003


Neil Brown wrote:

>
>>    screen = SDL_SetVideoMode(256, 256, 16, 0);
>>
>>          offset = screen->pitch/2 * y + x;
>>
>> what is that "/2" doing in there?  if pitch is really the width of the
>
>
> Code snipped in places above, but basically pitch is measured in 
> bytes, width is measured in pixels.  Because he wants the offset in 
> pixels (which are 2 bytes, as he has set 16 bit colour) he divides it 
> by 2 (e.g. 32 bytes = 16 pixels).  I'm sure he probably could have 
> annotated in better though...

That's correct. For the sake of clarity, I should have divided by 
screen->format->BytesPerPixel.

-John






More information about the SDL mailing list