简体   繁体   中英

Using OpenGL in C++.NET and Painting Over the Viewport

I'm trying to create a .NET application that uses OpenGL. I need to have 4 viewports, but instead of creating 4 controls and syncing them, I'm going to have 1 control that is split into 4 viewports. I want to paint lines over the OpenGL control to split up the viewports visually. I'm using a custom control, and to accomplish this, I have two panels on top of the base UserControl. The Panel in the middle is the OpenGL panel, where the OpenGL output is renderered. The panel on the top is where I'm going to draw the viewport dividers, and it has transparency so I can see the panel beneath it.

The problem is, when the OpenGL viewport loads (it's in a separate thread, so it's just black for a few seconds), it covers up the entire UserControl, regardless of its z layer. If I shrink the OpenGL panel, I can see that it still paints only on the panel, but it just doesn't care about what's above it--it just covers it up.

Why is this happened? If you want to see how I'm creating the OpenGL context and such, you can see the tutorial I followed . I'm passing the Handle of the Panel, not of the UserControl. Do all the controls in the custrom control share the same device context or something?

Use the combination of glViewport and glScissor with GL_SCISSOR_TEST enabled to split your window into viewports. Use OpenGL itself to draw the viewport splitters. You can change the projection used at any time. So for the splitters make the viewport covering the whole window, draw the splitters, then limit the viewport to the panes and use scissor to prevent things from "leaking" outside of it.

OpenGL doesn't use the .net windows forms stuff to draw on the screen, it interacts directly with the graphics hardware. One way to achieve what you want may be to render the opengl output to an off screen texture/framebuffer (fbo), then somehow access the framebuffer in normal .net UI. I would suggest instead that you simply draw your viewport dividers using OpenGL calls, and bypass using .net UI elements at all.

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