-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathWindow.cs
More file actions
139 lines (119 loc) · 4.8 KB
/
Copy pathWindow.cs
File metadata and controls
139 lines (119 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using Dear_ImGui_Sample.Backends;
using ImGuiNET;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Dear_ImGui_Sample
{
public class Window : GameWindow
{
public Window() : base(GameWindowSettings.Default, new NativeWindowSettings(){ ClientSize = new Vector2i(1600, 900), APIVersion = new Version(3, 3) })
{ }
protected override void OnLoad()
{
base.OnLoad();
Title += ": OpenGL Version: " + GL.GetString(StringName.Version);
GL.DebugMessageCallback(DebugProcCallback, IntPtr.Zero);
GL.Enable(EnableCap.DebugOutput);
GL.Enable(EnableCap.DebugOutputSynchronous);
ImGui.CreateContext();
ImGuiIOPtr io = ImGui.GetIO();
io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags.NavEnableGamepad;
io.ConfigFlags |= ImGuiConfigFlags.DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable;
ImGui.StyleColorsDark();
ImGuiStylePtr style = ImGui.GetStyle();
if ((io.ConfigFlags & ImGuiConfigFlags.ViewportsEnable) != 0)
{
style.WindowRounding = 0.0f;
style.Colors[(int)ImGuiCol.WindowBg].W = 1.0f;
}
ImguiImplOpenTK4.Init(this);
ImguiImplOpenGL3.Init();
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
ImguiImplOpenGL3.NewFrame();
ImguiImplOpenTK4.NewFrame();
ImGui.NewFrame();
ImGui.DockSpaceOverViewport();
ImGui.ShowDemoWindow();
ImGui.Render();
GL.Viewport(0, 0, FramebufferSize.X, FramebufferSize.Y);
GL.ClearColor(new Color4(0, 32, 48, 255));
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
ImguiImplOpenGL3.RenderDrawData(ImGui.GetDrawData());
if (ImGui.GetIO().ConfigFlags.HasFlag(ImGuiConfigFlags.ViewportsEnable))
{
ImGui.UpdatePlatformWindows();
ImGui.RenderPlatformWindowsDefault();
Context.MakeCurrent();
}
SwapBuffers();
}
public void OnClosed()
{
ImguiImplOpenGL3.Shutdown();
ImguiImplOpenTK4.Shutdown();
}
public readonly static DebugProc DebugProcCallback = Window_DebugProc;
private static void Window_DebugProc(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr messagePtr, IntPtr userParam)
{
string message = Marshal.PtrToStringAnsi(messagePtr, length);
bool showMessage = true;
switch (source)
{
case DebugSource.DebugSourceApplication:
showMessage = false;
break;
case DebugSource.DontCare:
case DebugSource.DebugSourceApi:
case DebugSource.DebugSourceWindowSystem:
case DebugSource.DebugSourceShaderCompiler:
case DebugSource.DebugSourceThirdParty:
case DebugSource.DebugSourceOther:
default:
showMessage = true;
break;
}
if (showMessage)
{
switch (severity)
{
case DebugSeverity.DontCare:
Console.WriteLine($"[DontCare] [{source}] {message}");
break;
case DebugSeverity.DebugSeverityNotification:
//Logger?.LogDebug($"[{source}] {message}");
break;
case DebugSeverity.DebugSeverityHigh:
Console.Error.WriteLine($"Error: [{source}] {message}");
break;
case DebugSeverity.DebugSeverityMedium:
Console.WriteLine($"Warning: [{source}] {message}");
break;
case DebugSeverity.DebugSeverityLow:
Console.WriteLine($"Info: [{source}] {message}");
break;
default:
Console.WriteLine($"[default] [{source}] {message}");
break;
}
}
}
}
}