I want to render my OpenGL GLUT project to a window/control in C# WPF. I have read articles online from Microsoft on how to do it but I am very confused.

Does anyone have any experience with this? Could someone walk me through it with code? What are some other good ways to create a UI?


1 Answer 1


GLUT owns the window it creates. It can't share it with WPF, nor can it use a window created by WPF.

If you want to have an OpenGL application render to a window owned by WPF, that may be possible, but you can't use GLUT for that. You'd have to manually attach OpenGL to the window and manage all of the stuff GLUT otherwise does.

Also, most WPF "windows" are not Win32 HWNDs. So OpenGL cannot render to them. You'd need to make sure that the window is an actual HWND.

  • $\begingroup$ Can you tell me how I can get the HWND in GLFW or some other OpenGL library since GLUT can't do that? $\endgroup$ Jun 8, 2022 at 14:50
  • $\begingroup$ Would Mouse Input work as if it were running natively in C++ if I render to a form or WPF? $\endgroup$ Jun 8, 2022 at 14:54
  • 1
    $\begingroup$ @ArjanSingh: The GLFW docs have an entire section on native access. $\endgroup$ Jun 8, 2022 at 15:17
  • $\begingroup$ I looked at the section and there is only a function to get the HWND and not set it. Am I missing something or is there no option to be able to pass GLFW a handle to render to? $\endgroup$ Jun 8, 2022 at 16:09
  • $\begingroup$ @ArjanSingh: "not set it" Yeah. You can access GLFWs window, but you can't make it adopt yours. If you need to control the window's creation, then you're going to have to manage OpenGL yourself. $\endgroup$ Jun 8, 2022 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.