Whilst I've been using Blitz3D for a few years, I've now started playing around with the actual 3D components and have come across a problem.
I have an entity that has an image textured to it. However, parts of the image (specifically black - RGB(0,0,0) are being masked out, meaning that the background image is showing through what is supposed to be a solid object.
Question - Is there a command (or a function) that will allow me to set the entity mask colour like the MaskImage Image,R,G,B command? I've looked through the commandset and can't seem to find one that suits my needs. I want the maskimage colour to be 255,0,255 if possible.
It seems odd that I can't show black in my entities.
Please don't say re-draw your image texture, replacing RGB 0,0,0 to RGB 0,0,5 or something silly like that - I have over 100 images and I haven't the time or inclination to redo them all!
Your help is greatly appreciated.
Do the following
ClearTextureFilters()
TextureFilter "",1+8
At the top of your code, just after the graphics command :o) What this does, is clears all the filters that are preset for textures. In your case, stops the mask flag from being used.
If you want to mask of a colour in a texture, use this function:
;---------------------------------------------------------------------
; This function will mask the passed across RGB of the texture also |
; passed across. Do NOT pass across a value for flag if you only |
; want to mask an exact colour. |
;---------------------------------------------------------------------
;parameters = texture : the texture you wish to clear alpha information from
; = r1 : the red value to mask
; = g1 : the green value to mask
; = b1 : the blue value to mask
; = tolerance : the tolerance value. If set to 0, then the function will only mask the
; EXACT colours passed across. Higher value will mask values close to the colour.
Function texture_mask_colour(texture,r1,g1,b1,tolerance=0)
LockBuffer TextureBuffer(texture)
For loop=0 To TextureWidth(texture)
For loop1=0 To TextureHeight(texture)
RGB1=ReadPixelFast(loop,loop1,TextureBuffer(texture)) ; read the RGB value from the 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 ; extract the alpha
If r>=r1-tolerance And r=<r1+tolerance And g=>g1-tolerance And g=<g1+tolerance And b=>b1-tolerance And b=<b1+tolerance Then; check RGB lies with the tolerance
;temp=((Abs(r-r1)+Abs(g-g1)+Abs(b-b1))/3.0)*4.0 ; alpha the values based on the tolerance value
a=0;temp
End If
newrgb= (a shl 24) or (r shl 16) or (g shl 8) or b ; combine the ARGB back into one value
WritePixelFast(loop,loop1,newrgb,TextureBuffer(texture)); write back to the texture
Next
Next
UnlockBuffer TextureBuffer(texture)
End Function
Cheers Ross, but using both of your methods I can mask a specified colour, but colour 0,0,0 is still masked out too. I want to see 0,0,0. The first method didn't seem to make any difference at all.
:(
[EDIT] I looked at the "LoadTexture" command and removed the mask flag (4) from the command and that allowed the black to show :), but the pink 255,0,255 doesn't get masked out now :(
What flag setting do I need to use to allow the black to remain, but remove the pink for your function to work?
Ok, use this function first, on your texture:
Function prepare_texture(texture)
LockBuffer TextureBuffer(texture)
For loop=0 To TextureWidth(texture)-1
For loop1=0 To TextureHeight(texture)-1
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=255; remove any alpha information currently in the texture.
newrgb= (a shl 24) or (r shl 16) or (g shl 8) or b; combine the ARGB back into a number
WritePixelFast(loop,loop1,newrgb,TextureBuffer(texture)); write the info back to the texture
Next
Next
UnlockBuffer TextureBuffer(texture)
End Function
Call it by doing:
prepare_texture(texture)
This will clear all mask and alpha info. Then use the other function by doing:
texture_mask_colour(texture,r,g,b)
The RGB being the colour you wish to show.
Thanks Ross, that had the desired effect :)
Sorry, i forgot to post the clearing function. If you click on peoples names, above their post, then click on CODE ARCHIVE ENTRIES, you can see what code they have put in. I took that code from my code archive entry :o)
Well it worked in the end, and that's all that matters :)
Thanks for your help.