opengl4
This commit is contained in:
+94
-108
@@ -26,155 +26,141 @@ public class Program
|
||||
ImGui.SetNextWindowSize(viewport.WorkSize);
|
||||
ImGui.SetNextWindowViewport(viewport.ID);
|
||||
|
||||
if (ImGui.Begin("MainWindow", ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoBringToFrontOnFocus))
|
||||
ImGui.Begin("MainWindow", ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoBringToFrontOnFocus);
|
||||
if (ImGui.BeginMenuBar())
|
||||
{
|
||||
if (ImGui.BeginMenuBar())
|
||||
if (ImGui.BeginMenu("Stuff"))
|
||||
{
|
||||
if (ImGui.BeginMenu("Stuff"))
|
||||
if (ImGui.MenuItem("Quit"))
|
||||
{
|
||||
if (ImGui.MenuItem("Quit"))
|
||||
{
|
||||
window.ShouldClose = true;
|
||||
}
|
||||
|
||||
ImGui.EndMenu();
|
||||
window.ShouldClose = true;
|
||||
}
|
||||
ImGui.Spacing();
|
||||
ImGui.MenuItem("Demo Window", "", ref _demoWindowVisible);
|
||||
ImGui.Spacing();
|
||||
ImGui.MenuItem("ImPlot Demo Window", "", ref _imPlotDemoVisible);
|
||||
ImGui.Spacing();
|
||||
ImGui.MenuItem("Font Stuff", "", ref _fontStuff);
|
||||
|
||||
ImGui.EndMenuBar();
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
ImGui.Spacing();
|
||||
ImGui.MenuItem("Demo Window", "", ref _demoWindowVisible);
|
||||
ImGui.Spacing();
|
||||
ImGui.MenuItem("ImPlot Demo Window", "", ref _imPlotDemoVisible);
|
||||
ImGui.Spacing();
|
||||
ImGui.MenuItem("Font Stuff", "", ref _fontStuff);
|
||||
|
||||
ImGui.End();
|
||||
ImGui.EndMenuBar();
|
||||
}
|
||||
ImGui.End();
|
||||
|
||||
if (_fontStuff)
|
||||
{
|
||||
ImGui.SetNextWindowSize(new Vector2(250, 500), ImGuiCond.FirstUseEver);
|
||||
if (ImGui.Begin("FontStuff", ref _fontStuff))
|
||||
ImGui.Begin("FontStuff", ref _fontStuff);
|
||||
|
||||
ImGui.ShowFontSelector("Font");
|
||||
|
||||
bool change = false;
|
||||
if (ImGui.GetFont() != _font)
|
||||
{
|
||||
ImGui.ShowFontSelector("Font");
|
||||
_font = ImGui.GetFont();
|
||||
change = true;
|
||||
}
|
||||
|
||||
bool change = false;
|
||||
if (ImGui.GetFont() != _font)
|
||||
string fontName = _font.GetDebugNameS();
|
||||
fontName = string.IsNullOrEmpty(fontName) ? _font.FontId.ToString() : fontName;
|
||||
if (!_initialized || change)
|
||||
{
|
||||
if (!GlyphsByName.TryGetValue(fontName, out List<uint>? glyphs))
|
||||
{
|
||||
_font = ImGui.GetFont();
|
||||
change = true;
|
||||
}
|
||||
glyphs = new List<uint>();
|
||||
|
||||
string fontName = _font.GetDebugNameS();
|
||||
fontName = string.IsNullOrEmpty(fontName) ? _font.FontId.ToString() : fontName;
|
||||
if (!_initialized || change)
|
||||
{
|
||||
if (!GlyphsByName.TryGetValue(fontName, out List<uint>? glyphs))
|
||||
ImFontPtr font = _font;
|
||||
|
||||
for (uint codepoint = 0; codepoint <= 0x10FFFF; codepoint++)
|
||||
{
|
||||
glyphs = new List<uint>();
|
||||
|
||||
ImFontPtr font = _font;
|
||||
|
||||
for (uint codepoint = 0; codepoint <= 0x10FFFF; codepoint++)
|
||||
if (codepoint >= 0xD800 && codepoint <= 0xDFFF)
|
||||
{
|
||||
if (codepoint >= 0xD800 && codepoint <= 0xDFFF)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!font.IsGlyphInFont(codepoint)) continue;
|
||||
|
||||
glyphs.Add(codepoint);
|
||||
continue;
|
||||
}
|
||||
|
||||
GlyphsByName[fontName] = glyphs;
|
||||
Logger.Log($"Initialized font {fontName} with {glyphs.Count} glyphs");
|
||||
if (!font.IsGlyphInFont(codepoint)) continue;
|
||||
|
||||
glyphs.Add(codepoint);
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
GlyphsByName[fontName] = glyphs;
|
||||
Logger.Log($"Initialized font {fontName} with {glyphs.Count} glyphs");
|
||||
}
|
||||
|
||||
ImGui.PushFont(null, 24);
|
||||
|
||||
if (GlyphsByName.TryGetValue(fontName, out List<uint>? glyphs2))
|
||||
{
|
||||
float cursorXStart = ImGui.GetCursorPosX();
|
||||
float maxWidth = ImGui.GetContentRegionAvail().X;
|
||||
|
||||
foreach (uint codepoint in glyphs2!)
|
||||
{
|
||||
string text = char.ConvertFromUtf32((int)codepoint);
|
||||
float glyphWidth = ImGui.CalcTextSize(text).X;
|
||||
|
||||
float cursorX = ImGui.GetCursorPosX();
|
||||
if (cursorX > cursorXStart && (cursorX + glyphWidth) > (cursorXStart + maxWidth))
|
||||
{
|
||||
ImGui.NewLine();
|
||||
}
|
||||
|
||||
ImGui.TextUnformatted(text);
|
||||
|
||||
ImGui.SameLine();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.PopFont();
|
||||
|
||||
ImGui.End();
|
||||
_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui.Begin("Thing"))
|
||||
{
|
||||
float time = (float)ImGui.GetTime() * 5;
|
||||
if (ImPlot.BeginPlot("Moving Rainbow Sine Wave"))
|
||||
ImGui.PushFont(null, 24);
|
||||
|
||||
if (GlyphsByName.TryGetValue(fontName, out List<uint>? glyphs2))
|
||||
{
|
||||
int count = 200;
|
||||
float cursorXStart = ImGui.GetCursorPosX();
|
||||
float maxWidth = ImGui.GetContentRegionAvail().X;
|
||||
|
||||
float[] xs = new float[2];
|
||||
float[] ys = new float[2];
|
||||
|
||||
for (int i = 0; i < count - 1; i++)
|
||||
foreach (uint codepoint in glyphs2!)
|
||||
{
|
||||
float x0 = i * 0.1f;
|
||||
float x1 = (i + 1) * 0.1f;
|
||||
string text = char.ConvertFromUtf32((int)codepoint);
|
||||
float glyphWidth = ImGui.CalcTextSize(text).X;
|
||||
|
||||
float y0 = MathF.Sin(x0 * size + time);
|
||||
float y1 = MathF.Sin(x1 * size + time);
|
||||
float cursorX = ImGui.GetCursorPosX();
|
||||
if (cursorX > cursorXStart && (cursorX + glyphWidth) > (cursorXStart + maxWidth))
|
||||
{
|
||||
ImGui.NewLine();
|
||||
}
|
||||
|
||||
xs[0] = x0;
|
||||
xs[1] = x1;
|
||||
|
||||
ys[0] = y0;
|
||||
ys[1] = y1;
|
||||
|
||||
float t = i / (float)count;
|
||||
|
||||
float r = 0.5f + 1f * MathF.Sin(6.2831f * (t));
|
||||
float g = 0.5f + 1f * MathF.Sin(6.2831f * (t + 0.33f));
|
||||
float b = 0.5f + 1f * MathF.Sin(6.2831f * (t + 0.66f));
|
||||
|
||||
|
||||
ImPlot.PushStyleColor(ImPlotCol.Line, new Vector4(r, g, b, 1f));
|
||||
ImPlot.PlotLine("##seg", ref xs[0], ref ys[0], 2);
|
||||
ImPlot.PopStyleColor();
|
||||
ImGui.TextUnformatted(text);
|
||||
|
||||
ImGui.SameLine();
|
||||
}
|
||||
|
||||
ImPlot.EndPlot();
|
||||
}
|
||||
ImGui.SliderFloat("Sine", ref size, 1f, 120f);
|
||||
|
||||
ImGui.PopFont();
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
if (ImGui.Begin("ImageThing"))
|
||||
ImGui.Begin("Thing");
|
||||
float time = (float)ImGui.GetTime() * 5;
|
||||
if (ImPlot.BeginPlot("Moving Rainbow Sine Wave"))
|
||||
{
|
||||
int count = 200;
|
||||
|
||||
ImGui.End();
|
||||
float[] xs = new float[2];
|
||||
float[] ys = new float[2];
|
||||
|
||||
for (int i = 0; i < count - 1; i++)
|
||||
{
|
||||
float x0 = i * 0.1f;
|
||||
float x1 = (i + 1) * 0.1f;
|
||||
|
||||
float y0 = MathF.Sin(x0 * size + time);
|
||||
float y1 = MathF.Sin(x1 * size + time);
|
||||
|
||||
xs[0] = x0;
|
||||
xs[1] = x1;
|
||||
|
||||
ys[0] = y0;
|
||||
ys[1] = y1;
|
||||
|
||||
float t = i / (float)count;
|
||||
|
||||
float r = 0.5f + 1f * MathF.Sin(6.2831f * (t));
|
||||
float g = 0.5f + 1f * MathF.Sin(6.2831f * (t + 0.33f));
|
||||
float b = 0.5f + 1f * MathF.Sin(6.2831f * (t + 0.66f));
|
||||
|
||||
|
||||
ImPlot.PushStyleColor(ImPlotCol.Line, new Vector4(r, g, b, 1f));
|
||||
ImPlot.PlotLine("##seg", ref xs[0], ref ys[0], 2);
|
||||
ImPlot.PopStyleColor();
|
||||
|
||||
}
|
||||
|
||||
ImPlot.EndPlot();
|
||||
}
|
||||
|
||||
ImGui.SliderFloat("Sine", ref size, 1f, 120f);
|
||||
ImGui.End();
|
||||
|
||||
if (_demoWindowVisible)
|
||||
{
|
||||
ImGui.ShowDemoWindow(ref _demoWindowVisible);
|
||||
|
||||
Reference in New Issue
Block a user