grabpixmap and save with alpha

BlitzMax Forums/BlitzMax Programming/grabpixmap and save with alpha

Very nearly there with this, after googling I found out about glcolormask to draw in 2 passes, colour then alpha, it's not perfect but nearly there, I think maybe there's zbuffer issues, not sure tho:

SuperStrict

SetGraphicsDriver GLMax2DDriver() 

Graphics (1000, 500) 

SetAlpha.5

SetClsColor2 0, 0, 0, 0
Cls

glEnable GL_BLEND
glColorMask(True, True, True, False)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glDisable GL_ALPHA_TEST

SeedRnd 0

For Local c:Int = 1 To 255
	Local size:Int = Rnd(50, 125) 
	SetColor c, c, 0
	DrawOval Rnd(100, 300), Rnd(100, 300), size, size
Next

glEnable GL_BLEND
glColorMask(False, False, False, True)
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
glDisable GL_ALPHA_TEST

SeedRnd 0

For Local c:Int = 1 To 255
	Local size:Int = Rnd(50, 125) 
	SetColor c, c, 0
	SetAlpha.5
	DrawOval Rnd(100, 300), Rnd(100, 300), size, size
Next

Local pixmap:TPixmap = GrabPixmap(0, 0, 500, 500) 
SavePixmapPNG(pixmap, "test.png") 
glColorMask(True, True, True, True)
SetAlpha 1
SetBlend alphablend
Local testimg:TImage = LoadImage("test.png") 
DrawImage testimg, 500, 0

Flip
WaitKey

Function SetClsColor2(red#, green#, blue#, alpha# = 255) 
	glClearColor red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0
End Function