Closed PixelDough closed 10 months ago
Perhaps try installing ImGui.Net Nuget package, and let me know if anything changes or not
And for how the code should look:
using ImGuiNET;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.ImGuiNet;
using System.Text;
namespace Example
{
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public ImGuiRenderer GuiRenderer;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
GuiRenderer = new ImGuiRenderer(this);
GuiRenderer.RebuildFontAtlas();
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
GuiRenderer.BeginLayout(gameTime);
ImGui.Begin("Input Text");
ImGui.Text("a");
ImGui.End();
GuiRenderer.EndLayout();
base.Draw(gameTime);
}
}
}
(Rather than EndLayout
and BeginLayout
, it should be AfterLayout
and BeforeLayout
as of the current version, which will be changed in the upcoming update)
You have two different references on the same assembly, like this:
Solves by remaining single assembly reference in the whole project. I've deleted ImGUINet from my main project, as it wasn't required to even install that. As MonoGame.ImGuiNet has already reference itself on the version of ImGUINet it needs.
Hope it helps you.
With the basic implemention set up, I get the following error upon trying to draw anything within the ImGuiRenderer.BeginLayout:
Unhandled exception. System.MissingMethodException: Method not found: 'ImGuiNET.RangePtrAccessor`1<ImGuiNET.ImDrawListPtr> ImGuiNET.ImDrawDataPtr.get_CmdListsRange()'. at MonoGame.ImGui.ImGuiRenderer.UpdateBuffers(ImDrawDataPtr drawData) at MonoGame.ImGui.ImGuiRenderer.RenderDrawData(ImDrawDataPtr drawData) in C:\Users\PixelDoughAdmin\Documents\Repos\monogame_project\Monogame.ImGui\MonoGame.ImGui\ImGUIRenderer.cs:line 104 at MonoGame.ImGui.ImGuiRenderer.EndLayout() in C:\Users\PixelDoughAdmin\Documents\Repos\monogame_project\Monogame.ImGui\MonoGame.ImGui\ImGUIRenderer.cs:line 38
I've got the ImGuiRenderer initializing, calling "Initialize" on it makes no difference here, and RebuildFontAtlas too. Simply having a BeginLayout and EndLayout causes the crash