Surface Pitch inconsistencies?

OK I’ll admit this is probably a silly question and results from
the fact that I really don’t understand what pitch is completely
but this is just confusing the heck out of me. I am writing a
game that can run in both windowed and fullscreen mode at
640x480x16. Now when I am in a window My Resolution is 640x480
and my bytes per pixel is 2 making my pitch 1280 (which makes
since since I thought that pitch was width of the screen in
bytes which is 640 pixels times 2 bytes per pixel.) However,
when I run in fullscreen mode at 640x480 My bytes per pixel is
still 2 but my pitch seems to magically be 2560. (This makes
absolutely no sense to me since I wouldn’t expect the pitch to
change. Shouldn’t it still be 6402? Why is it all of the sudden
640
4?

Oh, BTW, X makes use of this feature of video cards: try setting a
larger virtual desktop than your video resolution, and you’ll have
high speed panning of the display of the larger resolution you
specified (assuming you have enough video ram for this).

 Warren

______________________________ Reply Separator _________________________________Subject: Re: [SDL] Surface Pitch inconsistencies?
Author: at internet-mail
Date: 8/16/99 5:53 PM

 Well, I may be wrong, but my guess is, pitch is referring to the video 
 RAM allocated to a scanline by your video card.  So when running full 
 screen, the video card has enough ram you could be running at 
 1280x1024, so it allocates that much for each line.  This way, the 
 address of each line doesn't change even when the resolution does, 
 which makes for more efficient card design.  Also, you can easily do a 
 side scroller this way, by changing the starting address of the screen 
 in the video buffer (though only if you're programming the card 
 directly, say, in DOS).
 
 However, when running windowed, a larger pitch than the bytes per used 
 by your window per scanline can't be used by you anyway, as you don't 
 have permission to write outside your window, so SDL sets the pitch to 
 the width of the window in pixels * number of bytes per pixel.
 
 Warren

______________________________ Reply Separator _________________________________
Subject: [SDL] Surface Pitch inconsistencies?
Author: at internet-mail
Date: 8/16/99 5:39 PM

    OK I'll admit this is probably a silly question and results from 
    the fact that I really don't understand what pitch is completely 
    but this is just confusing the heck out of me. I am writing a 
    game that can run in both windowed and fullscreen mode at 
    640x480x16. Now when I am in a window My Resolution is 640x480 
    and my bytes per pixel is 2 making my pitch 1280 (which makes 
    since since I thought that pitch was width of the screen in bytes 
    which is 640 pixels times 2 bytes per pixel.) However, when I run 
    in fullscreen mode at 640x480 My bytes per pixel is still 2 but 
    my pitch seems to magically be 2560. (This makes absolutely no 
    sense to me since I wouldn't expect the pitch to change. 
    Shouldn't it still be 640*2? Why is it all of the sudden 640*4?

Well, I may be wrong, but my guess is, pitch is referring to the video
RAM allocated to a scanline by your video card. So when running full
screen, the video card has enough ram you could be running at
1280x1024, so it allocates that much for each line. This way, the
address of each line doesn’t change even when the resolution does,
which makes for more efficient card design. Also, you can easily do a
side scroller this way, by changing the starting address of the screen
in the video buffer (though only if you’re programming the card
directly, say, in DOS).

 However, when running windowed, a larger pitch than the bytes per used 
 by your window per scanline can't be used by you anyway, as you don't 
 have permission to write outside your window, so SDL sets the pitch to 
 the width of the window in pixels * number of bytes per pixel.
 
 Warren

______________________________ Reply Separator _________________________________Subject: [SDL] Surface Pitch inconsistencies?
Author: at internet-mail
Date: 8/16/99 5:39 PM

    OK I'll admit this is probably a silly question and results from 
    the fact that I really don't understand what pitch is completely 
    but this is just confusing the heck out of me. I am writing a 
    game that can run in both windowed and fullscreen mode at 
    640x480x16. Now when I am in a window My Resolution is 640x480 
    and my bytes per pixel is 2 making my pitch 1280 (which makes 
    since since I thought that pitch was width of the screen in bytes 
    which is 640 pixels times 2 bytes per pixel.) However, when I run 
    in fullscreen mode at 640x480 My bytes per pixel is still 2 but 
    my pitch seems to magically be 2560. (This makes absolutely no 
    sense to me since I wouldn't expect the pitch to change. 
    Shouldn't it still be 640*2? Why is it all of the sudden 640*4?

OK I’ll admit this is probably a silly question and results from
the fact that I really don’t understand what pitch is completely
but this is just confusing the heck out of me. I am writing a
game that can run in both windowed and fullscreen mode at
640x480x16. Now when I am in a window My Resolution is 640x480
and my bytes per pixel is 2 making my pitch 1280 (which makes
since since I thought that pitch was width of the screen in
bytes which is 640 pixels times 2 bytes per pixel.) However,
when I run in fullscreen mode at 640x480 My bytes per pixel is
still 2 but my pitch seems to magically be 2560. (This makes
absolutely no sense to me since I wouldn’t expect the pitch to
change. Shouldn’t it still be 6402? Why is it all of the sudden
640
4?

Why do you care? Does the display work? That’s all that matters, isn’t it?

The mere existence of a pitch variable implies that the # of bytes between
successive rows is unpredictable. So, just use the pitch as intended, and
get on with your life :^).

-Dave

OK I’ll admit this is probably a silly question and results from
the fact that I really don’t understand what pitch is completely
but this is just confusing the heck out of me. I am writing a
game that can run in both windowed and fullscreen mode at
640x480x16. Now when I am in a window My Resolution is 640x480
and my bytes per pixel is 2 making my pitch 1280 (which makes
since since I thought that pitch was width of the screen in
bytes which is 640 pixels times 2 bytes per pixel.) However,
when I run in fullscreen mode at 640x480 My bytes per pixel is
still 2 but my pitch seems to magically be 2560. (This makes
absolutely no sense to me since I wouldn’t expect the pitch to
change. Shouldn’t it still be 6402? Why is it all of the sudden
640
4?

The video memory is actually wider than the resolution you have requested.
To get to the next visible scanline, you need to skip over quite a bit.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

OK I’ll admit this is probably a silly question and results from
the fact that I really don’t understand what pitch is completely
but this is just confusing the heck out of me. I am writing a
game that can run in both windowed and fullscreen mode at
640x480x16. Now when I am in a window My Resolution is 640x480
and my bytes per pixel is 2 making my pitch 1280 (which makes
since since I thought that pitch was width of the screen in
bytes which is 640 pixels times 2 bytes per pixel.) However,

No, it isn’t exactly the width of the screen in bytes. From reading the
SDL code (since the pitch entry doesn’t seem to be documented anywhere
else!), it seems to be the width of the screen in bytes rounded to the
closest multiple of four, at least this is the case when you have
offscreen surfaces or surfaces in windows. I once had a problem with
this when trying to directly access the pixels in a buffer.

when I run in fullscreen mode at 640x480 My bytes per pixel is
still 2 but my pitch seems to magically be 2560. (This makes
absolutely no sense to me since I wouldn’t expect the pitch to
change. Shouldn’t it still be 6402? Why is it all of the sudden
640
4?

This is probably because your full screen video mode uses interleaving
(another thing learned from reading the code). You might have two video
pages and the one your surface is mapped to uses the even addresses in
video memory. I suppose that a second page would start 640*2 bytes away
from the first, and also have a pitch of 2560, and so uses odd addreses.
Some video cards do that.On Mon, 16 Aug 1999 dtabuenc at cs.ucr.edu wrote:


| Rafael R. Sevilla @Rafael_R_Sevilla_94 |
| Instrumentation, Robotics, and Control Laboratory |

College of Engineering, University of the Philippines, Diliman