Skip to content

This is a project for cross-platform window creation, OpenGL context creation and input control, implemented in C#

License

Notifications You must be signed in to change notification settings

witcherofthorns/csharp-glfw-imgui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C# GLFW + IMGUI

This is a project for cross-platform window creation, OpenGL context creation and input control, implemented in C#
It is a ported library from the native C language to my favorite C# language. The built-in ImGui in this project has been adapted for GLFW and GL context, you can use this without worrying about problems. All ImGui draw calls are called from the classic Nuget ImGui.Net package

Plans for the future

  • Implement GLEW for GL calls
  • Add cross-platform compilation of solution

How to use

Create GLFW window and GL context

private IntPtr window;
  // any void() { ... }
  if (GLFW.glfwInit() == 0) throw new Exception("glfwInit");
  GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 4);
  GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 6);
  GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
  window = GLFW.glfwCreateWindow(WIDTH, HEIGHT, "Window GLFW", IntPtr.Zero, IntPtr.Zero);

  if (window == IntPtr.Zero) {
      GLFW.glfwTerminate();
      throw new Exception("glfwCreateWindow");
  }

  GLFW.glfwMakeContextCurrent(window);
  GL.LoadEntryPoints();

Create ImGui with GLFW context

private ImGuiController imGuiController = null;
  // any void() { ... }
  imGuiController = new ImGuiController(window);
  imGuiController.Init();

Main loop of GLFW and ImGui draw-calls

while (GLFW.glfwWindowShouldClose(window) == 0) {
  GlfwEvents();
  imGuiController.Update();
  // your ImGui calls
  // ImGui.Begin("Info");
  // ImGui.End();     
  GL.glClear(GL.GL_COLOR_BUFFER_BIT);
  imGuiController.Render();
  GLFW.glfwSwapBuffers(window);
}

About

This is a project for cross-platform window creation, OpenGL context creation and input control, implemented in C#

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages