Transparent textures with CreateTexture?
Blitz3D Forums/Blitz3D Programming/Transparent textures with CreateTexture?
| ||
Can I have a transparent texture that is dynamically created using CreateTexture? The following doesn't work... ; Create texture of size 256x256 tex = CreateTexture(256, 256, 4) ; Set buffer - texture buffer SetBuffer TextureBuffer(tex) ; Clear texture buffer with a black background ClsColor 0, 0, 0 Cls Color 255,0,0 Text 0, 0, "This is a test texture!" ; Texture cube with texture EntityTexture cube,tex PS. What are the tags for posting code? |
| ||
Can I have a transparent texture that is dynamically created using CreateTexture?[quote]Yes. No. Because you're not writting any data to the textures Alpha Channel. [quote]The following doesn't work... |
| ||
How do I do that? |
| ||
You can write this alpha data with writepixelfast - see code archives. |
| ||
This is a custom CreateTexture() function I wrote which gives the texture a starting alpha value.Function myCreateTexture( width, height, flags=0, frames=1, r=0, g=0, b=0, a=255 ) If width=0 Or height=0 Return 0 EndIf pBuffer = GraphicsBuffer( ) tex = CreateTexture( width, height, flags, frames ) SetBuffer TextureBuffer( tex ) argb = (b Or (g Shl 8) Or (r Shl 16) Or (a Shl 24)) For A = 0 To width For B = 0 To height WritePixel A, B, argb Next Next SetBuffer pBuffer Return tex End Function The alpha information is stored in the 8 bytes after the red value. |
| ||
PS. What are the tags for posting code? {code} ... {/code} But replace {} with []: ... |
| ||
http://www.blitzbasic.com/Community/posts.php?topic=26659 Check out the link above for a function to create a masked texture using createtexture |