C
C#3mo ago
Silme94

✅ ImGui.NET and OpenTK

hello, i tried to render a basic imgui window on my opentk window, but it just dont works and crash with an exception
using System;
using ImGuiNET;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

namespace ImGuiWithOpenTK
{
class Program
{
private static GameWindow gameWindow;

public static void Main(string[] args)
{
NativeWindowSettings nativeWindowSettings = new NativeWindowSettings
{
Size = new Vector2i(800, 600),
Title = "ImGui with OpenTK",
API = ContextAPI.OpenGL,
APIVersion = new Version(4, 6),
};

GameWindowSettings gameWindowSettings = new GameWindowSettings
{
UpdateFrequency = 60
};

gameWindow = new GameWindow(gameWindowSettings, nativeWindowSettings);

gameWindow.Load += GameWindow_Load;

gameWindow.RenderFrame += GameWindow_RenderFrame;

gameWindow.UpdateFrame += GameWindow_UpdateFrame;

gameWindow.Run();
}

private static void GameWindow_UpdateFrame(FrameEventArgs obj)
{

}

private static void GameWindow_RenderFrame(FrameEventArgs obj)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

ImGui.NewFrame();
ImGui.Begin("Demo windows");
ImGui.Text("Hello world");
ImGui.End();
ImGui.Render();

gameWindow.SwapBuffers();
}

private static void GameWindow_Load()
{
GL.ClearColor(Color4.CornflowerBlue);

ImGui.CreateContext();
ImGuiIOPtr io = ImGui.GetIO();
ImGui.StyleColorsDark();
}
}
}
using System;
using ImGuiNET;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

namespace ImGuiWithOpenTK
{
class Program
{
private static GameWindow gameWindow;

public static void Main(string[] args)
{
NativeWindowSettings nativeWindowSettings = new NativeWindowSettings
{
Size = new Vector2i(800, 600),
Title = "ImGui with OpenTK",
API = ContextAPI.OpenGL,
APIVersion = new Version(4, 6),
};

GameWindowSettings gameWindowSettings = new GameWindowSettings
{
UpdateFrequency = 60
};

gameWindow = new GameWindow(gameWindowSettings, nativeWindowSettings);

gameWindow.Load += GameWindow_Load;

gameWindow.RenderFrame += GameWindow_RenderFrame;

gameWindow.UpdateFrame += GameWindow_UpdateFrame;

gameWindow.Run();
}

private static void GameWindow_UpdateFrame(FrameEventArgs obj)
{

}

private static void GameWindow_RenderFrame(FrameEventArgs obj)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

ImGui.NewFrame();
ImGui.Begin("Demo windows");
ImGui.Text("Hello world");
ImGui.End();
ImGui.Render();

gameWindow.SwapBuffers();
}

private static void GameWindow_Load()
{
GL.ClearColor(Color4.CornflowerBlue);

ImGui.CreateContext();
ImGuiIOPtr io = ImGui.GetIO();
ImGui.StyleColorsDark();
}
}
}
35 Replies
Silme94
Silme943mo ago
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
at ImGuiNET.ImGuiNative.igNewFrame()
--------------------------------
at ImGuiNET.ImGui.NewFrame()
at ImGuiWithOpenTK.Program.GameWindow_RenderFrame(OpenTK.Windowing.Common.FrameEventArgs)
at OpenTK.Windowing.Desktop.GameWindow.OnRenderFrame(OpenTK.Windowing.Common.FrameEventArgs)
at OpenTK.Windowing.Desktop.GameWindow.Run()
at ImGuiWithOpenTK.Program.Main(System.String[])
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
at ImGuiNET.ImGuiNative.igNewFrame()
--------------------------------
at ImGuiNET.ImGui.NewFrame()
at ImGuiWithOpenTK.Program.GameWindow_RenderFrame(OpenTK.Windowing.Common.FrameEventArgs)
at OpenTK.Windowing.Desktop.GameWindow.OnRenderFrame(OpenTK.Windowing.Common.FrameEventArgs)
at OpenTK.Windowing.Desktop.GameWindow.Run()
at ImGuiWithOpenTK.Program.Main(System.String[])
TheRanger
TheRanger3mo ago
ah yes good thing im here cuz i did make it work but that error seems new to me Shouldnt you have an instance of a ImGuiController ?
Silme94
Silme943mo ago
ImGuiController is not definied on ImGui.NET bro
TheRanger
TheRanger3mo ago
never said it does
Silme94
Silme943mo ago
its from github or smth? is there a way to make without?
TheRanger
TheRanger3mo ago
let me check actually imguicontroller is there
TheRanger
TheRanger3mo ago
GitHub
GitHub - ImGuiNET/ImGui.NET: An ImGui wrapper for .NET.
An ImGui wrapper for .NET. Contribute to ImGuiNET/ImGui.NET development by creating an account on GitHub.
TheRanger
TheRanger3mo ago
did you follow the tutorial? there's an example project there called SampleProgram try running it
Silme94
Silme943mo ago
ok yeah but i dont wanna paste it bro i wanna write myself
TheRanger
TheRanger3mo ago
the controller?
Silme94
Silme943mo ago
how do we actually use it cause i see also Memory.cs MemoryEditor
TheRanger
TheRanger3mo ago
this is specialized for opentk https://github.com/aybe/DearImGui
GitHub
GitHub - aybe/DearImGui: imgui & implot for .NET & OpenTK
imgui & implot for .NET & OpenTK. Contribute to aybe/DearImGui development by creating an account on GitHub.
Silme94
Silme943mo ago
there is no way to use the normal ImGui.NET library? how do u do for example on ur projects
TheRanger
TheRanger3mo ago
ah yes sorry this is the one im actually using https://github.com/NogginBops/ImGui.NET_OpenTK_Sample
GitHub
GitHub - NogginBops/ImGui.NET_OpenTK_Sample: A sample project showi...
A sample project showing an ImGui (using ImGui.NET) renderer for OpenTK in C# - NogginBops/ImGui.NET_OpenTK_Sample
Silme94
Silme943mo ago
i copy the controller and how i use it on my code?
TheRanger
TheRanger3mo ago
to be safe use this ^ project because its the one im using so it'd probably be easier to help u the project has an example it should give you an idea how to
Silme94
Silme943mo ago
this is working but that just look rly weird, and i cannot interacte the imgui menu with keys
TheRanger
TheRanger3mo ago
use $paste
MODiX
MODiX3mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Silme94
Silme943mo ago
using System;
using ImGuiNET;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

namespace ImGuiWithOpenTK
{
class Program
{
private static GameWindow gameWindow;
private static ImGuiController _controller;

public static void Main(string[] args)
{
NativeWindowSettings nativeWindowSettings = new NativeWindowSettings
{
Size = new Vector2i(800, 600),
Title = "ImGui with OpenTK",
API = ContextAPI.OpenGL,
APIVersion = new Version(4, 6),
};

GameWindowSettings gameWindowSettings = new GameWindowSettings
{
UpdateFrequency = 60
};

gameWindow = new GameWindow(gameWindowSettings, nativeWindowSettings);

_controller = new ImGuiController(800, 600);

gameWindow.Load += GameWindow_Load;

gameWindow.RenderFrame += GameWindow_RenderFrame;

gameWindow.UpdateFrame += GameWindow_UpdateFrame;

gameWindow.Run();
}

private static void GameWindow_UpdateFrame(FrameEventArgs obj)
{

}

private static void GameWindow_RenderFrame(FrameEventArgs obj)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

_controller.Update(gameWindow, (float)obj.Time);

ImGui.DockSpaceOverViewport();

ImGui.ShowDemoWindow();

_controller.Render();

ImGuiController.CheckGLError("End of frame");

gameWindow.SwapBuffers();
}

private static void GameWindow_Load()
{
GL.ClearColor(Color4.CornflowerBlue);
GL.Viewport(0, 0, 800, 600);
}
}
}
using System;
using ImGuiNET;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

namespace ImGuiWithOpenTK
{
class Program
{
private static GameWindow gameWindow;
private static ImGuiController _controller;

public static void Main(string[] args)
{
NativeWindowSettings nativeWindowSettings = new NativeWindowSettings
{
Size = new Vector2i(800, 600),
Title = "ImGui with OpenTK",
API = ContextAPI.OpenGL,
APIVersion = new Version(4, 6),
};

GameWindowSettings gameWindowSettings = new GameWindowSettings
{
UpdateFrequency = 60
};

gameWindow = new GameWindow(gameWindowSettings, nativeWindowSettings);

_controller = new ImGuiController(800, 600);

gameWindow.Load += GameWindow_Load;

gameWindow.RenderFrame += GameWindow_RenderFrame;

gameWindow.UpdateFrame += GameWindow_UpdateFrame;

gameWindow.Run();
}

private static void GameWindow_UpdateFrame(FrameEventArgs obj)
{

}

private static void GameWindow_RenderFrame(FrameEventArgs obj)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

_controller.Update(gameWindow, (float)obj.Time);

ImGui.DockSpaceOverViewport();

ImGui.ShowDemoWindow();

_controller.Render();

ImGuiController.CheckGLError("End of frame");

gameWindow.SwapBuffers();
}

private static void GameWindow_Load()
{
GL.ClearColor(Color4.CornflowerBlue);
GL.Viewport(0, 0, 800, 600);
}
}
}
No description
Silme94
Silme943mo ago
the color of my windows does not infect the imgui menu why this is grey and dont resize
TheRanger
TheRanger3mo ago
bro did you check the sample? where is this method
protected override void OnResize(ResizeEventArgs e)
{
base.OnResize(e);

// Update the opengl viewport
GL.Viewport(0, 0, ClientSize.X, ClientSize.Y);

// Tell ImGui of the new size
_controller.WindowResized(ClientSize.X, ClientSize.Y);
}
protected override void OnResize(ResizeEventArgs e)
{
base.OnResize(e);

// Update the opengl viewport
GL.Viewport(0, 0, ClientSize.X, ClientSize.Y);

// Tell ImGui of the new size
_controller.WindowResized(ClientSize.X, ClientSize.Y);
}
Silme94
Silme943mo ago
yes fr but what is ClientSize where did he got that variable form
TheRanger
TheRanger3mo ago
its in the sample its a property defined in the GameWindow class in your case it would be gameWindow.ClientSize.X
Silme94
Silme943mo ago
oh ok sorry thats works but i cannot change the background color and its always grey
Silme94
Silme943mo ago
MODiX
MODiX3mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Silme94
Silme943mo ago
BlazeBin - ahsxjyzdlcjj
A tool for sharing your source code with the world!
TheRanger
TheRanger3mo ago
show image?
Silme94
Silme943mo ago
@ @R like the screen here the same color but it scale well i just want to change color
TheRanger
TheRanger3mo ago
so its all grey?
Silme94
Silme943mo ago
yes but imgui windows work well
TheRanger
TheRanger3mo ago
what color is this? GL.ClearColor(new Color4(0.0f, 0.3f, 0.5f, 1.0f)); also wow this code
gameWindowSettings = new GameWindowSettings
{
UpdateFrequency = 60
};
gameWindowSettings = new GameWindowSettings
{
UpdateFrequency = 60
};
super lags my game i just use GameWindowSettings.Default like the sample does hmm ur right i ran the sample, it doesnt change the color lol it does change in my game, ill see why found the culprit comment this line ImGui.DockSpaceOverViewport();
Silme94
Silme943mo ago
ok that work well thanks !close
Accord
Accord3mo ago
Closed!
Want results from more Discord servers?
Add your server
More Posts
Effective way learn asp .net from scratchhi, im beginer (i know some html,css,js n some framework to work with fronend) ,so i decide to jump ASP MVC Inventory management checkout process helpHi all, I have been working for many months in school to complete this project and am getting to theAuthentication problem with InteractiveServer render modeI have created an authentication system using OAuth in my Blazor Web App project. I have two side (cPracticing OOP in c#, is this logical implementation of an Interface?```c# public interface IMembershipManager { void RegisterMembership(Person person); void CanWhy the shortcut of my App in the Startup Folder not starts??Hi guys, hope you're doing well, I have a `Console App`, in the `program.cs` I have the following co✅ Get base version of project in Github actionsI want to setup a github actions workflow that gets the base version of my library (for example 1.5.My methods loop does not want to stop even if i use returnI have tried different ways but i cant get to making it just exitIs using a blazor component from a service a good idea?I have a DocumentManagerComponent.razor that is used in multiple places across the app. It has an OnAspNetCore `net8.0` - Blazor {*CatchAll} route overrides MVC AdminController routeI'm using a Blazor8 with OrchardCore as a de-coupled CMS. I want `/admin*` to be routed by Orchard, Need to edit a outlook mail without interopHello, i have a .msg template that i have to work with. First i need to read it, then edit the mess