Skip to content

Commit ffefcf7

Browse files
committed
font performance
1 parent 070f865 commit ffefcf7

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/Box2D.NET.Samples/Graphics/Fonts.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static void AddText(ref Font font, float x, float y, B2HexColor color, st
149149
fontText.y = y;
150150
fontText.color = color;
151151
fontText.text = text;
152-
152+
153153
font.texts.Add(fontText);
154154

155155
// if (text == null)
@@ -191,21 +191,25 @@ public static void AddText(ref Font font, float x, float y, B2HexColor color, st
191191

192192
public static void FlushText(GL gl, ref Font font, Camera camera)
193193
{
194+
if (0 >= font.texts.Count)
195+
return;
196+
197+
ImGui.Begin("Overlay",
198+
ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.AlwaysAutoResize |
199+
ImGuiWindowFlags.NoScrollbar);
200+
194201
foreach (var text in font.texts)
195202
{
196-
ImGui.Begin("Overlay",
197-
ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.AlwaysAutoResize |
198-
ImGuiWindowFlags.NoScrollbar);
199-
200203
int hex = (int)text.color;
201204
float r = ((hex >> 16) & 0xFF) / 255.0f;
202205
float g = ((hex >> 8) & 0xFF) / 255.0f;
203206
float b = (hex & 0xFF) / 255.0f;
204207

205208
ImGui.SetCursorPos(new Vector2(text.x, text.y));
206209
ImGui.TextColored(new Vector4(r, g, b, 1.0f), text.text);
207-
ImGui.End();
208210
}
211+
212+
ImGui.End();
209213
font.texts.Clear();
210214

211215
// var tempProjectionMatrix = new B2FixedArray16<float>();

0 commit comments

Comments
 (0)