DX Class, VB.net

maen

Newcomer
Joined
Mar 22, 2003
Messages
4
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 :

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:
You posted this same question in the DirectX forum already... not good for only two posts when one of them is a duplicate...

To answer your question though, use DirectX9 not DirectX8. DX8 is not an officially supported SDK for .NET. And doing 3D is going to be hard, so be prepared to work at it. If you want camera movement, zooming, turning objects on/off and more, you're in for a lot of work. I'd start by looking at the samples that come with the DX9 SDK and working through some of the tutorial projects.

There are also a number of 3D "engines" and "libraries" available, but they're all going to be non-trivial to learn. There is no library to say "load this 3D object and let me move it around on the screen" - that's the program that you want, not a programmable library :)

-Nerseus
 
If you're using .NET you should use DirectX 9, it includes managed classes for most dx technologies. Check out the samples, I'm sure there's one that does roughly what you need, it should be enough to get you started.
 
You're not getting the diffuse from the mesh that might be causing the blackness(completely absorbs light)

BTW. I would NOT recommend using DX7 or 8 in VB.Net or C# or J#(or anything else beside C++7), because there are complete incompadibilities and malfunctions in most sections(DirectPlay doesn't work at all). You should use DX9
 
Back
Top