Transparent Image drawing masks ????
BlitzMax Forums/BlitzMax Programming/Transparent Image drawing masks ????
| ||
this is hard to explain without code .. but I will try. I have three images, layers, I then draw a blast hole (black) over the first layer which is the mask colour so layer 2 is then visible through layer 1, I then repeat the above on layer 2 but shrinking the blastimage a little to give a 3D effect. Trouble is that when I draw more than one or when I happen to have an image thats colour is the same as the mask it gets all messed up. is there a way for me to draw my blast hole image as transparent so that I dont need to worry about maskcolors. ? |
| ||
Save your images in a format (such as PNG) that supports an alpha channel so you can have transparency. Then it's just as simple as having your blend mode set to ALPHABLEND, I believe. |
| ||
they are png's |
| ||
is there a faster way to do this ?DrawImage DesktopImage , 0 , 0 DrawImage Blast1 , hx , hy , 0 GrabImage (DesktopImage,0,0) because that's slow as hell and as soon as I call it a few times it's really laggin the code. |
| ||
Unless you use opengl directly I don't think it's possible to do this on the fly. If it is I'd love to know how. |
| ||
I'm doing this once every second , if I up the rate to 2 seconds then I could get away with it as is but I want it faster. I find it really odd that blitz3d can do this really fast and max can't there must be some code to do it faster |
| ||
SetBlend SHADEBLEND you will need another layer, a mask layer, which is two colors: black and white. white is the circle (pixels) you want to keep, everythign else is black draw from back to front, using the black&white layer inbetween and the final top layer. |
| ||
Sounds like a worms game is in the works? |
| ||
Is this fast enough to do several dozen times a frame? |
| ||
It sounds like you want RGBA textures and to then draw the blast circles to the alpha channel of those textures. |
| ||
Imaginary yeah that sounds about right got any code for that ? I am actually working on a screen saver, the code grabs a screen shot of your current windows desktop, and stores it as an image, I then have two other images, one that looks like a computer circuit board and a third is a hummour picture. the bombs fall, land and start to tick, when they blow up , I am drawing a big blast on the desktop image, a smaller blast on the circuit image which over time reveals whats on the funny image. it's kinda working at the moment, but as I said in the OP, grabimage is way to slow. As for worms, I actually got the idea while looking at my old worms clone game that I wrote in blitz2d so im stunned that blitzmax cant actually do this faster. any help code wise would be much appreciated. |
| ||
Harder to change textures, better with pixmaps. There's a trick to this, I need to sit and experiment. OpenGL register combiners may work for this. There is a simple solution somewhere... |
| ||
AdamRedwoods, I can't get this to work SetBlend SHADEBLEND you will need another layer, a mask layer, which is two colors: black and white. white is the circle (pixels) you want to keep, everythign else is black draw from back to front, using the black&white layer inbetween and the final top layer. The first can't be shadeblend or it's all black. The mask is a white square with a black circle. I can get grass with a black circle but I can't get the sand to fill in the black circle. SetBlend ALPHABLEND DrawImage grass, 0, 0 SetBlend SHADEBLEND DrawImage mask, 0, 0 SetBlend SHADEBLEND DrawImage sand, 0, 0 |
| ||
I might just fake it and just draw hole sprites store them in. A list. But it won't be as good |
| ||
Hi, I had to sit and think about this one. I'm not sure why this has to be so difficult with OpenGL, but it is. Anyways: '' alpha masking example '' adamredwoods, 2011 '' SetGraphicsDriver (GLMax2DDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_STENCILBUFFER|GRAPHICS_ALPHABUFFER) Graphics 900,600,0,60 Local imagedesktop:TImage = LoadImage("desktop.jpg") Local image2:TImage = LoadImage("kitten-1.jpg") Local maskwidth:Int=90, maskheight:Int=90 SetMaskColor( 0,0,0 ) Local maskimage:TImage = CreateImage(maskwidth,maskheight,1,MASKEDIMAGE) 'Local maskimage:TImage = LoadImage("white_circle_alpha.png") SetBlend ALPHABLEND SetClsColor 0,0,0 Cls SetColor 255,255,255 DrawOval 10,10,80,80 GrabImage maskimage,0,0 ''if you load an image or draw an oval (below), disable this SetColor 255,255,255 ''reset the color for drawimage glEnable (GL_STENCIL_TEST) glDepthMask(GL_FALSE) glStencilMask($ffffff) SetBlend solidblend Local x:Int, y:Int While Not AppTerminate() And Not KeyDown(KEY_ESCAPE) Cls glClearStencil(0) glClear(GL_STENCIL_BUFFER_BIT) glDisable (GL_STENCIL_TEST) DrawImage imagedesktop,0,0 x = MouseX()-maskwidth*0.5 y = MouseY()-maskheight*0.5 If x+maskwidth>image2.width Then x = image2.width-maskwidth If y+maskheight>image2.height Then y = image2.height-maskheight ''set mask glEnable (GL_ALPHA_TEST) glEnable (GL_STENCIL_TEST) glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE) glStencilFunc (GL_ALWAYS, $ffffff,$ffffff) DrawImage maskimage,x,y 'DrawPixmap LockImage(maskimage),x,y 'DrawOval x,y,30,30 ''draw the revealed image glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP) glStencilFunc (GL_EQUAL, $ffffff,$ffffff) glDisable (GL_ALPHA_TEST) DrawImage image2,0,0 Flip Wend End The negative side of this is that it does NOT draw nice feathered edges, even when loading a nice PNG image. This is because (as far as I understand) the stencil buffer rejects or draws the fragment.... so there's no inbetween. The only other solution I can think of is to use register combiners and textures. Last edited 2011 |
| ||
Czar Flavius also has a similar solution here Last edited 2011 |