Hello,
I don’t understand PITCH.
1) The pitch in SDL is the length of a surface scanline in bytes, since the
code assumes 4 bytes per int, it divides by 4 to get the number of integers
per scanline.
- But even in DirectX there is pitch (as in lots of books). And it is
larged used.
it divides by 4 to get the number of integers per scanline
Example: resolution is 800x600, 32-bit color and the pitch is exactly
3.200(800 x 4 bytes). Dividing by four, I get 800 again. So, if I want
the pixel
(1,2) I will have to do:
offset = 2 * (pitch / 4) + 1;
this means that offset = 1601; what is very confusing.
- This means that “offset” is an integer number to a pixel?
- But if the integers aren’t 4 bytes, imagine 2 bytes or even 8 bytes?
- How does the offset would be correct to the position?
- I am still very lost with this thing and unfortunately I havent found any
good article / tutorial / chapter that explains this. - Does you know where find this / which book? I really want to understand
this principles, and if there is a good book on it, would be great. - I “googled” and “wikipeded” and haven’t found a good material about this
subject. All the information goes straight to the code and doesn’t say what
it means or why. =(
A) I found another way of pitching:
http://www3.telus.net/alexander_russell/course_dx/chapter_2_dx.htm
But it stills unclear. It uses another way:
offset= (xpixelWidth) + (ysurface.lPitch);
Now it doesn’t divides Y, it multiplies X. More confusing.
B) Gamedev’s dictionary says: “The width of a drawable surface multiplied
by the number of bytes per pixel. For instance an 800x600 screen at 16-bit
color would have a pitch of 1600.”.
If pitch is always divided by the number of the bytes, I will be always the
same as width. So, why use pitch? I just can use the width, no? Even if it
is 8, 16 or 32 bit color, because there is always a division to these number
of bytes, so on calculating offset, pitch = width.
C) This Mailing list: 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).
The same as B above.
Any help would be great.
Thanks,
Alfred R. Baudisch