我正在创建一个Minecraft克隆版,每当我移动相机时,如果显示速度有点快,那么这些块之间会有很大的撕裂:
每个块都是32x32x32立方体,并且对于每种立方体都有一个顶点缓冲区,以防它重要。我也在屏幕上绘制2D文本,我了解到我必须为每种绘图设置图形设备状态。以下是我绘制立方体的方法:
GraphicsDevice.Clear(Color.LightSkyBlue);
#region 3D
// Set the device
device.BlendState = BlendState.Opaque;
device.DepthStencilState = DepthStencilState.Default;
device.RasterizerState = RasterizerState.CullCounterClockwise;
// Go through each shader and draw the cubes of that style
lock (GeneratedChunks)
{
foreach (KeyValuePair<CubeType, BasicEffect> KVP in CubeType_Effect)
{
// Iterate through each technique in this effect
foreach (EffectPass pass in KVP.Value.CurrentTechnique.Passes)
{
// Go through each chunk in our chunk map, and pluck out the cubetype we care about
foreach (Vector3 ChunkKey in GeneratedChunks)
{
if (ChunkMap[ChunkKey].CubeType_TriangleCounts[KVP.Key] > 0)
{
pass.Apply(); // assign it to the video card
KVP.Value.View = camera.ViewMatrix;
KVP.Value.Projection = camera.ProjectionMatrix;
KVP.Value.World = worldMatrix;
device.SetVertexBuffer(ChunkMap[ChunkKey].CubeType_VertexBuffers[KVP.Key]);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, ChunkMap[ChunkKey].CubeType_TriangleCounts[KVP.Key]);
}
}
}
}
}
#endregion
如果我站着不动,世界看起来很好。我想这可能是因为我处于窗口模式,但是当我切换全屏时问题仍然存在。我还假设XNA本身是双缓冲的吗?或者谷歌告诉我。
答案 0 :(得分:1)
我有一个类似的问题 - 我发现在设置所有效果的参数后我必须调用pass.Apply()...
答案 1 :(得分:0)
到目前为止,修复程序一直使用1个巨型顶点缓冲区。我不喜欢它,但这似乎都有效。