Pixel Format of Main Surface

Okay, I fought with SDL all day today, and I cannot figure out
how to configure the main surface(SDL_Surface returned from
SDL_SetVideoMode). I spent most of my afternoon looking over the
documentation on www.libsdl.org and all of the examples in the
documentation are 8bit. I’m trying to get a 16bit surface with a
sane pixel format. I would LIKE to get 5/5/5/1(that’s five bits of
red, five bits of green, five bits of blue and 1 bit of alpha)
since that’s the format of the image I’m reading in. 5/6/5/0
would be fine if that’s not possible. Looking in the PixelFormat
structure, I found screen->format->[R,G,B,A]loss which look like
from their values(though there are no comments in the source to
say) that they are the bits per pixel I’m looking for. The
default surface for a 16bit mode seems to be 3/2/3/8 which looks
totally biased towards 8bit… All I would like is to know what
the magic is to pixel formats. SDL looks like a great library
and I’ve had a lot of fun playing with it, but this has been
pretty frustrating.

Ted

Well, I figured it all out, though I don’t know intuitive it is
to people just starting out with SDL. It threw me for a loop
even after studying the documentation. Sam Lantinga ultimately
helped by suggesting the SDL Documentation Project, which there
isn’t any link to from www.libsdl.org. Eventually I found that
the masks you provide to SDL_CreateRGBSurface() was what I didn’t
understand correctly. Making that assumption about [R,G,B,A]loss
didn’t help me any either. As soon as I get done with this
project I’m working on, I’ll try to write a doc that explains how
pixel formats/masks all work together. It certainly would have
helped me.

Ted

Well, I figured it all out, though I don’t know intuitive it is
to people just starting out with SDL. It threw me for a loop
even after studying the documentation. Sam Lantinga ultimately
helped by suggesting the SDL Documentation Project, which there
isn’t any link to from www.libsdl.org. Eventually I found that
the masks you provide to SDL_CreateRGBSurface() was what I didn’t
understand correctly. Making that assumption about [R,G,B,A]loss
didn’t help me any either. As soon as I get done with this
project I’m working on, I’ll try to write a doc that explains how
pixel formats/masks all work together. It certainly would have
helped me.

I’m glad you figured it out, and I’m looking forward to adding that
documentation to the documentation project.

Thanks! :slight_smile:

-Sam Lantinga, Lead Programmer, Loki Entertainment Software