mirror of
https://github.com/prime31/FNA-VSCode-Template.git
synced 2025-10-31 21:50:44 +07:00
ImGui up and running
This commit is contained in:
parent
f4f9f314a0
commit
ed4a035574
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
FNA/
|
FNA/
|
||||||
|
ImGui.NET/
|
||||||
fnalibs/
|
fnalibs/
|
||||||
project_name/bin
|
project_name/bin
|
||||||
project_name/obj
|
project_name/obj
|
||||||
|
|||||||
50
getFNA.sh
50
getFNA.sh
@ -62,6 +62,35 @@ function updateFNA()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Clones FNA from the git master branch
|
||||||
|
function downloadImGui()
|
||||||
|
{
|
||||||
|
checkGit
|
||||||
|
echo "Downloading ImGui..."
|
||||||
|
git -C $MY_DIR clone https://github.com/mellinoe/ImGui.NET.git --recursive
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Finished downloading!\n"
|
||||||
|
else
|
||||||
|
echo >&2 "ERROR: Unable to download successfully. Maybe try again later?"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pulls FNA from the git master branch
|
||||||
|
function updateImGui()
|
||||||
|
{
|
||||||
|
checkGit
|
||||||
|
echo "Updating to the latest git version of ImGui.NET..."
|
||||||
|
git -C "$MY_DIR/ImGui.NET" pull --recurse-submodules
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Finished updating!\n"
|
||||||
|
else
|
||||||
|
echo >&2 "ERROR: Unable to update."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Downloads and extracts prepackaged archive of native libraries ("fnalibs")
|
# Downloads and extracts prepackaged archive of native libraries ("fnalibs")
|
||||||
function getLibs()
|
function getLibs()
|
||||||
{
|
{
|
||||||
@ -114,17 +143,36 @@ if [[ $shouldDownloadLibs =~ ^[Yy]$ ]]; then
|
|||||||
getLibs
|
getLibs
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Dear ImGui
|
||||||
|
if [ ! -d "$MY_DIR/ImGui.NET" ]; then
|
||||||
|
read -p "Download ImGui.NET (y/n)? " shouldDownload
|
||||||
|
if [[ $shouldDownload =~ ^[Yy]$ ]]; then
|
||||||
|
downloadImGui
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
read -p "Update ImGui.NET (y/n)? " shouldUpdate
|
||||||
|
if [[ $shouldUpdate =~ ^[Yy]$ ]]; then
|
||||||
|
updateImGui
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# install t4 engine
|
# install t4 engine
|
||||||
installT4
|
installT4
|
||||||
|
|
||||||
|
|
||||||
# Rename project
|
|
||||||
|
# Only proceed from here if we have not yet renamed the project
|
||||||
if [ ! -d "$MY_DIR/project_name" ]; then
|
if [ ! -d "$MY_DIR/project_name" ]; then
|
||||||
# old project_name folder already renamed so we are all done here
|
# old project_name folder already renamed so we are all done here
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# copy over ImGui files before renaming the project
|
||||||
|
echo "Copying ImGui renderer to project..."
|
||||||
|
cp "$MY_DIR/ImGui.NET/src/ImGui.NET.SampleProgram.XNA/DrawVertDeclaration.cs" "$MY_DIR/project_name/ImGui"
|
||||||
|
cp "$MY_DIR/ImGui.NET/src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs" "$MY_DIR/project_name/ImGui"
|
||||||
|
sed -i '' "s/cimgui/cimgui.dylib/g" ImGui.NET/src/ImGui.NET/Generated/ImGuiNative.gen.cs
|
||||||
|
|
||||||
read -p "Enter the project name to use for your folder and csproj file or 'exit' to quit: " newProjectName
|
read -p "Enter the project name to use for your folder and csproj file or 'exit' to quit: " newProjectName
|
||||||
if [[ $newProjectName = 'exit' || -z "$newProjectName" ]]; then
|
if [[ $newProjectName = 'exit' || -z "$newProjectName" ]]; then
|
||||||
|
|||||||
78
project_name/ImGui/ImGuiFinalRenderDelegate.cs
Normal file
78
project_name/ImGui/ImGuiFinalRenderDelegate.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using ImGuiNET;
|
||||||
|
using ImGuiNET.SampleProgram.XNA;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
|
namespace Nez
|
||||||
|
{
|
||||||
|
public class ImGuiFinalRenderDelegate : IFinalRenderDelegate
|
||||||
|
{
|
||||||
|
public Scene scene { get; set; }
|
||||||
|
|
||||||
|
ImGuiRenderer _imGuiRenderer;
|
||||||
|
RenderTarget2D _lastRenderTarget;
|
||||||
|
IntPtr _renderTargetId;
|
||||||
|
|
||||||
|
public ImGuiFinalRenderDelegate()
|
||||||
|
{
|
||||||
|
var core = typeof(Core).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as Core;
|
||||||
|
_imGuiRenderer = new ImGuiRenderer(core);
|
||||||
|
_imGuiRenderer.RebuildFontAtlas();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleFinalRender( Color letterboxColor, RenderTarget2D source, Rectangle finalRenderDestinationRect, SamplerState samplerState )
|
||||||
|
{
|
||||||
|
if(_lastRenderTarget != source)
|
||||||
|
{
|
||||||
|
// unbind the old texture if we had one
|
||||||
|
if(_lastRenderTarget != null)
|
||||||
|
_imGuiRenderer.UnbindTexture(_renderTargetId);
|
||||||
|
|
||||||
|
// bind the new texture
|
||||||
|
_lastRenderTarget = source;
|
||||||
|
_renderTargetId = _imGuiRenderer.BindTexture(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
Core.graphicsDevice.setRenderTarget( null );
|
||||||
|
Core.graphicsDevice.Clear( letterboxColor );
|
||||||
|
|
||||||
|
|
||||||
|
_imGuiRenderer.BeforeLayout(new GameTime(TimeSpan.FromDays(0), TimeSpan.FromMilliseconds(Time.deltaTime * 1000)));
|
||||||
|
layoutGui();
|
||||||
|
_imGuiRenderer.AfterLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void layoutGui()
|
||||||
|
{
|
||||||
|
ImGui.ShowDemoWindow();
|
||||||
|
|
||||||
|
var maxSize = new System.Numerics.Vector2(_lastRenderTarget.Width, _lastRenderTarget.Height);
|
||||||
|
var minSize = maxSize / 4;
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
ImGui.SetNextWindowSizeConstraints(minSize, maxSize, data =>
|
||||||
|
{
|
||||||
|
var size = (*data).CurrentSize;
|
||||||
|
var ratio = size.X / _lastRenderTarget.Width;
|
||||||
|
(*data).DesiredSize.Y = ratio * _lastRenderTarget.Height;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.SetNextWindowPos(new System.Numerics.Vector2(0, 0), ImGuiCond.FirstUseEver);
|
||||||
|
ImGui.Begin("Game Window");
|
||||||
|
ImGui.Image(_renderTargetId, ImGui.GetContentRegionAvail());
|
||||||
|
ImGui.End();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onAddedToScene()
|
||||||
|
{}
|
||||||
|
|
||||||
|
public void onSceneBackBufferSizeChanged( int newWidth, int newHeight )
|
||||||
|
{}
|
||||||
|
|
||||||
|
public void unload()
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,17 +2,19 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net46</TargetFramework>
|
<TargetFramework>net462</TargetFramework>
|
||||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<AssemblyName>project_name</AssemblyName>
|
<AssemblyName>project_name</AssemblyName>
|
||||||
<MonoGamePlatform>DesktopGL</MonoGamePlatform>
|
<MonoGamePlatform>DesktopGL</MonoGamePlatform>
|
||||||
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!-- Reference FNA project -->
|
<!-- Reference FNA project -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="../FNA/FNA.csproj" />
|
<ProjectReference Include="../FNA/FNA.csproj" />
|
||||||
<ProjectReference Include="../Nez.FNA/Nez.FNA/Nez.FNA.csproj" />
|
<ProjectReference Include="../Nez.FNA/Nez.FNA/Nez.FNA.csproj" />
|
||||||
|
<ProjectReference Include="../ImGui.NET/src/ImGui.NET/ImGui.NET.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Include the Content directory (except for .fx files, since we use .fxb at runtime) -->
|
<!-- Include the Content directory (except for .fx files, since we use .fxb at runtime) -->
|
||||||
@ -67,4 +69,24 @@
|
|||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- Copy ImGui native code to output -->
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="..\ImGui.NET\deps\cimgui\win-x86\*.*" Condition="'$(OS)' == 'Windows_NT' AND '$(Platform)' != 'x64'">
|
||||||
|
<Link>osx\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="..\ImGui.NET\deps\cimgui\win-x64\*.*" Condition="'$(OS)' == 'Windows_NT' AND '$(Platform)' != 'x86'">
|
||||||
|
<Link>osx\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="..\ImGui.NET\deps\cimgui\osx-x64\*.*" Condition="'$(OS)' != 'Windows_NT' AND $(IsOSX) == 'true'">
|
||||||
|
<Link>osx\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="..\ImGui.NET\deps\cimgui\linux-x64\*.*" Condition="'$(OS)' != 'Windows_NT' AND $(IsLinux) == 'true'">
|
||||||
|
<Link>osx\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Loading…
Reference in New Issue
Block a user