can't get basic mask to work

BlitzMax Forums/BlitzMax Beginners Area/can't get basic mask to work

Grey Alien(Posted 2006) [#1]
Hmm, OK so in BlitzPlus if I had an image and it had a black background, I could set the mask colour to black and then when I drew it, all the pixels would be drawn except for the black ones, which were drawn as transparent.

I know I can achieve the same thing in BMax by having a proper png with transparency info and drawing it with SetBlend AlphaBlend, fine.

BUT, what if I have a bitmap with a black background that I don't want drawn, and I don't want to convert it into a png. I've tried using SetMaskColor 0,0,0 and loading it with the MASKEDIMAGE flag, and then drawing with SOLIDBLEND, but that still draws the black. Drawing with MASKBLEND looks horrible has it filters out all pixels < 0.5 alpha, and I don't want to use AlphaBlend. Any ideas what I'm doing wrong? Maybe I'm misinterpreting how MASKEDIMAGE works and it doesn't work like BlitzPlus? Thanks in advance.


WendellM(Posted 2006) [#2]
Playing with a non-alpha-ed PNG with a black background in BMax, I was able to get decent masking with both ALPHABLEND and MASKBLEND. Are you not wanting to use either of these modes because you're wanting the image to have two different sets of mask/blend info at the same time that can be displayed separately (i.e. black mask and alpha)? Otherwise a masked image works with either as long as it doesn't also have alpha information in it (is full alpha throughout).


TomToad(Posted 2006) [#3]
It has to do with the differences betwen the way DirectDraw(B+) and Direct3D(BMax) handle masking. In DirectDraw, every time you draw an image, the pixels are examined to see if it matches the mask color. If it matches, the pixel isn't drawn. If it doesn't match, then the pixels are drawn. In Direct3D, the alpha channel is examined. When the alpha bit is greater than 0.5, then the pixel is drawn, otherwise it is masked. When you load the image in BMax with the MASKEDIMAGE flag, BMax will examine the image and set it's alpha bit to 0 if it matches the SetMaskColor color.
If your image already has alpha information, then anything which matches the mask color, as well as anything with an alpha <= 0.5 will be masked. You either need to save the image without alpha information or make sure that anything you want to have drawn has an alpha > 0.5.


tonyg(Posted 2006) [#4]
Can you post the image as loading and drawing a bitmap image with the defaults (maskimage, mask colour 0,0,0 and
blend mode maskblend) works fine for me?


Grey Alien(Posted 2006) [#5]
hmm thanks for the info people. It's true I'm using a png with an alpha channel already and a black area that I wanted not drawn. I guess I could save it as a bmp and try again...I'm afraid I can't post the image as it would give away the game and I'm under an NDA.

Basically I have a png with alpha info, that I'm actually drawing with solid blend so the transparent areas come out dark. But I'm moving it vertically and drawing a non-integer coords which gives a juddery effect on the edge of the image. I discovered a while ago that adding an empty row of pixels around the edge of an image means it can anti-alias better when drawing at sub-pixel coords. So I added a black row on the edge and hoped that SetMaskColor 0,0,0 with Solidblend would just not draw it, but it didn't and MaskBlend looked horrible due to the <0.5 thing. IT's not critical, I was just being picky. May try as a bmp right now...


Grey Alien(Posted 2006) [#6]
yep that worked, saved as bmp and the black is now masked out. Interestingly, when using SolidBlend it still juddered at the edges whereas using Alphablend it looked much more smooth (even though the image has no alpha info), weird...

It's worth noting that when you export a png as bmp in Gimp, it turns the transparent are into your current background colour (mine was white at first, so I changed it to black).

Now I'm going to try converting it back to png to save disk space and see if it still works...

Yep that totally work. thanks all.


Dreamora(Posted 2006) [#7]
The main difference between BM masking and Blitz3d / BB+ is that the later two didn't support alpha as directDraw does not ... and BM does.

Originally, masking worked as with those two in BM as well ... but with 1.14 or 1.16 it was changed so alpha was taken into account as well.


Grey Alien(Posted 2006) [#8]
Yeah I knew BPlus couldn't do alpha support which is why I changed to BMax (one of the main reasons). I was just trying to get my drawing to work in that old way for a specific purpose and finally got it sorted.