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
|