Ques, About DX8.1 With VB.Net
A very good day to all of you ..
I want to make a program that can view 3D objects , with zoom , rotation , and rendering features, it is a program that
deal with the anatomy of the body ,
I had made a 3ds object using 3DSMax , and convert it to .x type , I am using VB .net , with DirectX 8.1 , but I don't have
the DirectX 8.1 SDK and the Help Functions of it ,
I could load the mesh and do some transformations by applying Matrices, but my problem is that my object is all black
even I had applied a texture to it , and light object I created , but it still totally black , I tried to apply a texture in 3DSMax
and load it in my code but it didn't work .
here is my code , I would be greatful to anyone give me help ( Since I am not an expert in DirectX )
Thank you very much .
The Code :
A very good day to all of you ..
I want to make a program that can view 3D objects , with zoom , rotation , and rendering features, it is a program that
deal with the anatomy of the body ,
I had made a 3ds object using 3DSMax , and convert it to .x type , I am using VB .net , with DirectX 8.1 , but I don't have
the DirectX 8.1 SDK and the Help Functions of it ,
I could load the mesh and do some transformations by applying Matrices, but my problem is that my object is all black
even I had applied a texture to it , and light object I created , but it still totally black , I tried to apply a texture in 3DSMax
and load it in my code but it didn't work .
here is my code , I would be greatful to anyone give me help ( Since I am not an expert in DirectX )
Thank you very much .
The Code :
Visual Basic:
g_D3D = g_DX.Direct3DCreate
'=============================================================================
Dim Mode As DxVBLibA.D3DDISPLAYMODE
Const D3DADAPTER_DEFAULT As DxVBLibA.CONST_D3DCONST = 0
g_D3D.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, Mode)
'=============================================================================
Dim d3dpp As DxVBLibA.D3DPRESENT_PARAMETERS
Const D3DSWAPEFFECT_COPY_VSYNC As DxVBLibA.CONST_D3DSWAPEFFECT = 4
d3dpp.Windowed = 1
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
d3dpp.BackBufferFormat = Mode.Format
'=============================================================================
Const D3DDEVTYPE_HAL As DxVBLibA.CONST_D3DDEVTYPE = 1
Const D3DCREATE_SOFTWARE_VERTEXPROCESSING As DxVBLibA.CONST_D3DCREATEFLAGS = 32
g_D3DDevice = g_D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Me.Handle.ToInt32(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp)
'=============================================================================
g_Mesh = g_D3DX.LoadMeshFromX("D:\box.x", D3DXMESH_MANAGED, g_D3DDevice, D3DXB, MtrlBuffer, g_NumMaterials)
ReDim g_MeshMaterials(g_NumMaterials)
ReDim g_MeshTextures(g_NumMaterials)
For i = 0 To g_NumMaterials - 1
g_D3DX.BufferGetMaterial(MtrlBuffer, i, g_MeshMaterials(i))
g_MeshMaterials(i).ambient = g_MeshMaterials(i).diffuse
g_MeshTextures(i) = g_D3DX.CreateTextureFromFile(g_D3DDevice, "D:\tiger.bmp")
Next i
MtrlBuffer = Nothing
' Use the same color settings for all emitted light color.
With c
.r = 1.0# : .g = 1.0# : .b = 1.0#
.a = 1.0# ' The alpha component isn't used for lights.
End With
With vPos
.x = -1 : .y = -1 : .z = -1
End With
With LightDesc
.Type = 3
.Position = vPos
.Direction.x = 0.1
.Direction.y = 0.1
.Direction.z = 0
.ambient = c : .diffuse = c : .specular = c
.Attenuation0 = 1.0# ' Don't attenuate the light
.Range = 200
End With
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
g_D3D = Nothing
g_D3DDevice = Nothing
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim math As Math
Dim mat As DxVBLibA.D3DMATRIX
Dim n As Double
For n = -1.5 To 1.5 Step 0.1 '6.28 Step 3.14 / 90
g_D3DDevice.Clear(0, System.IntPtr.Zero, DxVBLibA.CONST_D3DCLEARFLAGS.D3DCLEAR_TARGET, &HFF&, 1.0#, 0)
vPos.x = 10 * math.Cos(n)
vPos.y = 10 * math.Sin(n)
LightDesc.Position = vPos
mat.m11 = 1 : mat.m12 = 0 : mat.m13 = 0 : mat.m14 = 0
mat.m21 = 0 : mat.m22 = 1 : mat.m23 = 0 : mat.m24 = 0
mat.m31 = n : mat.m32 = 0 : mat.m33 = 0 : mat.m34 = 0
mat.m41 = 0 : mat.m42 = 0 : mat.m43 = 0 : mat.m44 = 14
g_D3DDevice.SetTransform(2, mat)
g_D3DDevice.BeginScene()
For i = 0 To g_NumMaterials - 1
g_D3DDevice.SetMaterial(g_MeshMaterials(i))
g_D3DDevice.SetTexture(0, g_MeshTextures(i))
g_D3DDevice.SetTextureStageState(0, 1, 1)
g_D3DDevice.SetLight(0, LightDesc)
g_D3DDevice.SetRenderState(139, &H202020)
g_Mesh.DrawSubset(i)
Next
g_D3DDevice.EndScene()
g_D3DDevice.Present(System.IntPtr.Zero, System.IntPtr.Zero, 0, System.IntPtr.Zero)
Next n
End Sub
Last edited by a moderator: