Question about blitting

Hello everyone!
OK… I have a car, and I want to put windows on it. How do I make the
windows so that they are transparent, like, so I can see the driver? I
have the window on a PNG file, and I set up the transparency in
Photoshop, but it just shows up solid on SDL… How do I blit it
correctly? I have the following code:

===
// Create window surface
SDL_Surface *glass = SDL_CreateRGBSurface(SDL_HWSURFACE, 96, 96, 32, 0,
0, 0, 0);

// Blit the window from the PNG to the ‘glass’ surface
SDL_BlitSurface(this->vehicles[0].layers, &src, glass, &dest);

// Set 100 transparency
SDL_SetAlpha(glass, SDL_SRCALPHA, 100);

// Blit it to the car
SDL_BlitSurface(glass, &src, this->vehicles[0].bmp, &dest);

==

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

Hello everyone!
OK… I have a car, and I want to put windows on it. How do I make
the
windows so that they are transparent, like, so I can see the driver?
I
have the window on a PNG file, and I set up the transparency in
Photoshop, but it just shows up solid on SDL… How do I blit it
correctly? I have the following code:

===
// Create window surface
SDL_Surface *glass = SDL_CreateRGBSurface(SDL_HWSURFACE, 96, 96, 32,
0,
0, 0, 0);

// Blit the window from the PNG to the ‘glass’ surface
SDL_BlitSurface(this->vehicles[0].layers, &src, glass, &dest);

// Set 100 transparency
SDL_SetAlpha(glass, SDL_SRCALPHA, 100);

// Blit it to the car
SDL_BlitSurface(glass, &src, this->vehicles[0].bmp, &dest);

This will only blend the window onto the car. It will not affect the
alpha channel of the car, and thus, it cannot make the window on the
car transparent.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Saturday 12 August 2006 03:55, L-28C wrote:

Dang… How can I make it transparent then? Thanks!

David Olofson wrote:> On Saturday 12 August 2006 03:55, L-28C wrote:

Hello everyone!
OK… I have a car, and I want to put windows on it. How do I make
the
windows so that they are transparent, like, so I can see the driver?
I
have the window on a PNG file, and I set up the transparency in
Photoshop, but it just shows up solid on SDL… How do I blit it
correctly? I have the following code:

===
// Create window surface
SDL_Surface *glass = SDL_CreateRGBSurface(SDL_HWSURFACE, 96, 96, 32,
0,
0, 0, 0);

// Blit the window from the PNG to the ‘glass’ surface
SDL_BlitSurface(this->vehicles[0].layers, &src, glass, &dest);

// Set 100 transparency
SDL_SetAlpha(glass, SDL_SRCALPHA, 100);

// Blit it to the car
SDL_BlitSurface(glass, &src, this->vehicles[0].bmp, &dest);

This will only blend the window onto the car. It will not affect the
alpha channel of the car, and thus, it cannot make the window on the
car transparent.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


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

The usual way is to draw/render/whatever the artwork directly the way
it’s supposed to look, with transparency and all, and save it in a
format that supports alpha channels, like PNG.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Saturday 12 August 2006 23:55, L-28C wrote:

Dang… How can I make it transparent then? Thanks!

Goddammit… I thought I had already done that… :mad:
But thanks!

David Olofson wrote:> On Saturday 12 August 2006 23:55, L-28C wrote:

Dang… How can I make it transparent then? Thanks!

The usual way is to draw/render/whatever the artwork directly the way
it’s supposed to look, with transparency and all, and save it in a
format that supports alpha channels, like PNG.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


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

Well, it seemed like you were composing the car from multiple
images…? :slight_smile:

This is of course theoretically doable, but the SDL blitters cannot
combine source and destination alpha channels the way you need to do
this properly. (IIRC, you can have it overwrite the destination
alpha channel as if it were just anoter color channel, though. Might
cut it in some simple special cases…)

Anyway, what I was saying was, if you want a car with translucent
windows, draw the car like that, instead of adding the window at load
time.

Or, write custom blitter code to do the composing properly in real
time or at load time. No limits to what you can do that way - except
you can’t have it hardware accelerated (at least not through SDL),
and you have to do some serious optimizing to get to the performance
level of the SDL software blitters.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Sunday 13 August 2006 01:45, L-28C wrote:

Goddammit… I thought I had already done that… :mad:
But thanks!

David Olofson wrote:

Well, it seemed like you were composing the car from multiple
images…? :slight_smile:

I am… :stuck_out_tongue:

David Olofson wrote:

Anyway, what I was saying was, if you want a car with translucent
windows, draw the car like that, instead of adding the window at load
time.

Can’t do that - the player has to be seen inside…

But thanks!

David Olofson wrote:> On Sunday 13 August 2006 01:45, L-28C wrote:

Goddammit… I thought I had already done that… :mad:
But thanks!

Well, it seemed like you were composing the car from multiple
images…? :slight_smile:

This is of course theoretically doable, but the SDL blitters cannot
combine source and destination alpha channels the way you need to do
this properly. (IIRC, you can have it overwrite the destination
alpha channel as if it were just anoter color channel, though. Might
cut it in some simple special cases…)

Anyway, what I was saying was, if you want a car with translucent
windows, draw the car like that, instead of adding the window at load
time.

Or, write custom blitter code to do the composing properly in real
time or at load time. No limits to what you can do that way - except
you can’t have it hardware accelerated (at least not through SDL),
and you have to do some serious optimizing to get to the performance
level of the SDL software blitters.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


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

[…]

David Olofson wrote:

Anyway, what I was saying was, if you want a car with translucent
windows, draw the car like that, instead of adding the window at
load time.

Can’t do that - the player has to be seen inside…

Independent animations for the player and the car? (That’s one of the
few valid reasons for going down the “composed sprites” route.)

Can’t see why you can’t render the player before the car… You could
even render an inside view of the car before rendering the player.

Basically, if you do all rendering directly to the screen (as
opposed to composing first, then blitting to the screen), alpha
blending works as expected, because each new surface is blended over
the background and any previous surfaces rendered, with or without
blending. Plain painter’s algorithm, just that not all pixels drawn
are opaque.

Of course, this means potentially lots of overdraw (wasted cycles),
but if you’re moving and/or animating everything, this cannot be
avoided anyway. Composing off-screen just adds another copy operation
to the cost.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Sunday 13 August 2006 02:52, L-28C wrote:

David Olofson wrote:

Well, it seemed like you were composing the car from multiple
images…? :slight_smile:

I am… :stuck_out_tongue:

David Olofson wrote:

Anyway, what I was saying was, if you want a car with translucent
windows, draw the car like that, instead of adding the window at
load

time.

Can’t do that - the player has to be seen inside…

You can’t render/draw the car with the player already inside? Is this
a
matter of having the player external to the car and getting inside? If
so,
why not render the car without the driver and one with the driver?
Then,
when the driver gets in the car you switch the car to a vehicle with
the
driver already inside and the driver becomes, essentially, invisible
but
maybe still represented by a rectangle in order to fix his location
for
later use or for, maybe, collision detection.>>> On 8/12/2006 at 7:52 PM, in message <eblt17$7r5$1 at sea.gmane.org>, L-28C wrote:


Lilith