[SDL] [Update] Can anyone please tell me what's wrong with this code?
L-28C
leo28c at gmail.com
Wed Aug 9 16:42:07 PDT 2006
Like this?
=<Code>=================
if (SDL_SetColorKey(this->vehicles[0].bmp, SDL_SRCCOLORKEY, 255) == -1)
return false;
if (SDL_SetAlpha(this->vehicles[0].bmp, SDL_SRCALPHA, 128) == -1)
return false;
=</Code>================
Yay, it works! :-D But it makes the whole image transparent... I just
want the black background to get out, so must I change the 3rd param on
SDL_SetColorKey (255) to something that represents black? What is
black? Thanks very much!
Laurent Carlier wrote:
> Le mercredi 9 août 2006 06:59, L-28C a écrit :
>> OK, after some fiddling around, I changed the initialization of 'bmp' to
>> this:
>>
>> =<Code>=================
>> this->vehicles[0].bmp = SDL_CreateRGBSurface(SDL_HWSURFACE, 96, 96, 32,
>> 0, 0, 0, 0);
>> =</Code>================
>>
>> It works! But then I get a black background (initial reason to use the
>> transparent image file)... How can I fix this? Thanks!
>>
>> L-28C wrote:
>>> Hello everyone!
>>> OK, here's the code:
>>>
>>> =<Code>=================
>>> bool Game::t_DrawVehicle()
>>> {
>>> SDL_Rect src, dest;
>>> src.w = 96;
>>> src.h = 96;
>>>
>>> dest.w = 96;
>>> dest.h = 96;
>>> dest.x = 0;
>>> dest.y = 0;
>>>
>>> // Layer 1
>>> src.x = 0;
>>> src.y = 0;
>>> SDL_BlitSurface(this->vehicles[0].layers, &src, this->vehicles[0].bmp,
>>> &dest);
>>>
>>> SDL_UpdateRect(this->vehicles[0].bmp, 0, 0, 96, 96);
>>>
>>> return true;
>>> }
>>> =</Code>================
>>>
>>> The blit isn't working... Here's the declaration of both surfaces
>>> (they're not on the same func):
>>>
>>> =<Code>=================
>>> this->vehicles[0].layers = IMG_Load("./Graphics/Vehicles/AZX-2400.PNG");
>>> //192x192
>>>
>>> this->vehicles[0].bmp = IMG_Load("./Graphics/Transparent 96x96
>>> Image.png"); //96x96
>>> =</Code>================
>>>
>>> The 'layers' one works, because I can display it to the screen, but
>>> 'bmp' just displays the original image it had... ("Transparent 96x96
>>> Image.png", just a transparent box with a black pixel in the middle...)
>>>
>>> Does anyone know why it's happening? Thanks very much!
>
> Try to enable alpha with SDL_SetAlpha
>
> ++
--
~ Leo, M@$73r L3170, Sulfurik, Kixdemp, L-28C... Whatever you wanna call me.
More information about the SDL
mailing list