我把MaterialsAndLightsSample示例中的代码改为4.0后,怎么无法显示物体,不知道是那个地方没有搞对?
谁有4.0版本的代码?
核心代码改动
//graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;
//graphics.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
//4.0
graphics.GraphicsDevice.BlendState = BlendState.Opaque;
graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
viewParameter.SetValue(camera.ViewMatrix);
cameraPositionParameter.SetValue(camera.Position);
for (int i = 0; i < 8; i++)
{
Matrix world = meshRotation * meshWorlds[i];
materials[(i + materialRotation) % 8].DrawModelWithMaterial(
sampleMeshes[i % 4], ref world);
}
floorMaterial.DrawModelWithMaterial(sampleMeshes[0], ref floorWorld);
。。。。。
public void DrawModelWithMaterial(Model model, ref Matrix world)
{
if (model == null)
{
throw new ArgumentNullException("model");
}
ModelMesh mesh = model.Meshes[0];
ModelMeshPart meshPart = mesh.MeshParts[0];
device.SamplerStates[0] = SamplerState.LinearWrap;
//device.Vertices[0].SetSource(
// mesh.VertexBuffer, meshPart.StreamOffset, meshPart.VertexStride);
//device.VertexDeclaration = meshPart.VertexDeclaration;
device.SetVertexBuffer(meshPart.VertexBuffer);
device.Indices = meshPart.IndexBuffer;
effectInstance.Parameters["world"].SetValue(world);
//effectInstance.Begin(SaveStateMode.None);
//effectInstance.CurrentTechnique.Passes[0].Begin();
effectInstance.CurrentTechnique.Passes[0].Apply();
device.DrawIndexedPrimitives(
PrimitiveType.TriangleList, meshPart.VertexOffset, 0,
meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount);
。。。。