[SDL] Surface Pitch inconsistencies?

Rafael R. Sevilla 94-22131 rsevilla at eee.upd.edu.ph
Tue Aug 17 13:27:37 PDT 1999


On Mon, 16 Aug 1999 dtabuenc at cs.ucr.edu wrote:

> 	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 640*2? 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.

------------------------------------------------------------------------
| Rafael R. Sevilla                            rsevilla at eee.upd.edu.ph |
|           Instrumentation, Robotics, and Control Laboratory          |
|    College of Engineering, University of the Philippines, Diliman    |
------------------------------------------------------------------------



More information about the SDL mailing list