[SDL] Doubts about screen Pitch and things related to it.

Gabriel Gambetta mystml at adinet.com.uy
Mon Jun 19 07:38:37 PDT 2006


        El lun, 19-06-2006 a las 10:47 -0300, Alfred Reinold Baudisch
        escribió:
        Hello,
        I don't understand PITCH.

You have a 2D dataset (the screen or window) which you want to represent
as a linear dataset (an array, given by a pointer).

The easiest way to arrange the screen into a linear array is to take all
the pixels of the first row, then all the pixels of the second row, and
so on. For a 6x3 screen like this one

000000
111111
222222

you get an array like this

000000111111222222

Row 0 starts at index 0, row 1 starts at index 6 (1*6), row 2 starts at
index 12 (2*6). 6 is the WIDTH of the surface.

However, assume that for some obscure, hardware-related issue, it's
better for the video card to have rows start at indexes which are
multiples of 8 instead of 6. So you take your 6x3 screen and waste some
bytes at the end of each row to make each row 8 spaces wide, like this :

000000xx
111111xx
222222xx

When you put that in a linear array, you now get

000000xx111111xx222222xx

Row 0 starts at index 0, row 1 starts at index 8 (1*8), row 2 starts at
index 16 (2*8) and the video card is happy. The WIDTH of the surface is
still 6, but the PITCH is 8 - the "distance" between consecutive rows,
which as you see not always matches the width of a row.

Hope this helps!

--Gabriel



________________________________________________________________________
Gabriel Gambetta
Mystery Studio - http://www.mysterystudio.com
Gabriel on Graphics - http://gabrielongraphics.blogspot.com





More information about the SDL mailing list