Tron, the directX tutorial
In this second chapter us use some frames, light and a X file to create a animation scene
 
No Spot lights
Direcctional light

About frames: 
A frame is a 3d buffer to render the scene in the correct perspective, the frame have a object abilities , you can link some frame with another , any change in the master frame modifies the child frame.You can move and rotate all the frames. Light and camera are a frame and have all frames abilities.

To facility the work, us create some functions, use this function on your next programs.

InicializarVideo(Horitzontal As Integer, Vertical As Integer)
This function is used to initialize Direct 3d and Direct Draw, have two parameters Horizontal and Vertical . Horizontal is a screen width , Verticas is a screen height 
Inicizentorno()
Tuned the system , link the frames ,  objects load, create light etc..
Accion()
Running the system
CargarX(StrNombreX As String)
Load any *.x file . read about Conv3ds on sorgonet.com
To load files x with textures, you need that the texture files is in the same directory that to the  X file.
LuzAmbiente(rojo As Single, verde As Single, Blue As Single)
Make an environmental light, the parameters are the light color.
luzdirecciona(rojo As Single, verde As Single, azul As Single)
Make a POINT  light, the parameters are the light color
Point light, Directional light and Spot light  are available..
 

 

 
 
FORM1
Private Sub Form_Load()
IntHoritzontal = 800
IntVertical = 600
InicializarVideo IntHoritzontal, IntVertical
Inicizentorno 'call to Inicizentorno
Do While DoEvents
'infinite loop calling Accion function
Accion
Loop
End Sub
 
 

MODULE
Option Explicit
'chapter 1 definitions
Public IntHoritzontal As Integer
Public IntVertical As Integer
Public Direct As New DirectX7
Public Ddraw As DirectDraw4
Public Ddrm As Direct3DRM3
Public DDclipper As DirectDrawClipper
Public DDsurface As DirectDrawSurface4
Public DDsurfacesec As DirectDrawSurface4
Public DDSDsurface As DDSURFACEDESC2
Public DDSCAP As DDSCAPS2
Public RMDevice As Direct3DRMDevice3
Public RMViewport As Direct3DRMViewport2

'New definitions
Public Textureim As Direct3DRMLoadTextureCallback3 'to load textures
Public MeshCargar As Direct3DRMMeshBuilder3 ' to get the *.x mesh
Public FramePrincipal As Direct3DRMFrame3 'frame to working and link another frames
Public Camara As Direct3DRMFrame3 'Camera frame to link with viewport
Public FrameCargar As Direct3DRMFrame3 'frame to link mesh with FramePrincipal
Public LuzAmbiental As Direct3DRMLight ' to make a  environmental light
Public Luz1 As Direct3DRMLight ' to make a movile light

'The INICIALIZARVIDEO commands are explainet in the first chapter tutorial
Public Function InicializarVideo(Horitzontal As Integer, Vertical As Integer)
Set Ddraw = Direct.DirectDraw4Create("")
Form1.Show
Ddraw.SetCooperativeLevel Form1.hWnd, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE
Ddraw.SetDisplayMode Horitzontal, Vertical, 16, 0, DDSDM_DEFAULT
DDSDsurface.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
DDSDsurface.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_3DDEVICE Or DDSCAPS_COMPLEX Or DDSCAPS_FLIP
DDSDsurface.lBackBufferCount = 1
Set DDsurface = Ddraw.CreateSurface(DDSDsurface)
DDSCAP.lCaps = DDSCAPS_BACKBUFFER
Set DDsurfacesec = DDsurface.GetAttachedSurface(DDSCAP)
Set Ddrm = Direct.Direct3DRMCreate()
Set RMDevice = Ddrm.CreateDeviceFromSurface("IID_IDirect3DHALDevice", Ddraw, DDsurfacesec, D3DRMDEVICE_DEFAULT)
RMDevice.SetBufferCount 2
RMDevice.SetQuality D3DRMLIGHT_ON Or D3DRMFILL_SOLID Or D3DRMSHADE_GOURAUD Or D3DRMSHADE_MAX
RMDevice.SetTextureQuality D3DRMTEXTURE_MIPNEAREST
RMDevice.SetRenderMode D3DRMRENDERMODE_DEFAULT
End Function

Public Function Inicizentorno()
Set FramePrincipal = Ddrm.CreateFrame(Nothing) 'Make a master frame
Set Camara = Ddrm.CreateFrame(FramePrincipal) 'Link the camera frame with the master frame
Set RMViewport = Ddrm.CreateViewport(RMDevice, Camara, 0, 0, IntHoritzontal, IntVertical)'link the viewport with camera frame
RMViewport.Clear D3DRMCLEAR_TARGET Or D3DRMCLEAR_ZBUFFER 'delete the viewport
RMViewport.SetBack 5000 'select how far see you
CargarX "/torre.x" 'call to CargarX function
FrameCargar.SetPosition FramePrincipal, 0, 0, 0 'select the Master frame position
FrameCargar.SetRotation FramePrincipal, 0, 1, 0, 0.01 'select a Master frame rotation
Camara.SetPosition FramePrincipal, 0, 0, -300 ' select a Camera frame position
luzdirecciona 0.8, 0.8, 0.8 'call to luzdirecciona function
LuzAmbiente 0.1, 0.1, 0.1 'call to LuzAmbiente function
End Function

Public Function Accion()
RMViewport.Clear D3DRMCLEAR_TARGET Or D3DRMCLEAR_ZBUFFER 'clear a viewport
RMDevice.Update 'update the viewport
RMViewport.Render FramePrincipal 'render a Master frame
Ddrm.Tick 1 'select another animation step
DDsurface.Flip Nothing, DDFLIP_WAIT
End Function

Public Function CargarX(StrNombreX As String)
Set FrameCargar = Ddrm.CreateFrame(FramePrincipal) 'link FrameCargar with Master frame
Set MeshCargar = Ddrm.CreateMeshBuilder() 'Create a memori space to load *.x
MeshCargar.LoadFromFile App.Path & StrNombreX, 0, D3DRMLOAD_ASYNCHRONOUS, Textureim, Nothing'load a objet
MeshCargar.SetPerspective D_TRUE 'correct the perpective
FrameCargar.AddVisual MeshCargar 'link the MeshCargar dato with Framecargar
End Function

Public Function LuzAmbiente(rojo As Single, verde As Single, Blue As Single)
Set LuzAmbiental = Ddrm.CreateLightRGB(D3DRMLIGHT_AMBIENT, rojo, verde, Blue) 'create a Ambient light
FramePrincipal.AddLight LuzAmbiental 'link the new light with master Frame
End Function

Public Function luzdirecciona(rojo As Single, verde As Single, azul As Single)
Set Luz1 = Ddrm.CreateLightRGB(D3DRMLIGHT_POINT, rojo, verde, azul) 'create a POINT light
Luz1.SetUmbra 0.0001 'select umbra
Luz1.SetPenumbra 0.0001 'select Penumbra
Camara.AddLight Luz1 'link the light with Camera Frame
End Function
 
 
Correct lights
Rotation

 

You can download a source code.
 

by Necro_
www.sorgonet.com