Skip to content

Commit ecbbc43

Browse files
committed
Imgui update
1 parent 90ec09a commit ecbbc43

File tree

7 files changed

+70
-66
lines changed

7 files changed

+70
-66
lines changed

Monoboy/Application/Application.cs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System;
2-
using System.IO;
32
using System.Numerics;
3+
44
using ImGuiNET;
5+
56
using ImGuiOpenTK;
7+
68
using Monoboy.Constants;
79
using Monoboy.Utility;
8-
using OpenTK.Graphics.OpenGL4;
10+
11+
using OpenTK.Graphics.OpenGL;
912
using OpenTK.Windowing.Common;
1013
using OpenTK.Windowing.Common.Input;
1114
using OpenTK.Windowing.Desktop;
@@ -61,10 +64,10 @@ protected override void OnUpdateFrame(FrameEventArgs args)
6164

6265
UpdateJoypad();
6366

64-
if(emulator.paused == false)
67+
if (emulator.paused == false)
6568
{
6669
int cycles = 0;
67-
while(cycles < Constant.CyclesPerFrame)
70+
while (cycles < Constant.CyclesPerFrame)
6871
{
6972
cycles += emulator.Step();
7073
}
@@ -106,45 +109,45 @@ public override void ImGuiRender()
106109
windowFlags |= ImGuiWindowFlags.NoBringToFrontOnFocus;
107110
windowFlags |= ImGuiWindowFlags.AlwaysAutoResize;
108111

109-
if(ImGui.Begin("Monoboy", windowFlags) == false)
112+
if (ImGui.Begin("Monoboy", windowFlags) == false)
110113
{
111114
ImGui.End();
112115
return;
113116
}
114117

115118
// Menubar
116-
if(ImGui.BeginMenuBar())
119+
if (ImGui.BeginMenuBar())
117120
{
118-
if(ImGui.BeginMenu("File"))
121+
if (ImGui.BeginMenu("File"))
119122
{
120-
if(ImGui.MenuItem("Open", "Ctrl+O"))
123+
if (ImGui.MenuItem("Open", "Ctrl+O"))
121124
{
122125
openRom = TinyFileDialog.OpenFileDialog("Open Rom", "", new string[] { "*.gb", "*.gbc" }, "Rom (.gb,.gbc)", false);
123126

124-
if(string.IsNullOrEmpty(openRom) == false)
127+
if (string.IsNullOrEmpty(openRom) == false)
125128
{
126129
emulator.Open(openRom);
127130
}
128131
}
129-
if(ImGui.MenuItem("Quit", "Alt+F4"))
132+
if (ImGui.MenuItem("Quit", "Alt+F4"))
130133
{
131134
Close();
132135
}
133136
ImGui.EndMenu();
134137
}
135138

136-
if(ImGui.BeginMenu("Debug"))
139+
if (ImGui.BeginMenu("Debug"))
137140
{
138-
if(ImGui.MenuItem("Background Toggle", null, ref BackgroundEnabled)) { }
139-
if(ImGui.MenuItem("Window Toggle", null, ref WindowEnabled)) { }
140-
if(ImGui.MenuItem("Sprites Toggle", null, ref SpritesEnabled)) { }
141+
if (ImGui.MenuItem("Background Toggle", null, ref BackgroundEnabled)) { }
142+
if (ImGui.MenuItem("Window Toggle", null, ref WindowEnabled)) { }
143+
if (ImGui.MenuItem("Sprites Toggle", null, ref SpritesEnabled)) { }
141144
ImGui.EndMenu();
142145
}
143146

144-
if(ImGui.BeginMenu("Windows"))
147+
if (ImGui.BeginMenu("Windows"))
145148
{
146-
if(ImGui.MenuItem("Background", null, ref backgroundWindow)) { }
147-
if(ImGui.MenuItem("Tilemap", null, ref tilemapWindow)) { }
149+
if (ImGui.MenuItem("Background", null, ref backgroundWindow)) { }
150+
if (ImGui.MenuItem("Tilemap", null, ref tilemapWindow)) { }
148151
ImGui.EndMenu();
149152
}
150153

@@ -170,7 +173,7 @@ public override void ImGuiRender()
170173

171174
private void BackgroundWindow()
172175
{
173-
if(backgroundWindow == true)
176+
if (backgroundWindow == true)
174177
{
175178
uint[] palette = { 0xD0D058, 0xA0A840, 0x708028, 0x405010 };
176179

@@ -180,11 +183,11 @@ private void BackgroundWindow()
180183
ushort tilesetAddress = (ushort)(tileset ? 0x0000 : 0x1000);
181184
ushort tilemapAddress = (ushort)(tilemap ? 0x1C00 : 0x1800);
182185

183-
for(int y = 0; y < 256; y++)
186+
for (int y = 0; y < 256; y++)
184187
{
185188
ushort row = (ushort)(y / 8);
186189

187-
for(int x = 0; x < 256; x++)
190+
for (int x = 0; x < 256; x++)
188191
{
189192
ushort colum = (ushort)(x / 8);
190193

@@ -219,15 +222,15 @@ private void BackgroundWindow()
219222

220223
private void TilemapWindow()
221224
{
222-
if(tilemapWindow == true)
225+
if (tilemapWindow == true)
223226
{
224227
uint[] palette = { 0xD0D058, 0xA0A840, 0x708028, 0x405010 };
225228

226-
for(int y = 0; y < 192; y++)
229+
for (int y = 0; y < 192; y++)
227230
{
228231
ushort row = (ushort)(y / 8);
229232

230-
for(int x = 0; x < 128; x++)
233+
for (int x = 0; x < 128; x++)
231234
{
232235
ushort colum = (ushort)(x / 8);
233236

Monoboy/Application/Program.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Drawing;
4-
using System.Drawing.Imaging;
1+
using OpenTK.Windowing.Desktop;
2+
3+
using System;
54
using System.IO;
6-
using System.Reflection;
7-
using System.Runtime.InteropServices;
8-
using OpenTK.Windowing.Common.Input;
9-
using OpenTK.Windowing.Desktop;
10-
using Image = OpenTK.Windowing.Common.Input.Image;
115

126
namespace Monoboy.Application
137
{
148
public static class Program
159
{
1610
public static void Main()
1711
{
18-
if(Directory.Exists("Roms") == false)
12+
if (Directory.Exists("Roms") == false)
1913
{
2014
Directory.CreateDirectory("Roms");
2115
}
22-
if(Directory.Exists("Saves") == false)
16+
if (Directory.Exists("Saves") == false)
2317
{
2418
Directory.CreateDirectory("Saves");
2519
}
2620

2721
NativeWindowSettings settings = new NativeWindowSettings
2822
{
2923
API = OpenTK.Windowing.Common.ContextAPI.OpenGL,
30-
APIVersion = new Version(4, 5),
24+
APIVersion = new Version(3, 2),
3125
Size = new OpenTK.Mathematics.Vector2i(1280, 720)
3226
};
3327

Monoboy/ImGuiOpenTK/ImGuiController.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Runtime.CompilerServices;
5-
using OpenTK.Graphics.OpenGL4;
5+
using OpenTK.Graphics.OpenGL;
66
using OpenTK.Mathematics;
77
using OpenTK.Windowing.Common.Input;
88
using OpenTK.Windowing.Desktop;
@@ -156,7 +156,7 @@ public void RecreateFontDeviceTexture()
156156
/// </summary>
157157
public void Render()
158158
{
159-
if(_frameBegun)
159+
if (_frameBegun)
160160
{
161161
_frameBegun = false;
162162
ImGui.Render();
@@ -169,7 +169,7 @@ public void Render()
169169
/// </summary>
170170
public void Update(GameWindow wnd, float deltaSeconds)
171171
{
172-
if(_frameBegun)
172+
if (_frameBegun)
173173
{
174174
ImGui.Render();
175175
}
@@ -214,16 +214,16 @@ private void UpdateImGuiInput(GameWindow wnd)
214214
var point = screenPoint;//wnd.PointToClient(screenPoint);
215215
io.MousePos = new System.Numerics.Vector2(point.X, point.Y);
216216

217-
foreach(Key key in Enum.GetValues(typeof(Key)))
217+
foreach (Key key in Enum.GetValues(typeof(Key)))
218218
{
219-
if(key == Key.Unknown)
219+
if (key == Key.Unknown)
220220
{
221221
continue;
222222
}
223223
io.KeysDown[(int)key] = KeyboardState.IsKeyDown(key);
224224
}
225225

226-
foreach(var c in PressedChars)
226+
foreach (var c in PressedChars)
227227
{
228228
io.AddInputCharacter(c);
229229
}
@@ -278,17 +278,17 @@ private static void SetKeyMappings()
278278

279279
private void RenderImDrawData(ImDrawDataPtr draw_data)
280280
{
281-
if(draw_data.CmdListsCount == 0)
281+
if (draw_data.CmdListsCount == 0)
282282
{
283283
return;
284284
}
285285

286-
for(int i = 0; i < draw_data.CmdListsCount; i++)
286+
for (int i = 0; i < draw_data.CmdListsCount; i++)
287287
{
288288
ImDrawListPtr cmd_list = draw_data.CmdListsRange[i];
289289

290290
int vertexSize = cmd_list.VtxBuffer.Size * Unsafe.SizeOf<ImDrawVert>();
291-
if(vertexSize > _vertexBufferSize)
291+
if (vertexSize > _vertexBufferSize)
292292
{
293293
int newSize = (int)Math.Max(_vertexBufferSize * 1.5f, vertexSize);
294294
GL.NamedBufferData(_vertexBuffer, newSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
@@ -298,7 +298,7 @@ private void RenderImDrawData(ImDrawDataPtr draw_data)
298298
}
299299

300300
int indexSize = cmd_list.IdxBuffer.Size * sizeof(ushort);
301-
if(indexSize > _indexBufferSize)
301+
if (indexSize > _indexBufferSize)
302302
{
303303
int newSize = (int)Math.Max(_indexBufferSize * 1.5f, indexSize);
304304
GL.NamedBufferData(_indexBuffer, newSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
@@ -336,7 +336,7 @@ private void RenderImDrawData(ImDrawDataPtr draw_data)
336336
GL.Disable(EnableCap.DepthTest);
337337

338338
// Render command lists
339-
for(int n = 0; n < draw_data.CmdListsCount; n++)
339+
for (int n = 0; n < draw_data.CmdListsCount; n++)
340340
{
341341
ImDrawListPtr cmd_list = draw_data.CmdListsRange[n];
342342

@@ -349,10 +349,10 @@ private void RenderImDrawData(ImDrawDataPtr draw_data)
349349
int vtx_offset = 0;
350350
int idx_offset = 0;
351351

352-
for(int cmd_i = 0; cmd_i < cmd_list.CmdBuffer.Size; cmd_i++)
352+
for (int cmd_i = 0; cmd_i < cmd_list.CmdBuffer.Size; cmd_i++)
353353
{
354354
ImDrawCmdPtr pcmd = cmd_list.CmdBuffer[cmd_i];
355-
if(pcmd.UserCallback != IntPtr.Zero)
355+
if (pcmd.UserCallback != IntPtr.Zero)
356356
{
357357
throw new NotImplementedException();
358358
}
@@ -367,7 +367,7 @@ private void RenderImDrawData(ImDrawDataPtr draw_data)
367367
GL.Scissor((int)clip.X, _windowHeight - (int)clip.W, (int)(clip.Z - clip.X), (int)(clip.W - clip.Y));
368368
Util.CheckGLError("Scissor");
369369

370-
if((io.BackendFlags & ImGuiBackendFlags.RendererHasVtxOffset) != 0)
370+
if ((io.BackendFlags & ImGuiBackendFlags.RendererHasVtxOffset) != 0)
371371
{
372372
GL.DrawElementsBaseVertex(PrimitiveType.Triangles, (int)pcmd.ElemCount, DrawElementsType.UnsignedShort, (IntPtr)(idx_offset * sizeof(ushort)), vtx_offset);
373373
}

Monoboy/ImGuiOpenTK/Shader.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System.Collections.Generic;
22
using System.Diagnostics;
33
using System.Runtime.CompilerServices;
4-
using OpenTK.Graphics.OpenGL4;
4+
5+
using OpenTK.Graphics.OpenGL;
56

67
namespace ImGuiOpenTK
78
{
@@ -38,7 +39,7 @@ public void UseShader()
3839

3940
public void Dispose()
4041
{
41-
if(Initialized)
42+
if (Initialized)
4243
{
4344
GL.DeleteProgram(Program);
4445
Initialized = false;
@@ -51,7 +52,7 @@ public UniformFieldInfo[] GetUniforms()
5152

5253
UniformFieldInfo[] Uniforms = new UniformFieldInfo[UnifromCount];
5354

54-
for(int i = 0; i < UnifromCount; i++)
55+
for (int i = 0; i < UnifromCount; i++)
5556
{
5657
string Name = GL.GetActiveUniform(Program, i, out int Size, out ActiveUniformType Type);
5758

@@ -70,12 +71,12 @@ public UniformFieldInfo[] GetUniforms()
7071
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7172
public int GetUniformLocation(string uniform)
7273
{
73-
if(UniformToLocation.TryGetValue(uniform, out int location) == false)
74+
if (UniformToLocation.TryGetValue(uniform, out int location) == false)
7475
{
7576
location = GL.GetUniformLocation(Program, uniform);
7677
UniformToLocation.Add(uniform, location);
7778

78-
if(location == -1)
79+
if (location == -1)
7980
{
8081
Debug.Print($"The uniform '{uniform}' does not exist in the shader '{Name}'!");
8182
}
@@ -89,24 +90,24 @@ private int CreateProgram(string name, params (ShaderType Type, string source)[]
8990
Util.CreateProgram(name, out int Program);
9091

9192
int[] Shaders = new int[shaderPaths.Length];
92-
for(int i = 0; i < shaderPaths.Length; i++)
93+
for (int i = 0; i < shaderPaths.Length; i++)
9394
{
9495
Shaders[i] = CompileShader(name, shaderPaths[i].Type, shaderPaths[i].source);
9596
}
9697

97-
foreach(var shader in Shaders)
98+
foreach (var shader in Shaders)
9899
GL.AttachShader(Program, shader);
99100

100101
GL.LinkProgram(Program);
101102

102103
GL.GetProgram(Program, GetProgramParameterName.LinkStatus, out int Success);
103-
if(Success == 0)
104+
if (Success == 0)
104105
{
105106
string Info = GL.GetProgramInfoLog(Program);
106107
Debug.WriteLine($"GL.LinkProgram had info log [{name}]:\n{Info}");
107108
}
108109

109-
foreach(var Shader in Shaders)
110+
foreach (var Shader in Shaders)
110111
{
111112
GL.DetachShader(Program, Shader);
112113
GL.DeleteShader(Shader);
@@ -124,7 +125,7 @@ private int CompileShader(string name, ShaderType type, string source)
124125
GL.CompileShader(Shader);
125126

126127
GL.GetShader(Shader, ShaderParameter.CompileStatus, out int success);
127-
if(success == 0)
128+
if (success == 0)
128129
{
129130
string Info = GL.GetShaderInfoLog(Shader);
130131
Debug.WriteLine($"GL.CompileShader for shader '{Name}' [{type}] had info log:\n{Info}");

Monoboy/ImGuiOpenTK/Texture.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Numerics;
3-
using OpenTK.Graphics.OpenGL4;
4-
using PixelFormat = OpenTK.Graphics.OpenGL4.PixelFormat;
3+
4+
using OpenTK.Graphics.OpenGL;
5+
6+
using PixelFormat = OpenTK.Graphics.OpenGL.PixelFormat;
57

68
namespace ImGuiOpenTK
79
{
@@ -56,7 +58,7 @@ public Texture(string name, int width, int height, IntPtr data, bool generateMip
5658

5759
GL.TextureSubImage2D(GLTexture, 0, 0, 0, Width, Height, PixelFormat.Bgra, PixelType.UnsignedByte, data);
5860

59-
if(generateMipmaps) GL.GenerateTextureMipmap(GLTexture);
61+
if (generateMipmaps) GL.GenerateTextureMipmap(GLTexture);
6062

6163
SetWrap(TextureCoordinate.S, TextureWrapMode.Repeat);
6264
SetWrap(TextureCoordinate.T, TextureWrapMode.Repeat);
@@ -77,7 +79,7 @@ public Texture(string name, int width, int height, byte[] data, bool generateMip
7779

7880
GL.TextureSubImage2D(GLTexture, 0, 0, 0, Width, Height, PixelFormat.Rgb, PixelType.UnsignedByte, data);
7981

80-
if(generateMipmaps) GL.GenerateTextureMipmap(GLTexture);
82+
if (generateMipmaps) GL.GenerateTextureMipmap(GLTexture);
8183

8284
SetWrap(TextureCoordinate.S, TextureWrapMode.Repeat);
8385
SetWrap(TextureCoordinate.T, TextureWrapMode.Repeat);

0 commit comments

Comments
 (0)