Creating an IN FRONT Control in an OpenGL View

I have an OpenGL view on Mac. I want to put an NSTextField in front of it, but even if I put it in front, it will be closed by the view.

There is a very simple test case. Create a new project in Xcode (I use 4.0.2) and a window. Add an OpenGL View. Now add a text box and set it so that half of it overlaps the OpenGL view. Run the program. The entire field is displayed, but when you enter text, only half of it is displayed, regardless of how you arrange the fields from front to back.

+4
source share
1 answer

An NSOpenGLView does not actually draw inside the window; it draws on a surface that is higher or lower than the window, higher by default. If you need a control in front of an OpenGL surface, you must make the surface under the window using the NSOpenGLContext NSOpenGLCPSurfaceOrder parameter. But then you have to cut out the transparent rectangle in the window to see the surface of OpenGL.

Edit to add: as an alternative, you can make a transparent overlay or child window located above the OpenGL surface, as well as the main window and place the control there. Not sure which way will be easier.

+2
source

Source: https://habr.com/ru/post/1399056/


All Articles