Skip to content

Commit 6257505

Browse files
authored
imgui: update ImGuiController to use ImGui OpenGL 3 reference example (#459)
* imgui: update ImGuiController to use ImGui OpenGL 3 reference example * imgui: re-added Shader/Texture/Util. Fixes from code review. * imgui: more code review updates. Added Bind method to Texture * imgui: removed additional Bind calls from Texture
1 parent b30d176 commit 6257505

File tree

9 files changed

+532
-326
lines changed

9 files changed

+532
-326
lines changed

Silk.NET.sln

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Silk.NET.Windowing.Common", "src\Windowing\Silk.NET.Windowing.Common\Silk.NET.Windowing.Common.csproj", "{956F722C-DFD3-435E-9D2E-A0549C4D8BC0}"
1919
EndProject
2020
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{E1F91563-7277-4E9B-A3B7-8D5FD9802A4A}"
21-
ProjectSection(SolutionItems) = preProject
22-
examples\Directory.Build.props = examples\Directory.Build.props
23-
EndProjectSection
21+
ProjectSection(SolutionItems) = preProject
22+
examples\Directory.Build.props = examples\Directory.Build.props
23+
EndProjectSection
2424
EndProject
2525
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenAL", "OpenAL", "{081E7761-B200-4DBF-8950-941464DECACE}"
2626
EndProject
@@ -44,7 +44,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build Properties", "Build P
4444
build\csharp_typemap.json = build\csharp_typemap.json
4545
generator.json = generator.json
4646
build\gl_typemap.json = build\gl_typemap.json
47-
build\dx_typemap.json = build\dx_typemap.json
47+
build\dx_typemap.json = build\dx_typemap.json
4848
EndProjectSection
4949
EndProject
5050
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Silk.NET.Input.Common", "src\Input\Silk.NET.Input.Common\Silk.NET.Input.Common.csproj", "{8FFF49D6-B029-400B-8510-1A088868DFA6}"
@@ -346,9 +346,9 @@ EndProject
346346
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.XInput", "src\Microsoft\Silk.NET.XInput\Silk.NET.XInput.csproj", "{E8DE9BA0-8391-4278-926D-DD931C4172AF}"
347347
EndProject
348348
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Maths", "Maths", "{41EEBDB3-75C4-4A60-B4D5-673FBCA791E7}"
349-
ProjectSection(SolutionItems) = preProject
350-
src\Maths\.editorconfig = src\Maths\.editorconfig
351-
EndProjectSection
349+
ProjectSection(SolutionItems) = preProject
350+
src\Maths\.editorconfig = src\Maths\.editorconfig
351+
EndProjectSection
352352
EndProject
353353
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Maths", "src\Maths\Silk.NET.Maths\Silk.NET.Maths.csproj", "{BD86AB4D-74FD-429D-9AEE-79B0C429BB3A}"
354354
EndProject
@@ -374,6 +374,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Assimp.Native", "s
374374
EndProject
375375
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.OpenGL.Extensions.ImGui", "src\OpenGL\Extensions\Silk.NET.OpenGL.Extensions.ImGui\Silk.NET.OpenGL.Extensions.ImGui.csproj", "{462A4DDB-3B81-46C7-BFC8-3AD9269BCF85}"
376376
EndProject
377+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImGui", "src\Lab\ImGui\ImGui.csproj", "{BBCE3663-B0A6-4198-A2DB-4A64B0530449}"
378+
EndProject
377379
Global
378380
GlobalSection(SolutionConfigurationPlatforms) = preSolution
379381
Debug|Any CPU = Debug|Any CPU
@@ -2238,6 +2240,18 @@ Global
22382240
{462A4DDB-3B81-46C7-BFC8-3AD9269BCF85}.Release|x64.Build.0 = Release|Any CPU
22392241
{462A4DDB-3B81-46C7-BFC8-3AD9269BCF85}.Release|x86.ActiveCfg = Release|Any CPU
22402242
{462A4DDB-3B81-46C7-BFC8-3AD9269BCF85}.Release|x86.Build.0 = Release|Any CPU
2243+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2244+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Debug|Any CPU.Build.0 = Debug|Any CPU
2245+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Debug|x64.ActiveCfg = Debug|Any CPU
2246+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Debug|x64.Build.0 = Debug|Any CPU
2247+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Debug|x86.ActiveCfg = Debug|Any CPU
2248+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Debug|x86.Build.0 = Debug|Any CPU
2249+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Release|Any CPU.ActiveCfg = Release|Any CPU
2250+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Release|Any CPU.Build.0 = Release|Any CPU
2251+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Release|x64.ActiveCfg = Release|Any CPU
2252+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Release|x64.Build.0 = Release|Any CPU
2253+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Release|x86.ActiveCfg = Release|Any CPU
2254+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449}.Release|x86.Build.0 = Release|Any CPU
22412255
EndGlobalSection
22422256
GlobalSection(SolutionProperties) = preSolution
22432257
HideSolutionNode = FALSE
@@ -2406,6 +2420,7 @@ Global
24062420
{84F51960-D814-450D-80EB-D9E46A1D5187} = {72E7FA64-5B1E-477D-BD30-63B7F206B3C4}
24072421
{D3D9891B-88E6-46AD-919C-7EC4EABE5266} = {72E7FA64-5B1E-477D-BD30-63B7F206B3C4}
24082422
{462A4DDB-3B81-46C7-BFC8-3AD9269BCF85} = {CF69D5C3-4ACE-4458-BA5A-0E9A3B294CDC}
2423+
{BBCE3663-B0A6-4198-A2DB-4A64B0530449} = {DFA0E841-33E5-4533-AF00-964E21A141B8}
24092424
EndGlobalSection
24102425
GlobalSection(ExtensibilityGlobals) = postSolution
24112426
SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D}

src/Lab/ImGui/ImGui.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="ImGui.NET" Version="1.78.0" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\Input\Silk.NET.Input\Silk.NET.Input.csproj" />
15+
<ProjectReference Include="..\..\OpenGL\Silk.NET.OpenGL\Silk.NET.OpenGL.csproj" />
16+
<ProjectReference Include="..\..\OpenGL\Extensions\Silk.NET.OpenGL.Extensions.ImGui\Silk.NET.OpenGL.Extensions.ImGui.csproj" />
17+
<ProjectReference Include="..\..\Windowing\Silk.NET.Windowing\Silk.NET.Windowing.csproj" />
18+
</ItemGroup>
19+
20+
<Import Project="..\..\..\build\props\common.props" />
21+
22+
</Project>

src/Lab/ImGui/ImGui.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.809.3
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImGui", "ImGui.csproj", "{33E401A2-A133-4257-BEFD-5F18955B7DD5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{33E401A2-A133-4257-BEFD-5F18955B7DD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{33E401A2-A133-4257-BEFD-5F18955B7DD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{33E401A2-A133-4257-BEFD-5F18955B7DD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{33E401A2-A133-4257-BEFD-5F18955B7DD5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2A81595E-510A-45C9-A0CF-EDCDF75E10AD}
24+
EndGlobalSection
25+
EndGlobal

src/Lab/ImGui/Program.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// This file is part of Silk.NET.
2+
//
3+
// You may modify and distribute Silk.NET under the terms
4+
// of the MIT license. See the LICENSE file for details.
5+
6+
using System.Drawing;
7+
using Silk.NET.Windowing;
8+
using Silk.NET.Input;
9+
using Silk.NET.OpenGL;
10+
using Silk.NET.OpenGL.Extensions.ImGui;
11+
12+
namespace ImGui
13+
{
14+
class Program
15+
{
16+
static void Main(string[] args)
17+
{
18+
// Create a Silk.NET window as usual
19+
using var window = Window.Create(WindowOptions.Default);
20+
21+
// Declare some variables
22+
ImGuiController controller = null;
23+
GL gl = null;
24+
IInputContext inputContext = null;
25+
26+
// Our loading function
27+
window.Load += () =>
28+
{
29+
controller = new ImGuiController(
30+
gl = window.CreateOpenGL(), // load OpenGL
31+
window, // pass in our window
32+
inputContext = window.CreateInput() // create an input context
33+
);
34+
};
35+
36+
// Handle resizes
37+
window.FramebufferResize += s =>
38+
{
39+
// Adjust the viewport to the new window size
40+
gl.Viewport(s);
41+
};
42+
43+
// The render funciton
44+
window.Render += delta =>
45+
{
46+
// Make sure ImGui is up-to-date
47+
controller.Update((float) delta);
48+
49+
// This is where you'll do any rendering beneath the ImGui context
50+
// Here, we just have a blank screen.
51+
gl.ClearColor(Color.FromArgb(255, (int) (.45f * 255), (int) (.55f * 255), (int) (.60f * 255)));
52+
gl.Clear((uint) ClearBufferMask.ColorBufferBit);
53+
54+
// This is where you'll do all of your ImGUi rendering
55+
// Here, we're just showing the ImGui built-in demo window.
56+
ImGuiNET.ImGui.ShowDemoWindow();
57+
58+
// Make sure ImGui renders too!
59+
controller.Render();
60+
};
61+
62+
// The closing function
63+
window.Closing += () =>
64+
{
65+
// Dispose our controller first
66+
controller?.Dispose();
67+
68+
// Dispose the input context
69+
inputContext?.Dispose();
70+
71+
// Unload OpenGL
72+
gl?.Dispose();
73+
};
74+
75+
// Now that everything's defined, let's run this bad boy!
76+
window.Run();
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)