diff --git a/src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs b/src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs index 829b83b..4e8afbb 100644 --- a/src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs +++ b/src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs @@ -339,6 +339,11 @@ namespace ImGuiNET.SampleProgram.XNA { ImDrawCmdPtr drawCmd = cmdList.CmdBuffer[cmdi]; + if (drawCmd.ElemCount == 0) + { + continue; + } + if (!_loadedTextures.ContainsKey(drawCmd.TextureId)) { throw new InvalidOperationException($"Could not find a texture with id '{drawCmd.TextureId}', please check your bindings"); @@ -360,19 +365,18 @@ namespace ImGuiNET.SampleProgram.XNA #pragma warning disable CS0618 // // FNA does not expose an alternative method. _graphicsDevice.DrawIndexedPrimitives( primitiveType: PrimitiveType.TriangleList, - baseVertex: vtxOffset, + baseVertex: (int)drawCmd.VtxOffset + vtxOffset, minVertexIndex: 0, numVertices: cmdList.VtxBuffer.Size, - startIndex: idxOffset, + startIndex: (int)drawCmd.IdxOffset + idxOffset, primitiveCount: (int)drawCmd.ElemCount / 3 ); #pragma warning restore CS0618 } - - idxOffset += (int)drawCmd.ElemCount; } vtxOffset += cmdList.VtxBuffer.Size; + idxOffset += cmdList.IdxBuffer.Size; } } diff --git a/src/ImGui.NET.SampleProgram/ImGuiController.cs b/src/ImGui.NET.SampleProgram/ImGuiController.cs index 4cbe615..6fe41de 100644 --- a/src/ImGui.NET.SampleProgram/ImGuiController.cs +++ b/src/ImGui.NET.SampleProgram/ImGuiController.cs @@ -520,12 +520,11 @@ namespace ImGuiNET (uint)(pcmd.ClipRect.Z - pcmd.ClipRect.X), (uint)(pcmd.ClipRect.W - pcmd.ClipRect.Y)); - cl.DrawIndexed(pcmd.ElemCount, 1, (uint)idx_offset, vtx_offset, 0); + cl.DrawIndexed(pcmd.ElemCount, 1, pcmd.IdxOffset + (uint)idx_offset, (int)pcmd.VtxOffset + vtx_offset, 0); } - - idx_offset += (int)pcmd.ElemCount; } vtx_offset += cmd_list.VtxBuffer.Size; + idx_offset += cmd_list.IdxBuffer.Size; } }