Can anyone please tell me what's wrong with this code?

Hello everyone!
OK, here’s the 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;

}
=================

The blit isn’t working… Here’s the declaration of both surfaces
(they’re not on the same func):

==================
this->vehicles[0].layers = IMG_Load("./Graphics/Vehicles/AZX-2400.PNG");
//192x192

this->vehicles[0].bmp = IMG_Load("./Graphics/Transparent 96x96
Image.png"); //96x96
=================

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!–
~ Leo, M@$73r L3170, Sulfurik, Kixdemp, L-28C… Whatever you wanna call me.

OK, after some fiddling around, I changed the initialization of ‘bmp’ to
this:

==================
this->vehicles[0].bmp = SDL_CreateRGBSurface(SDL_HWSURFACE, 96, 96, 32,
0, 0, 0, 0);
=
================

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:

==================
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;
}
=================

The blit isn’t working… Here’s the declaration of both surfaces
(they’re not on the same func):

==================
this->vehicles[0].layers = IMG_Load("./Graphics/Vehicles/AZX-2400.PNG");
//192x192

this->vehicles[0].bmp = IMG_Load("./Graphics/Transparent 96x96
Image.png"); //96x96
=================

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!


~ Leo, M@$73r L3170, Sulfurik, Kixdemp, L-28C… Whatever you wanna call me.

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:

==================
this->vehicles[0].bmp = SDL_CreateRGBSurface(SDL_HWSURFACE, 96, 96, 32,
0, 0, 0, 0);
=
================

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:

==================
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;

}
=================

The blit isn’t working… Here’s the declaration of both surfaces
(they’re not on the same func):

==================
this->vehicles[0].layers = IMG_Load("./Graphics/Vehicles/AZX-2400.PNG");
//192x192

this->vehicles[0].bmp = IMG_Load("./Graphics/Transparent 96x96
Image.png"); //96x96
=================

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++

Like this?

==================
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;
=
================

Yay, it works! :smiley: 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:

==================
this->vehicles[0].bmp = SDL_CreateRGBSurface(SDL_HWSURFACE, 96, 96, 32,
0, 0, 0, 0);
=
================

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:

==================
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;
}
=================

The blit isn’t working… Here’s the declaration of both surfaces
(they’re not on the same func):

==================
this->vehicles[0].layers = IMG_Load("./Graphics/Vehicles/AZX-2400.PNG");
//192x192

this->vehicles[0].bmp = IMG_Load("./Graphics/Transparent 96x96
Image.png"); //96x96
=================

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.