Of course, it was a straightforward merging of the existing BBCOWL and LIGHTING demos. I assume it's the BB4W (Direct3D) code you are more interested in rather than the BBCSDL (OpenGL) version:
Code: Select all
MODE 8 : OFF
INSTALL @lib$+"D3D9LIB"
DIM Light%(1), Object%(2), nVert%(2), Format%(2), Size%(2)
DIM Material%(2), Texture%(2), Yaw(2), Pitch(2), Roll(2)
DIM Xpos(2), Ypos(2), Zpos(2), Eye(2), LookAt(2), r{pitch%,pbits%}
ON CLOSE PROCcleanup:QUIT
ON ERROR PROCcleanup:PRINT REPORT$:END
pDevice% = FN_initd3d(@hwnd%, 2, 1)
IF pDevice% = 0 ERROR 100, "Can't initialise Direct3D"
SYS !(!pDevice%+228), pDevice%, 27, 1 : REM ALPHABLENDENABLE
SYS !(!pDevice%+228), pDevice%, 19, 5 : REM SRCBLEND
SYS !(!pDevice%+228), pDevice%, 20, 6 : REM DSTBLEND
SYS !(!pDevice%+228), pDevice%, 29, 1 : REM D3DRS_SPECULARENABLE
SYS !(!pDevice%+228), pDevice%, 147, 1 : REM D3DRS_AMBIENTMATERIALSOURCE
Object%(0) = FN_load3d(pDevice%, @dir$+"OBJECT_texture_opaque_matt.FVF", \
\ nVert%(0), Format%(0), Size%(0))
IF Object%(0) = 0 ERROR 100, "Couldn't load OBJECT_texture_opaque_matt.FVF"
Object%(1) = FN_load3d(pDevice%, @dir$+"OBJECT_colour_opaque_matt.FVF", \
\ nVert%(1), Format%(1), Size%(1))
IF Object%(1) = 0 ERROR 100, "Couldn't load OBJECT_colour_opaque_matt.FVF"
Object%(2) = FN_load3d(pDevice%, @dir$+"OBJECT_colour_transp_matt.FVF", \
\ nVert%(2), Format%(2), Size%(2))
IF Object%(2) = 0 ERROR 100, "Couldn't load OBJECT_colour_transp_matt.FVF"
Texture%(0) = FN_loadtexture(pDevice%, @dir$+"is.bmp")
IF Texture%(0) = 0 ERROR 100, "Couldn't load is.bmp"
REM Make texture opaque:
SYS !(!Texture%(0)+76), Texture%(0), 0, r{}, 0, 0 : REM LockRect
FOR Y% = 0 TO 340
FOR X% = 0 TO 501
P% = r.pbits% + r.pitch%*Y% + 4*X%
P%?3 = &FF
NEXT
NEXT Y%
SYS!(!Texture%(0)+80), Texture%(0), 0 : REM UnlockRect
DIM Material{Diffuse{r%,g%,b%,a%}, Ambient{r%,g%,b%,a%}, \
\ Specular{r%,g%,b%,a%}, Emissive{r%,g%,b%,a%}, Power%}
Material.Specular.r% = FN_f4(120/255)
Material.Specular.g% = FN_f4(120/255)
Material.Specular.b% = FN_f4(120/255)
Material.Power% = FN_f4(40)
Material%(0) = Material{}
DIM D3Dlight9{(1) Type%, Diffuse{r%,g%,b%,a%}, Specular{r%,g%,b%,a%}, \
\ Ambient{r%,g%,b%,a%}, Position{x%,y%,z%}, Direction{x%,y%,z%}, \
\ Range%, Falloff%, Attenuation0%, Attenuation1%, Attenuation2%, \
\ Theta%, Phi% }
D3Dlight9{(0)}.Type% = 3 : REM directional
D3Dlight9{(0)}.Diffuse.r% = FN_f4(170/255)
D3Dlight9{(0)}.Diffuse.g% = FN_f4(170/255)
D3Dlight9{(0)}.Diffuse.b% = FN_f4(170/255)
D3Dlight9{(0)}.Ambient.r% = FN_f4(85/255)
D3Dlight9{(0)}.Ambient.g% = FN_f4(85/255)
D3Dlight9{(0)}.Ambient.b% = FN_f4(85/255)
D3Dlight9{(0)}.Direction.x% = FN_f4(-1)
D3Dlight9{(0)}.Direction.y% = FN_f4(-1)
D3Dlight9{(0)}.Direction.z% = FN_f4(-1)
Light%(0) = D3Dlight9{(0)}
D3Dlight9{(1)}.Type% = 1 : REM point source
D3Dlight9{(1)}.Specular.r% = FN_f4(1.0)
D3Dlight9{(1)}.Specular.g% = FN_f4(1.0)
D3Dlight9{(1)}.Specular.b% = FN_f4(1.0)
D3Dlight9{(1)}.Position.x% = FN_f4(-6)
D3Dlight9{(1)}.Position.y% = FN_f4(0)
D3Dlight9{(1)}.Position.z% = FN_f4(6)
D3Dlight9{(1)}.Range% = FN_f4(100)
D3Dlight9{(1)}.Attenuation0% = FN_f4(1)
Light%(1) = D3Dlight9{(1)}
Eye() = 0, 0, 6
LookAt() = 0, 0, 0
REPEAT
Yaw() = -TIME/200
Pitch() = PI/6
PROC_render(pDevice%, &00202020, 2, Light%(), \
\ 3, Material%(), Texture%(), Object%(), nVert%(), Format%(), Size%(), \
\ Yaw(), Pitch(), Roll(), Xpos(), Ypos(), Zpos(), \
\ Eye(), LookAt(), 0.4, 5/4, 1, 1000)
UNTIL INKEY(1)=0
END
DEF PROCcleanup
Texture%(0) += 0:IF Texture%(0) PROC_release(Texture%(0))
Object%(0) += 0 :IF Object%(0) PROC_release(Object%(0))
Object%(1) += 0 :IF Object%(1) PROC_release(Object%(1))
Object%(2) += 0 :IF Object%(2) PROC_release(Object%(2))
pDevice% += 0 :IF pDevice% PROC_release(pDevice%)
ENDPROC