Alpha color

Blitz3D Forums/Blitz3D Beginners Area/Alpha color

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Well, I just coded my version of translucent drawimage and it works fast enought for some sprites. I really would like this function is integrated in the next update of Blitz+.

Graphics(800,600,0,2)
SetBuffer BackBuffer()

Const LG_IMG=200,HT_IMG=180 ;Size of the sprite

bck=LoadImage("picture800x600.jpg")
img=LoadImage("sprite200x180.jpg")

bck_buf=ImageBuffer(bck)
img_buf=ImageBuffer(img)

LockBuffer(bck_buf)
LockBuffer(img_buf)

While Not KeyHit(1)
	x=MouseX()
	y=MouseY()
	
	DrawBlock(bck,0,0)
	LockBuffer()
	
	For j=0 To HT_IMG-1
		For i=0 To LG_IMG-1
			offx=x+i
			offy=y+j
			
			bck_pix=ReadPixelFast(offx,offy,bck_buf)
			bck_r=bck_pix And $00FF0000
			bck_g=bck_pix And $0000FF00
			bck_b=bck_pix And $000000FF
					
			img_pix=ReadPixelFast(i,j,img_buf)
			img_r=img_pix And $00FF0000
			img_g=img_pix And $0000FF00
			img_b=img_pix And $000000FF
			
			tr=(((bck_r Shr 16)+(img_r Shr 16)) Shr 1) Shl 16
			tg=(((bck_g Shr 8)+(img_g Shr 8)) Shr 1) Shl 8
			tb=(bck_b+img_b) Shr 1
					
			WritePixelFast(offx,offy,tr+tg+tb)	
		Next
	Next

	UnlockBuffer()
	Flip()
Wend

FreeImage(bck)
FreeImage(img)