Alpha Map Issues...

Blitz3D Forums/Blitz3D Programming/Alpha Map Issues...

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.

It's to filter out the A R G B from the readpixel command. The colour information gets returned in a 32 bit number.

			RGB1=ReadPixelFast(loop,loop1,TextureBuffer(texture))
			r=(RGB1 And $FF0000)shr 16;separate out the red
			g=(RGB1 And $FF00) shr 8;green
			b=RGB1 And $FF;and blue parts of the color
			a=(RGB1 And $FF000000)Shr 24


a is the variable that will hold the alpha information. That line of code will extract it from the number the readpixel command returns. I'm not dead sure about it, as i obtained the filtering code from another place, but it's taking certain bits from the number and storing them in a. Basically what you'd want to do, is only extract the alpha from the alpha texture and write it back into the normal texture.

So:

Function transfer_alpha(source,des) ; source is the texture the alpha will get copied from
									; des is the texture the alpha will get written to.

	LockBuffer TextureBuffer(source)
	LockBuffer TextureBuffer(des)

	For loop=0 To TextureWidth(source)-1
		For loop1=0 To TextureHeight(source)-1

			RGBsource=ReadPixelFast(loop,loop1,TextureBuffer(source))
			
			SourceR = (RGBsource And $FF0000)Shr 16;separate out the red
			SourceG = (RGBsource And $FF00) Shr 8;green
			SourceB = RGBsource And $FF;and blue parts of the color
			SourceA = (RGBsource And $FF000000)Shr 24; and seperate out the alpha

			RGBdes = ReadPixelFast(loop,loop1,TextureBuffer(des))

			DesR = (RGBdes And $FF0000)Shr 16;separate out the red
			DesG = (RGBdes And $FF00) Shr 8;green
			DesB = RGBdes And $FF;and blue parts of the color
			DesA = SourceA ; copy the alpha information from the source texture to the desination one.

			
			newrgb= (DesA Shl 24) Or (DesR Shl 16) Or (DesG Shl 8) Or DesB; combine the ARGB back into a number

			WritePixelFast(loop,loop1,newrgb,TextureBuffer(des)); write the info back to the texture
		Next
	Next

	UnlockBuffer TextureBuffer(des)
	UnlockBuffer TextureBuffer(source)


End Function


That function should work for you. Just call it with the source and destination textures. Make sure there the same size though. I didn't take into account they were different :o)