Anyone got an idea how to draw (add/sub/alpha) using a mask?
Anyone got an idea how to draw (add/sub/alpha) using a mask?
you mean in the same way that flash works?
(after 5 seconds of thought)
You need to make extra parts of your sprite transparent.
You can't directly I think,
one way to do it would be to create a temporary surface and blit your sprite to it.
Then blit the masked area to the temporary sprite (the masked area would be your normal transparent colour and another colour set as the transparent colour for this blit operation..)
so in effect, you are drawing extra transparent areas onto your sprite so when you blit this new surface to the screen, part of it is obscured.
Does this make sense?
For an example, you have a pre-rendered background with some nice chainlink fencing in the foreground.. but of course, there's all part of the background image so in order to walk behind them, you have to make a mask.
So you create another image with the foreground elements rendered in your normal sprite's background colour and the background elements rendered in another colour (possibly black) This image would only have 2 colours in it.
You blit your sprite image to a temporary surface
Then blit the part of the mask image to the temporary surface to add additional transparency to your sprite.
Then you blit your sprite to the screen and he'll be behind the chain link fence, but in front of the background elements.
Of course, this idea would work best with alpha transparency because with a simple transparent colour approach, you get very hard, jaggy edges.
Does this help?
I think you`ve just confirmed the way I thought I`d have to do it - but I was rather hoping there was a way a mask could be combined in the blitting operation itself (like it was on the Amiga for instance)
The problem comes when I would need to mask dynamic stuff from the screen (as opposed to a static image I could easily make a mask from)
Therefore, this leads to a new question: how to make an alpha channel from an existing image? I'll have to check what happens when an e.g. 16bit image is drawn into a 2bit surface
I have to ask the question, what is it you're trying to do..?
Masking is one trick to prevent overdraw performance hits by ensuring that sprites can be drawn in any order. If the system you're writing for has enough oomph, you don't need to worry too much about it.. in fact, it might slow your game down if you do too much. If you're making an isometric engine, just render left to right from the top down, only skipping sprites which are wholly obscured.
Unless you get performance issues while rendering, I would just make sure things were rendered in the correct order so that background objects don't obscure foreground objects.. masking would be something I'd worry about last and even then, after I'd exhausted all other optimisation tricks.
If you have a list of sprites to render, sort them by their Z axis, then they will always be drawn on top of eachother in the correct order. Unless you're doing something else, anything else will be overkill and bug prone.
My basic rule is:
get it working properly first, then optimise. It's OK to think about opimisation, but don't implement it until you're sure you need it. You may end up crippling yourself by concentrating on a problem which wasn't as bad as you thought it was.
Unless you're thinking about something else...
let me know what you're thinking.
There is a way of drawing transparent sprites to the screen just using BitBlt. But it's not soft alpha transparency, it's either transparent or not.
Here's how to do it:
1. Make all the areas of the sprite that should be transparent black
2. Create the mask, making all the areas that should be transparent on the original sprite white. Make all the areas that should be blitted unchanged to the destination black (ie. make the rest black).
3. BitBlt the Mask onto the destination with the SRCAND raster constant.
4. BitBlt the original sprite with the SRCPAINT raster operator.
Here's what I`m trying to do.
This is only an attract screen effect, not an ingame effect.
Here is the result using DrawAdd
and the same result with DrawSub
As you can see, I don't want to add the gradient effect to the background of the letters.
Hi,
When text will be as DIB32 with mask alphachannel then showed effect will be out (but I don't know exactly, how you create a glass).
Ijcro.
I played around with the old ROPS again (long time since I did this!)Originally Posted by Nitrogen
However, I got some serious problems with anything other than SRCCOPY or WHITENESS. Sometimes I even got pieces of my desktop mixed into the screen and only every other flip was updated?
I used the wait bits etc, but still odd behaviour... anyway, I ended up just drawing an inverted mask (more like a stencil really) and this works fine for pre-rendered work.
The problem remains how to generate a mask / stencil from an existing dynamic screen though - but I don't need it now
Bookmarks