View Full Version : Environment mapping with DirectX8.1?

02 February 2004, 05:33 AM
I have a mesh loaded up like so

Public Sub Create350ZMesh()

Dim xfName As String
Dim nMaterials As Long
Dim mtrlBuffer As D3DXBuffer
Dim meshMat As D3DMATERIAL8
Dim i As Long

GameDebugger.WriteLine "Loading 350Z into memory"

UpdateProgressbar "Loading 350Z Mesh", 0

OnLoadStep = 0

With Car350Z

'load the body mesh to .body
xfName = App.Path & "\Models\350Z.x"
Set .Body = d3dx.LoadMeshFromX(xfName, D3DXMESH_MANAGED, d3dDevice, Nothing, mtrlBuffer, nMaterials)
OnLoadStep = OnLoadStep + 1
UpdateProgressbar "Loading 350Z Mesh", OnLoadStep

'apply any textures the body requires
ReDim .BodyTexture(nMaterials)
ReDim .BodyTextureName(nMaterials)
ReDim .BodyMaterial(nMaterials)
.Bodymaterials = nMaterials
For i = 0 To nMaterials - 1
OnLoadStep = OnLoadStep + 1
UpdateProgressbar "Loading 350Z Mesh", OnLoadStep
d3dx.BufferGetMaterial mtrlBuffer, i, meshMat
meshMat.Ambient = meshMat.diffuse
.BodyMaterial(i) = meshMat
xfName = d3dx.BufferGetTextureName(mtrlBuffer, i)
.BodyTextureName(i) = xfName
d3dDevice.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1
If Len(xfName) > 0 Then
Set .BodyTexture(i) = d3dx.CreateTextureFromFile(d3dDevice, App.Path & "\Models\" & xfName)
End If
Next i

GameDebugger.WriteLine "Loaded 350Z into memory finished without error"

End Sub

The mesh is of the type

Private Type ModelMesh
Body As D3DXMesh
BackTires As D3DXMesh
FrontPassengerTire As D3DXMesh
FrontDriverTire As D3DXMesh
BodyTexture() As Direct3DTexture8
BodyReflection As Direct3DTexture8
TireBump As Direct3DTexture8
BackTiresTexture() As Direct3DTexture8
FrontDriverTireTexture() As Direct3DTexture8
FrontPassengerTexture() As Direct3DTexture8
BodyTextureName() As String
BackTiresTextureName() As String
FrontDriverTireTextureName() As String
FrontPassengerTextureName() As String
BodyMaterial() As D3DMATERIAL8
BackTiresMaterial() As D3DMATERIAL8
FrontDriverMaterial() As D3DMATERIAL8
FrontPassengerMaterial() As D3DMATERIAL8
Bodymaterials As Long
BackTiresmaterials As Long
FrontDrivermaterials As Long
FrontPassengermaterials As Long
UnitMeshName As String
End Type

Its rendered in the render loop by

With Car350Z
'draw the body
D3DXMatrixIdentity matTemp
D3DXMatrixRotationY matTemp, .Rotation
D3DXMatrixTranslation matTrans, .X, .Y, .z
D3DXMatrixMultiply matTemp, matTemp, matTrans
d3dDevice.SetTransform D3DTS_WORLD, matTemp
For i = 0 To .Bodymaterials - 1
d3dDevice.SetMaterial .BodyMaterial(i)
d3dDevice.SetTexture 0, .BodyTexture(i)
.Body.DrawSubset i
Next i
End With

I've been looking around at the MSDN archive but its so elusive. Any ideas? I'm hoping I can load a environment map and apply it to the model much like a regular texture map. Is that possible?

03 March 2004, 10:13 AM
Maybe U will find the "sphere mapping" useful. There's a sample in the Dx SDK named "SphereMap Sample" (

03 March 2004, 07:35 AM
Wow this is even better then I was expecting. Except I was only able to dig up a .net version of the dx sdk. I guess its time to bone up on it so I can translate it to plain old vb. Thanks for the helping hand.

CGTalk Moderation
01 January 2006, 03:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.