Skip to content

Commit a9a0fa8

Browse files
committed
highlight 04
1 parent 8ef191c commit a9a0fa8

File tree

10 files changed

+84
-30
lines changed

10 files changed

+84
-30
lines changed

articles/tutorials/advanced/2d_shaders/02_hot_reload/snippets/snippet-2-06.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<!-- ... -->
33

44
<Target Name="BuildAndCopyContent" DependsOnTargets="IncludeContent">

articles/tutorials/advanced/2d_shaders/02_hot_reload/snippets/snippet-2-08.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<!-- ... -->
33

44
<ItemGroup>

articles/tutorials/advanced/2d_shaders/02_hot_reload/snippets/snippet-2-11.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<!-- ... -->
33

44
<Target Name="WatchContent">

articles/tutorials/advanced/2d_shaders/04_debug_ui/index.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A common approach to building debug UIs in games is to use an _Immediate Mode_ s
1515

1616
To add `ImGUI.NET`, add the following Nuget package reference to the _MonoGameLibrary_ project:
1717

18-
[!code-xml[](./snippets/snippet-4-01.xml)]
18+
[!code-xml[](./snippets/snippet-4-01.xml?highlight=5)]
1919

2020
In order to render the `ImGui.NET` UI in MonoGame, we need a few supporting classes that convert the `ImGui.NET` data into MonoGame's graphical representation. There is a [sample project](https://github.com/ImGuiNET/ImGui.NET/tree/master/src/ImGui.NET.SampleProgram.XNA) on `ImGui.NET`'s public repository that we can copy for our use cases.
2121

@@ -25,7 +25,7 @@ Create a new folder in the _MonoGameLibrary_ project called _ImGui_ and copy and
2525

2626
There is `unsafe` code in the `ImGui` code, like this snippet, so you will need to enable `unsafe` code in the `MonoGameLibrary.csproj` file. Add this property:
2727

28-
[!code-xml[](./snippets/snippet-4-02.xml)]
28+
[!code-xml[](./snippets/snippet-4-02.xml?highlight=4)]
2929

3030
> [!note]
3131
> Why `unsafe`?
@@ -39,15 +39,15 @@ In the `Core.cs` file, add the following property to the `Core` class:
3939

4040
And then to initialize the instance, in the `Initialize()` method, add the following snippet:
4141

42-
[!code-csharp[](./snippets/snippet-4-04.cs)]
42+
[!code-csharp[](./snippets/snippet-4-04.cs?highlight=8-9)]
4343

4444
Similar to `SpriteBatch`'s `.Begin()` and `.End()` calls, the `ImGuiRenderer` has a start and end function call. In the `GameScene` class, add these lines to end of the `.Draw()` method:
4545

46-
[!code-csharp[](./snippets/snippet-4-05.cs)]
46+
[!code-csharp[](./snippets/snippet-4-05.cs?highlight=6,8)]
4747

4848
`ImGui` draws by adding draggable windows to the screen. To create a simple window that just prints out `"Hello World"`, use the following snippet:
4949

50-
[!code-csharp[](./snippets/snippet-4-06.cs)]
50+
[!code-csharp[](./snippets/snippet-4-06.cs?highlight=8-10)]
5151

5252
>[!tip]
5353
>do not forget to add a using statement at the top of the file for `using ImGuiNET;`
@@ -78,11 +78,11 @@ First, add this new boolean to the `Material` class:
7878

7979
Then, modify all of the `SetParameter()` methods to exit early when the `DebugOverride` variable is set to `true`:
8080

81-
[!code-csharp[](./snippets/snippet-4-09.cs)]
81+
[!code-csharp[](./snippets/snippet-4-09.cs?highlight=3)]
8282

8383
Then, in the `DebugDraw()` method, after the `LastUpdated` field gets drawn, add this following:
8484

85-
[!code-csharp[](./snippets/snippet-4-10.cs)]
85+
[!code-csharp[](./snippets/snippet-4-10.cs?highlight=14-17)]
8686

8787
Now, when you run the game, you can enable the `"Override Values"` checkbox to be able to set the `Saturation` value by hand.
8888

@@ -108,7 +108,7 @@ To finish off the edits to the `Material` class, add a method that actually rend
108108

109109
Now in the `Core`'s `Draw` method, we just need to call the new method. We should also delete the old code in the `GameScene` to draw the `_grayscaleEffect`'s debugUI as a one-shot:
110110

111-
[!code-csharp[](./snippets/snippet-4-14.cs)]
111+
[!code-csharp[](./snippets/snippet-4-14.cs?highlight=9)]
112112

113113
Finally, in order to render the debug UI for the `_grayscaleEffect`, just enable the `IsDebugVisible` property to `true`:
114114

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
<PackageReference Include="ImGui.NET" Version="1.91.6.1" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<!-- ... -->
3+
4+
<ItemGroup>
5+
<PackageReference Include="ImGui.NET" Version="1.91.6.1" />
6+
</ItemGroup>
7+
8+
<!-- ... -->
9+
</Project>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5+
</PropertyGroup>
6+
<!-- ... -->
7+
</Project>
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
// Create the ImGui renderer.
2-
ImGuiRenderer = new ImGuiRenderer(this);
3-
ImGuiRenderer.RebuildFontAtlas();
1+
protected override void Initialize()
2+
{
3+
base.Initialize();
4+
5+
// ...
6+
7+
// Create the ImGui renderer.
8+
ImGuiRenderer = new ImGuiRenderer(this);
9+
ImGuiRenderer.RebuildFontAtlas();
10+
11+
// ...
12+
}
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
// Draw debug UI
2-
Core.ImGuiRenderer.BeforeLayout(gameTime);
3-
// draw the debug UI here
4-
Core.ImGuiRenderer.AfterLayout();
1+
protected override void Draw(GameTime gameTime)
2+
{
3+
// ...
4+
5+
// Draw debug UI
6+
Core.ImGuiRenderer.BeforeLayout(gameTime);
7+
// draw the debug UI here
8+
Core.ImGuiRenderer.AfterLayout();
9+
10+
base.Draw(gameTime);
11+
}
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
// Draw debug UI
2-
Core.ImGuiRenderer.BeforeLayout(gameTime);
3-
ImGui.Begin("Demo Window");
4-
ImGui.Text("Hello world!");
5-
ImGui.End();
6-
Core.ImGuiRenderer.AfterLayout();
1+
protected override void Draw(GameTime gameTime)
2+
{
3+
// ...
4+
5+
// Draw debug UI
6+
Core.ImGuiRenderer.BeforeLayout(gameTime);
7+
8+
ImGui.Begin("Demo Window");
9+
ImGui.Text("Hello world!");
10+
ImGui.End();
11+
12+
Core.ImGuiRenderer.AfterLayout();
13+
14+
base.Draw(gameTime);
15+
}
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
ImGui.AlignTextToFramePadding();
2-
ImGui.Text("Override Values");
3-
ImGui.SameLine();
4-
ImGui.Checkbox("##override-values", ref DebugOverride);
1+
[Conditional("DEBUG")]
2+
public void DrawDebug()
3+
{
4+
ImGui.Begin(Effect.Name);
5+
6+
var currentSize = ImGui.GetWindowSize();
7+
ImGui.SetWindowSize(Effect.Name, new System.Numerics.Vector2(MathHelper.Max(100, currentSize.X), MathHelper.Max(100, currentSize.Y)));
8+
9+
ImGui.AlignTextToFramePadding();
10+
ImGui.Text("Last Updated");
11+
ImGui.SameLine();
12+
ImGui.LabelText("##last-updated", Asset.UpdatedAt.ToString() + $" ({(DateTimeOffset.Now - Asset.UpdatedAt).ToString(@"h\:mm\:ss")} ago)");
13+
14+
ImGui.AlignTextToFramePadding();
15+
ImGui.Text("Override Values");
16+
ImGui.SameLine();
17+
ImGui.Checkbox("##override-values", ref DebugOverride);
18+
19+
// ...

0 commit comments

Comments
 (0)