strange pixmap/image issue?

BlitzMax Forums/BlitzMax Programming/strange pixmap/image issue?

Xip(Posted 2008) [#1]
Im not sure if its me, who have been up for to long with no sleep and very little food... but i simply dont anderstand what the hell is going on here.

Here is what i was trying to do:
i was working on a game where the landskape was fully destructable, and i was having some huge problems with transparans on a image created with CreateImage() and generated with WritePixel(), after tons of testing i found out that a combination of MaskPixmap() and reloading the image, solves it.

now, when i create holes in the terrain, i need to do it again, but now this very odd behavier appears... and i francly dont know what the hell is going on, well... take a look and see your self.

there is a 1500ms delay on purpuse, to see what happens from the first loop to the next.

now, if it is not obvious, The pixels are not supose to get bigger, there is only supose to be a square hole in top left corner, however... all the pixels gets huge ?:S

uhm... now... me need sleep ... -.-


SeedRnd MilliSecs()
Graphics 800,600

SetMaskColor(255,0,255)

Global img:TImage = CreateImage(200,200,DYNAMICIMAGE|MASKEDIMAGE)



Local pmap2:TPixmap = LockImage(img)

For Local j:Int =0 To ImageHeight(img)-1
	For Local i:Int =0 To ImageWidth(img)-1
		
		If Rand(0,10)=1 Then
		
			WritePixel(pmap2,i,j, toARGB(255,0,255,255))
		Else
			WritePixel(pmap2,i,j, toARGB(255,255,0,255))
	
		EndIf
		
	Next
Next

pmap2=MaskPixmap(pmap2,255,0,255)

UnlockImage(img)

img = LoadImage(pmap2)

Repeat
	Cls()

	DrawImage img, 100,100 

	paintHole(img,20,20)

	Flip()
	
	Delay(1500)
	
Until KeyHit(KEY_ESCAPE)


Function toARGB:Int(a:Int,r:Int,g:Int,b:Int)
	Return ((a Shl 24)|(r Shl 16)|(g Shl 8)|b)
End Function


Function paintHole(image:TImage, x:Int, y:Int)
	' ...
	
	Local pmap:TPixmap = LockImage(image)

	For Local j:Int =0 To 50
		For Local i:Int =0 To 50
			WritePixel(pmap,i,j,toARGB(255,255,0,255))
		Next
	Next
	pmap=MaskPixmap(pmap,255,0,255)

	UnlockImage(image)
	img = LoadImage(pmap)
	
End Function




note:
removing maskpixmap and loadimage from inside the paintHole removes the problem, however... as far as i can tell, i still need to use them for the transparans to work on the hole, even tho it dont seem to work in the source above :(


Jesse(Posted 2008) [#2]
hint check your alpha - try to understand how setblend works and how it relates to setmaskcolor. sorry no time to explain have to go. When I come back I'll explain:

try this:

SeedRnd MilliSecs()
Graphics 800,600
SetBlend maskblend 
SetMaskColor(255,0,255)

Global pm:TPixmap = CreatePixmap(200,200,PF_RGBA8888)

For Local j:Int =0 Until pm.height
	For Local i:Int =0 Until pm.width
		
		If Rand(0,10) Then
			WritePixel(pm,i,j, toARGB(255,0,255,255))
		Else
			WritePixel(pm,i,j, toARGB(125,255,0,255))
		EndIf
		
	Next
Next

img = LoadImage(pm)

Repeat
	Cls()

	DrawImage img, 100,100 

	paintHole(pm,20,20)
	img = LoadImage(pm)
	Flip()
	
	Delay(2500)
	
Until KeyHit(KEY_ESCAPE)


Function toARGB:Int(a:Int,r:Int,g:Int,b:Int)
	Return ((a Shl 24)|(r Shl 16)|(g Shl 8)|b)
End Function


Function paintHole(pm:TPixmap, x:Int, y:Int)
	' ...
	
	For Local j:Int =0 To 50
		For Local i:Int =0 To 50
			WritePixel(pm,x+i,y+j,toARGB(125,255,0,255))
		Next
	Next
		
End Function



Xip(Posted 2008) [#3]
No need to explain, I got it :)

this is why you should not write code, when you havent sleept for a day or two :P he he

tanx for your help Jesse :)

[edit] uhm... this was quite silly of me, I have no idea wtf i was doing last night :P lol