Hi, I'm experiencing some problems trying to render a mesh. The application fails with "Invalid Call" at .drawsubset(0). I can view the mesh in the meshviewer that comes with the DXSDK. I'm using a real simple effect at the moment, however the mesh contains normals and such which the effect does not use, could this be a cause? I have also tried rendering other meshes without success. Also, how do you make custom vertices in SlimDX, used to be something like vertex = new customvertex.PositionTextured(...) but I can not find it now, just wanted to see if I can render anything at all. Thanks for looking.
Here's the whole application:
Imports SlimDX
Imports SlimDX.Direct3D9
Public Class Form1
Private D3DDevice As Device
Private DefaultEffect As Effect
Private GameRunning As Boolean = True
Private TestMesh As Mesh
Private WorldMatrix As Matrix = Matrix.Identity
Private ProjMatrix As Matrix = Matrix.PerspectiveFovLH(Math.PI / 4, 1, 10, 1000)
Private ViewMatrix As Matrix = Matrix.LookAtLH(New Vector3(0, 500, -500), New Vector3(0, 0, 0), New Vector3(0, 1, 0))
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
GameRunning = False
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Me.Focus()
Direct3D.Initialize()
Dim D3DPP As New PresentParameters
With D3DPP
.Windowed = True
.SwapEffect = SwapEffect.Discard
.AutoDepthStencilFormat = Format.D24X8
.EnableAutoDepthStencil = True
End With
D3DDevice = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.HardwareVertexProcessing, D3DPP)
With D3DDevice
.SetTransform(TransformState.Projection, ProjMatrix)
.SetTransform(TransformState.View, ViewMatrix)
.SetTransform(TransformState.World, WorldMatrix)
.SetRenderState(RenderState.ZEnable, True)
End With
DefaultEffect = Effect.FromFile(D3DDevice, "defaulteffect.fx", Nothing, Nothing,_
ShaderFlags.Debug, ShaderFlags.None, Nothing, Nothing)
DefaultEffect.Technique = "simple"
DefaultEffect.SetValue("worldViewProj", WorldMatrix * ViewMatrix * ProjMatrix)
DefaultEffect.CommitChanges()
TestMesh = Mesh.FromFile(D3DDevice, "spaceship.x", MeshFlags.Managed)
While GameRunning = True
Application.DoEvents()
D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Black, 1, 0)
DefaultEffect.Begin(FX.None)
DefaultEffect.BeginPass(0)
TestMesh.DrawSubset(0)
DefaultEffect.EndPass()
DefaultEffect.End()
D3DDevice.Present()
End While
If DefaultEffect.Disposed = False Then
DefaultEffect.Dispose()
End If
If TestMesh.Disposed = False Then
TestMesh.Dispose()
End If
If D3DDevice.Disposed = False Then
D3DDevice.Dispose()
End If
End
End Sub
End Class
And here's the effect, from MDXInfo
float4x4 worldViewProj : WORLDVIEWPROJ; //our world view projection matrix
//application to vertex structure
struct a2v
{
float4 position : POSITION0;
};
//vertex to pixel processing structure
struct v2p
{
float4 position : POSITION0;
};
//VERTEX SHADER
void vs( in a2v IN, out v2p OUT )
{
//transforming our position from object space to screen space.
OUT.position = mul(IN.position, worldViewProj);
}
technique simple
{
pass p0
{
vertexshader = compile vs_1_1 vs();
}
}
[Edited by - JustMe1984 on August 5, 2007 2:59:31 AM]