Transparent textures with CreateTexture?

Blitz3D Forums/Blitz3D Programming/Transparent textures with CreateTexture?

Slider(Posted 2003) [#1]
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?


FlameDuck(Posted 2003) [#2]
Can I have a transparent texture that is dynamically created using CreateTexture?[quote]Yes.
[quote]The following doesn't work...
No. Because you're not writting any data to the textures Alpha Channel.


Slider(Posted 2003) [#3]
How do I do that?


Rob(Posted 2003) [#4]
You can write this alpha data with writepixelfast - see code archives.


Odds On(Posted 2003) [#5]
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.


GitTech(Posted 2003) [#6]

PS. What are the tags for posting code?



{code}
...
{/code}

But replace {} with []:

...



Who was John Galt?(Posted 2003) [#7]
http://www.blitzbasic.com/Community/posts.php?topic=26659

Check out the link above for a function to create a masked texture using createtexture