2
votes

I have a regular Win32 window, I want to render using OpenGL only to part of that window, I found this question:

Using OpenGL in a regular window (Win32)

But I don't really know how they created a panel inside a window and got the DC for it..

Basically I want a window that will draw buttons, lists and more using win32 and on the same window, in some specified section, render opengl stuff.

I tried using glScissor and clearing the buffers but that just fills the whole screen with black and the part I specified in the clear color..

I also tried using glViewport but that didn't do anything.

2
Does the question boil down to: "How do I create controls in WinAPI?" If so, this tutorial gives a good overview. But I highly suggest not to work directly with the WinAPI since it's a terrible amount of work. Better use a UI framework that abstracts that.BDL

2 Answers

0
votes

I ended up creating a new widget like so:

HWND OpenglHWND = CreateWindowW(L"Static", L"",
                  WS_CHILD | WS_VISIBLE | WS_BORDER,
                  200, 10, 300, 300, ParentWindowHandle, 0, 0, NULL);

After that, you got the HWND of the panel you created, from here just initialize OpenGL like you always do, BUT, when creating the context, use the DC of the HWND we got before! (basically use GetDC(OpenGLHWND) for the OpenGL context)

-1
votes

You'd need to create a WinForms Panel control (assuming you are using WinForms?) then call GetDC(panel.Handle) passing the Handle property of the panel as a parameter. This will give you the DC to create the OpenGL context.