Shadow Example Code


Tweet blitzmax blitzmax-ng code-archives
(Posted 6 months ago) RonTek

Test code with using OpenB3D Stencil Shadows.

OpenB3D - Shadow Example Code

' stencil_shadows.bmx
' code by KronosUK

Framework Openb3dmax.B3dglgraphics

Graphics3D 800,600,0,2

Local light:TLight = CreateLight(2)
RotateEntity light,45,0,0
PositionEntity light,0,25,0

Local camera:TCamera = CreateCamera()
PositionEntity camera,-20,10,0

Local plane:TMesh = CreatePlane(16)
TranslateEntity plane,0,-1,0
PointEntity camera,plane

MoveEntity camera,-56,10,0

For Local i% = 1 To 100
    Local cube:TMesh = CreateCube()
    EntityColor cube,rand(255),rand(255),rand(255)
    PositionEntity cube,Rnd(100),0,Rnd(100)
    Local shadow:TShadowObject = CreateShadow(cube)

    Local cylinder:TMesh = CreateCylinder()
    EntityColor cylinder,rand(255),rand(255),rand(255)

    PositionEntity cylinder,Rnd(100),0,Rnd(100)
    Local shadow1:TShadowObject = CreateShadow(cylinder)
Next

Local wiretoggle%=-1
While Not KeyHit(key_escape) And Not AppTerminate()

    If KeyHit(key_space) Then wiretoggle=-wiretoggle

    If KeyDown(KEY_UP) Then MoveEntity camera,0,0,1
    If KeyDown(KEY_DOWN) Then MoveEntity camera,0,0,-1
    If KeyDown(KEY_LEFT) Then MoveEntity camera,-1,0,0
    If KeyDown(KEY_RIGHT) Then MoveEntity camera,1,0,0

    If wiretoggle=1 Then Wireframe True Else Wireframe False

    UpdateWorld()
    RenderWorld()
    Flip()
Wend

Reply To Topic (minimum 10 characters)

Please log in to reply