Color and surfaces problems (forever newbie)

I should be stupid !!!

I have lost four hours trying to make me an idea on how color is managed
but …

OK, here is the problem:

I’m programming a C++ program and I use 16 bits in my adaptor with a
1280x1024 (TNT2)
and I init SDL, until here works ok.

  • I start the video mode 800x600x16

    screen = SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE); // I have 16
    bits per pixel
    or
    screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE);

and whatever I do, I get:

cout << "\n Bytes per pixel: " << screen->format->BytesPerPixel <<

fflush;

\n Bytes per pixel : 1

  • Oh, one byte per pixel so 256 colors so framebuffer is 8006008 long,
    but not…

When I fill the screen with a color (say 123) I get only mid screen
filled:

for(i=0;i<800*600;i++){
*((char *)screen->pixels+i)=100;

}

SDL_Flip(screen);

// Just until the middle of the window.

I supposed that the other half is alpha chanel, but why?

And this problem happen to:

nueva_sur = SDL_CreateRGBSurface
(SDL_SWSURFACE,800,600,16,0xff0000,0xff00,0xff,0);

too, only reports 1 bytes per pixel.

Someone can help me? I’m getting crazy…

Thanks

[OFF-TOPIC]

I’m using ImageMagick too and Gimp to make the graphics… (png is the
graphic format used)

First, how can I force Gimp to save pictures on 16 bit per pixel, should
I force it?.

Second, My program says that my picture has 800x600x8 ( 8 !!! bits) (
really is the ImageMagick lib who(?) says that )
Then, should I do as follows:

        Read the color, look in the palette the RGB components and

put those on my SDL_surface
instead of the pic colors.
( I don’t know if I can explain what I’m trying to say)
Read another and make the same until pixels ends

Thirth, Where can I find info about what is alpha chanels exactly and
how should I use it.

Fourth, Where get the people info about unix c/c++ functions on console,
io calls, and all other stuff,
because I look includes and I try to make me an idea on how
they works.
In DOS I used to work with Borland C, Watcom C but they come
with help on their functions,
how works in UNIX?
All the libs don’t explain their structures and functions, so I
am lost and don’t know where to look.
Does the UNIX programmers look into the source code to use a
library? ( If so, then I have so much to learn)

Thanks, people!!!

cout << "\n Bytes per pixel: " << screen->format->BytesPerPixel <<

fflush;

\n Bytes per pixel : 1

  • Oh, one byte per pixel so 256 colors so framebuffer is 8006008 long,
    but not…

The print statement is misleading. The value is really 2 bytes per pixel:

Entrando en modo grafico… 173 screen = SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE);
(gdb)
175 cout << "Bytes per pixel: " << screen->format->BytesPerPixel << endl;
(gdb) n
Bytes per pixel:
179 if ( screen == NULL ) {
(gdb) print screen->format->BytesPerPixel
$1 = 2 ‘\002’
(gdb) print *screen->format
$2 = {palette = 0x0, BitsPerPixel = 16 ‘\020’, BytesPerPixel = 2 ‘\002’,
Rloss = 3 ‘\003’, Gloss = 2 ‘\002’, Bloss = 3 ‘\003’, Aloss = 8 ‘\b’,
Rshift = 11 ‘\013’, Gshift = 5 ‘\005’, Bshift = 0 ‘\000’, Ashift = 0 ‘\000’,
Rmask = 63488, Gmask = 2016, Bmask = 31, Amask = 0, colorkey = 0,
alpha = 0 ‘\000’}

-Sam Lantinga				(slouken at devolution.com)

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