Texture Alpha

Blitz3D Forums/Blitz3D Beginners Area/Texture Alpha

Whats My Face(Posted 2007) [#1]
I was trying to create something like that grass demo but for some odd reason when I create a texture from scratch it doesn't want to become transparent.

;some variables
Global gb.grassblock
Global grasstex

;set up
Graphics3D 800,600,16,2
AutoMidHandle True
SetBuffer BackBuffer()
SeedRnd(MilliSecs())
AmbientLight 255,255,255

;camera
Global camera = CreateCamera()
CameraClsColor camera,0,0,255
CameraRange camera,.01,1000
PositionEntity camera,0,.5,0

Type grassblock
	Field grass[25] ;to give the grass height
	Field size
	Field layers
	Field height
End Type

CreateGrassBlock(0,0,0,0,0,0,1,6,.0025)

;main loop
While Not KeyHit(1)
	Cls
	
	If KeyDown(30) TurnEntity camera,0,1,0
	If KeyDown(32) TurnEntity camera,0,-1,0
	
	If KeyDown(17) TranslateEntity camera,0,.025,0
	If KeyDown(31) TranslateEntity camera,0,-.025,0
	
	If KeyDown(200) MoveEntity camera,0,0,.025
	If KeyDown(208) MoveEntity camera,0,0,-.025
	
	UpdateWorld()
	RenderWorld()
	
	Flip
Wend 

Function CreateGrassBlock(x#,y#,z#,pitch#,yaw#,roll#,size,layers,height#)
	gb.grassblock = New grassblock
	gb\size = size
	gb\layers = layers
	gb\height = height#
	
	Local n
	
	;create the transparency texture
	grasstex = CreateTexture(256,256,2)
	
	SetBuffer TextureBuffer(grasstex)
	Color 0,0,0
	Rect 0,0,256,256,True
	
	Color 255,255,255
	For n = 1 To 5000
		Plot Rand(1,256),Rand(1,256)
	Next
	
	SetBuffer BackBuffer()
	
	;create the grass
	If layers > 25 layers = 25
	For n = 0 To layers
		gb\grass[n] = CreateTerrain(size)
		PositionEntity gb\grass[n],x#,y#,z#
		RotateEntity gb\grass[n],pitch#,yaw#,roll#
		TranslateEntity gb\grass[n],0,Float(height#*n),0
		EntityTexture gb\grass[n],grasstex,0,1
	Next

End Function 



Sledge(Posted 2007) [#2]
http://www.blitzbasic.com/Community/posts.php?topic=64678#722116


Whats My Face(Posted 2007) [#3]
I don't see what they did. Could somebody explain it to me.


Stevie G(Posted 2007) [#4]
Creating a texture using the alpha flag does nothing as it cannot know what pixels you would like to be transparent or otherwise so defaults to full alpha for everything.

You can use a routine like this to mask out the black ...

http://www.blitzbasic.com/codearcs/codearcs.php?code=1013

There may be issues with black borders but there are other routines in the Blitz3d Misc code archives which can help there.

Stevie


Whats My Face(Posted 2007) [#5]
Thanks Stevie G, I got it working now.


Ross C(Posted 2007) [#6]
I think skidracer had a great routine for that. If you can search for him you'll probably find it :o)