简体   繁体   中英

Render with OpenGL to part of Win32 Window

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.

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM