Surface pitch

Le Sat, 6 Jun 2009 10:44:30 +0200
Hubert Maraszek a ?crit:

My app creates an 8-bit surface. When surface->pitch is different than
surface->w in bytes?

It is different if SDL can not create a video mode for the width you
asked for (for example if the underlying hardware does nto support it).

I had that problem before - I was creating a Meritous port for Sony PSP, for
which SDL is fully ported, even with multitasking. The game had a very
strange way to show strings on a surface: it creates a pointer to
screen->pixels (or however it’s called) and moves it to drawing position,
but instead of moving screen->pitch for each line, it moved screen->w bytes
down. When app was in resolution 640x480, this method was working, but when
I changed to 480x272 (PSP native resolution) the strings were all shattered.
I spent 2 days finding out what was wrong.

For example, if the target only provides a 640x480 resolution and you
want 480x272, SDL will give you 640 for pitch (for 8 bits/pixel), and
your 480x272 SDL_Surface screen in reality is only a part of the real
640x480 screen.

So, my question is: When surface->pitch is different than
surface->w*surface->format->BytesPerPixel (it’s multiplying here)? And when
it is different, what data are stored between lines?

When drawing, you should always use surface->pitch *
surface->format->BytesPerPixel.–
Patrice Mandin
WWW: http://pmandin.atari.org/
Programmeur Linux, Atari
Sp?cialit?: D?veloppement, jeux