Create RGB Surface

I’m not quite sure how to implement the following function in SDL. I know
the data types that need to be passed, just not sure where they are to come
from. When I use the following, where I want to take part of the image in
"screen" and make it “s2”, I only get a black image. What am I doing wrong?----

SDL_LockSurface(screen);
s2 = SDL_CreateRGBSurface((Uint16)screen->pixels, 100, 100, 16,
screen->pitch,pixel>>screen->format->Rshift ,pixel>>screen->format->Gshift,
pixel>>screen->format->Rshift);
SDL_UnlockSurface(screen);


thanx!


Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

I’m not quite sure how to implement the following function in SDL. I know
the data types that need to be passed, just not sure where they are to come
from. When I use the following, where I want to take part of the image in
"screen" and make it “s2”, I only get a black image. What am I doing wrong?


SDL_LockSurface(screen);
s2 = SDL_CreateRGBSurface((Uint16)screen->pixels, 100, 100, 16,
screen->pitch,pixel>>screen->format->Rshift ,pixel>>screen->format->Gshift,
pixel>>screen->format->Rshift);
SDL_UnlockSurface(screen);

This is a bad way to copy a SDL_surface.
You should copy the surface with an apropriate function:

SDL_BlitSurface(screen, cuttingRect, s2, pastingRect);

The function that you are using is used to create a empthy SDL_surface.
You should call it to create you s2 surface:

SDL_PixelFormat* pxlformat;
w=16;
h=16;
pxlformat=screen->format;
s2 =SDL_CreateRGBSurface(SDL_SRCALPHA|SDL_SRCCOLORKEY|SDL_HWSURFACE,
w,
h,
pxlformat->BitsPerPixel,
pxlformat->Rmask,
pxlformat->Gmask,
pxlformat->Bmask,
pxlformat->Amask);

Luc-Olivier

“Luc-Olivier de Charri?re” <Luc-Olivier.deCharriere at epfl.ch> wrote in
message news:39A19413.6EACE055 at epfl.ch

This is a bad way to copy a SDL_surface.
You should copy the surface with an apropriate function:

SDL_BlitSurface(screen, cuttingRect, s2, pastingRect);

Won’t work with color-keys or alpha. SDL_DisplayFormat fixes this by
temporarily turning off color-keys and alpha. Note that this is ugly and
doesn’t work for per-pixel alpha.

There should be a special function for this in SDL.–
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

“Luc-Olivier de Charri?re” <Luc-Olivier.deCharriere at epfl.ch> wrote in
message news:39A19413.6EACE055 at epfl.ch

This is a bad way to copy a SDL_surface.
You should copy the surface with an apropriate function:

SDL_BlitSurface(screen, cuttingRect, s2, pastingRect);

Won’t work with color-keys or alpha. SDL_DisplayFormat fixes this by
temporarily turning off color-keys and alpha. Note that this is ugly and
doesn’t work for per-pixel alpha.

There should be a special function for this in SDL.

This should be fixed as of SDL 1.1.5 - Yorick is working on the code now. :slight_smile:

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

SDL_BlitSurface(screen, cuttingRect, s2, pastingRect);

Won’t work with color-keys or alpha. SDL_DisplayFormat fixes this by
temporarily turning off color-keys and alpha. Note that this is ugly and
doesn’t work for per-pixel alpha.

There should be a special function for this in SDL.

This should be fixed as of SDL 1.1.5 - Yorick is working on the code now. :slight_smile:

cough cough well of course, but /me got /meself a non-SDL-related
job right now so I’m giving it a little time now and then.

SDL_DisplayFormat() will work as before; SDL_DisplayFormatAlpha() is a
new function that preserves the alpha channel. Most of the code is in
place, but the devil is in the details… I’ll post separately about this
later, have work to do now