Now that we have the basics, time to wrap textures around our object.
To do this, all we need is a .BMP file for our texture. There's a few important
points to note, First, width and height of bitmap must be equal, and secondly, they must
be powers of 2 (ie. 32x32, 256x256, etc.). This is obviously for optimization reasons,
but don't ask me, I didn't create Direct3D. Anyway, to wrap this texture around our
object, we just need to modify the above code a bit (changes are noted in Blue):
' Wrap textures around 3D object
$TYPECHECK ON
CONST alClient = 5
'-- Light Types
CONST D3DRMLIGHT_AMBIENT = 0
CONST D3DRMLIGHT_POINT = 1
CONST D3DRMLIGHT_SPOT = 2
CONST D3DRMLIGHT_DIRECTIONAL = 3
CONST D3DRMLIGHT_PARALLELPOINT = 4
'-- Wrap Types
CONST D3DRMWRAP_FLAT = 0
CONST D3DRMWRAP_CYLINDER = 1
CONST D3DRMWRAP_SPHERE = 2
CONST D3DRMWRAP_CHROME = 3
CONST D3DRMWRAP_SHEET = 4
CONST D3DRMWRAP_BOX = 5
CONST WrapType = D3DRMWRAP_SPHERE '-- You can modify this
DECLARE SUB DXInitialize(Sender AS QDXScreen)
DECLARE SUB DXTimerExpired
DIM DXTimer AS QDXTimer
DXTimer.Enabled = 1
DXTimer.Interval = 0
DXTimer.Activeonly = 0
DXTimer.OnTimer = DXTimerExpired
CREATE Form AS QForm
Caption = "Direct 3D Example"
Center
CREATE DXScreen AS QDXScreen
Init(320,240)
Align = alClient
Use3D = 1
UseHardware = 0 '' This is for non-3D accelerated video cards.
'' 3D will be emulated using software, which
'' is much slower.
OnInitialize = DXInitialize
END CREATE
ShowModal
END CREATE
SUB DXInitialize(Sender AS QDXScreen)
DIM Light AS QD3DLight
DIM LightFrame AS QD3DFrame, MeshFrame AS QD3DFrame
DIM MeshBuilder AS QD3DMeshBuilder
DIM Texture AS QD3DTexture
DIM Wrap AS QD3DWrap
DIM Mesh AS QD3DMesh
DXScreen.CreateFrame(LightFrame)
DXScreen.CreateFrame(MeshFrame)
DXScreen.CreateLightRGB(D3DRMLIGHT_DIRECTIONAL, 0.9, 0.9, 0.9, Light)
LightFrame.AddLight(Light)
DXScreen.SetCameraPosition(-5, 10, 0)
DXScreen.SetCameraOrientation(0.35, -0.65, 1.0, -0.15, 1.0, 0.5)
MeshFrame.SetPosition(0, 0, 15)
MeshFrame.SetOrientation(0, 0, 1, 0, 1, 0)
MeshFrame.SetRotation(0, 0, 0, 0.05) ' Angle of rotation = 0.05
DXScreen.CreateMeshBuilder(MeshBuilder)
MeshBuilder.Load("poly.x") '-- Egg object
MeshBuilder.LoadTexture("back.bmp") '-- New lines
MeshBuilder.CreateMesh(Mesh)
MeshFrame.AddVisual(Mesh)
DXScreen.CreateWrap(WrapType, 0,0,0, 0,0,1, 0,1,0, 0,0, 1,1, Wrap)
Wrap.Apply(Mesh)
END SUB
SUB DXTimerExpired
DXScreen.ForceUpdate(0,0,50,50)
DXScreen.Render
DXScreen.TextOut(10,10,"FPS: "+STR$(DXTimer.FrameRate), &HFFFFFF, -1)
DXScreen.Flip
END SUB
Again, if everything worked, you should obtain some output that looks like this (depending
on what texture file you used of course):
As you can see, it doesn't take much to add textures to our objects.
The only problem is you lose a few frame rates by doing this.
13.5 Rotating/Moving objects
Unfortunately as of this writing, there is no support for Animation sets, but
that will be worked on later. You can do simple rotations and scene movements just
by calling the method Move or manually setting the camera angles and
positions. Using the example from above, add this extra code:
DXScreen.ForceUpdate(0,0,50,50)
DXScreen.Move(1) '-- Add this line
DXScreen.Render
This moves the camera position by the amount specified. The affect is a rotation
about angle Theta. This Theta was specified on the line:
MeshFrame.SetRotation(0, 0, 0, 0.05) ' Angle of rotation = 0.05
DXScreen.Move animates the entire scene, to just animate a certain frame, you
can use MeshFrame.Move(1).