About transparent images

BlitzMax Forums/BlitzMax Beginners Area/About transparent images

Takis76(Posted 2012) [#1]
Hello again,

Is it possible to have transparent images with transparent color 255,0,255

The setmaskcolor(255,0,255) alone is not working.
What is missing?

I don't want to create transparent image with GIMP.


Midimaster(Posted 2012) [#2]
you have to set the maskcolor before loading the image. And you have to set the MASKEDIMAGE filter, when loading:

Graphics 800,600
SetMaskColor 255,0,255
pic=LoadImage("PinkMask.png",MASKEDIMAGE)
Repeat
	DrawImage pic, 300,300
	Flip 0
Until KeyHit(key_Escape)


Last edited 2012


Kryzon(Posted 2012) [#3]
Don't forget to call SetBlend MASKBLEND before drawing any masked images.

It activates the blend mode responsible for masking images (it's GL_ALPHA_TEST or the D3D equivalent, if anyone's curious).


EDIT: using the above...
Graphics 800,600
SetMaskColor 255,0,255
pic=LoadImage("PinkMask.png",MASKEDIMAGE)
Repeat
	SetBlend MASKBLEND
	DrawImage pic, 300,300
	Flip 0
Until KeyHit(key_Escape)
If you're only drawing masked images, you can call it outside the loop once so that this blend state is kept for the entire program.
If, however, you're using several blend modes in the middle of your code, you need to call it again before drawing any series of images that need this masked blend.
This is how blend modes are best used: a single blend change done for the series of images that use it.

Last edited 2012


Takis76(Posted 2012) [#4]
Thank you very much is working.