Archived

This topic is now archived and is closed to further replies.

Mesh not visible (D3D8)

This topic is 5041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all. I'm having trubles getting my mesh to display. Yesterday it worked perfectly, but (apprently) i have had to change something since it aint working now. I tested most stuff (No culling, Camera Position, etc), but none of them are giving any results. Althought it wouldent suprise me if the camera is setup wrong... Anyways, here is some (VB6) code:
Dim MeshY As New clsMesh

Public Sub Init()
Dim DispMode As D3DDISPLAYMODE
Dim D3DWindow As D3DPRESENT_PARAMETERS

Set DX = New DirectX8
Set D3DX = New D3DX8
Set D3D = DX.Direct3DCreate()

D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DispMode
D3DWindow.Windowed = 1
D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
D3DWindow.BackBufferFormat = DispMode.Format

Set Device = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Picture1.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)

Call InitScene
Call MeshY.Load("C:\Nicw.x")
End Sub

Public Sub InitScene()
Dim Mtrl As D3DMATERIAL8
Dim Col As D3DCOLORVALUE
Dim Lights As D3DLIGHT8

D3DXMatrixIdentity matWorld
D3DXMatrixIdentity matView
D3DXMatrixIdentity matOrth

D3DXMatrixLookAtLH matView, D3DVec(1, 1, 1), D3DVec(0, 0, 0), D3DVec(0, 1, 0)
D3DXMatrixOrthoLH matOrth, 16, 12, -3.5, 3.5

Device.SetTransform D3DTS_VIEW, matView
Device.SetTransform D3DTS_PROJECTION, matOrth
Device.SetTransform D3DTS_WORLD, matWorld

Device.SetRenderState D3DRS_LIGHTING, True
'Device.SetRenderState D3DRS_ZENABLE, True
Device.SetRenderState D3DRS_AMBIENT, &HFFFFFF
Device.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE

Col.a = 1: Col.r = 1: Col.g = 1: Col.b = 1
Mtrl.Ambient = Col
Mtrl.diffuse = Col

Lights.Type = D3DLIGHT_DIRECTIONAL
Lights.diffuse.r = 1
Lights.diffuse.g = 1
Lights.diffuse.b = 1
Lights.Direction = D3DVec(0, -1, 0)

Device.SetMaterial Mtrl
Device.SetLight 0, Lights
Device.LightEnable 0, True
End Sub

Public Sub Render()
Call Device.Clear(0, ByVal 0, D3DCLEAR_TARGET, &H0, 0, 0)
Call Device.BeginScene
    Call MeshY.Render
Call Device.EndScene
Call Device.Present(ByVal 0, ByVal 0, 0, ByVal 0)
End Sub
The clsMesh Class
Public Sub Load(ByVal xFile As String)
Dim mtrlBuffer As D3DXBuffer
Dim TextureFile As String
Dim I As Long

Set mvarMesh = D3DX.LoadMeshFromX(xFile, D3DXMESH_MANAGED, Device, Nothing, mtrlBuffer, mvarNMaterials)

ReDim mvarMeshMaterials(0 To mvarNMaterials - 1) As D3DMATERIAL8
ReDim mvarMeshTextures(0 To mvarNMaterials - 1) As Direct3DTexture8

Call Device.SetVertexShader(mvarMesh.GetFVF)

For I = 0 To mvarNMaterials - 1
    D3DX.BufferGetMaterial mtrlBuffer, I, mvarMeshMaterials(I)
    mvarMeshMaterials(I).Ambient = mvarMeshMaterials(I).diffuse
    TextureFile = D3DX.BufferGetTextureName(mtrlBuffer, I)
    Set mvarMeshTextures(I) = D3DX.CreateTextureFromFileEx(Device, "C:\Dummy.bmp", 0, 0, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_LINEAR, D3DX_FILTER_LINEAR, 0, ByVal 0, ByVal 0)
Next
End Sub

Public Sub Render()
Dim matTemp As D3DMATRIX
Dim X As Long

Call D3DXMatrixIdentity(mvarMatObject)
    Call D3DXMatrixIdentity(matTemp)
        Call D3DXMatrixScaling(matTemp, 1, 1, 1)
        Call D3DXMatrixMultiply(mvarMatObject, mvarMatObject, matTemp)
    Call D3DXMatrixIdentity(matTemp)
        Call D3DXMatrixTranslation(matTemp, mvarObjPos.X, mvarObjPos.Y, mvarObjPos.Z)
        Call D3DXMatrixMultiply(mvarMatObject, mvarMatObject, matTemp)
Call Device.SetTransform(D3DTS_WORLD, mvarMatObject)

For X = 0 To mvarNMaterials - 1
    Call Device.SetMaterial(mvarMeshMaterials(X))
    Call Device.SetTexture(0, mvarMeshTextures(X))
    Call mvarMesh.DrawSubset(X)
Next
End Sub
[edited by - SWEDarwishi on February 22, 2004 8:16:30 PM]

Share this post


Link to post
Share on other sites