Creating a masked texture
Blitz3D Forums/Blitz3D Beginners Area/Creating a masked texture
| ||
Hello, I didn't think this would be that difficult, but I've been stumped for a while. In the code, "plan B" has the end result I want, but you have to save an image file. Plan A is how I want the code to be, but I can't get the mask to work. Please help, normally I don't even need a plan A XD |
| ||
CopyRect ignores alpha. Use ReadPixel/WritePixel and adjust "by hand". I think this should work for Plan A. ;CopyRect 0,0,256,256,0,0,ImageBuffer(image),TextureBuffer(texture) maskcolor = $000000 ; R = G = B = $00 iBuff = ImageBuffer(image) tBuff = TextureBuffer(texture) For x = 0 To 255 For y = 0 To 255 argb = $00FFFFFF And ReadPixel( x, y, iBuff ) ; If pixel is maskcolor leave it as is, otherwise set alpha to 255 If argb <> maskcolor argb = $FF000000 Or argb End If WritePixel x, y, argb, tBuff Next Next |
| ||
Looking forward to it, thanks. |
| ||
You can create a purely alphaed texture and copyrect that using alpha. But you will still need to use writepixelfast to draw to it at some point. |
| ||
I plan for it to have 100 frames too, so I'll probably be testing out a lot of different methods tonight. By the way, has anyone else ever noticed that when you make a Dim with 100 slots, it actually has 101? 0 through 99 - and - 100. I noticed that the other day. I don't remember if I tried storing something in the last variable, but it was there. I only got an "array index out of bounds" error calling 101 and above. Probably a courtesy, not a mistake. |
| ||
Yes blitz arrays go from 0 to n where dim array(n)....so yes..you do get 1 extra element. |
| ||
By the way, has anyone else ever noticed that when you make a Dim with 100 slots, it actually has 101? 0 through 99 - and - 100. Yes, depending on the case, you may want to have an array with indexes from 0 to 99 (for example when using coordinates X,Y or X,Z to classify entities), but sometimes you may want to have an array with indexes from 1 to 100 (for example when using ids to classify entities), so sometimes you can just don't care about the 0 index even if it exists... |
| ||
Floyd, could you please explain the $s, 00s, and FFs in your code? The And and Or confuses me too, but I'm more curious about the cryptic looking stuff. Looks like the $ makes it so a binary variable can be read from and written to in hex, but how is it that they aren't all in groups of 4? |
| ||
I tried the code in post 2, but I guess I didn't apply it right, and it froze my computer to the point where Esc, the Windows key, and even Ctrl Alt Delete wouldn't quit it, and I actually had to turn the computer off with the power button. Could someone please edit my actual code? I don't understand the $FF000000 stuff, and I really don't like messing around with buffers if I can help it. |
| ||
$FF000000 is a hexadecimal argb code. each channel has one byte: 0-255 or 0-$FF. $ aa rr gg bb. With boolean algebra you can mask and mix them: a=$ff0000 b=$ff c=a OR b c is $ff00ff c=a And b c is zero (no identical bits set in both, a AND b...) To get rid of, say, the alpha, you would: rgb= (argb AND $FFFFFF) or to keep only alpha: alpha= (argb and $ff000000) then mix it elsewhere: argb2= (rgb2 or alpha) Esp. within IF Conditions you should use the Brackets for Boolean Algebra. |