I can't seem to find an example of creating an OpenGL context off of an existing X11 Window. Every example I find creates a window that is already OpenGL ready by providing the necessary visual attributes (via glXChooseVisual or glXChooseFBConfig). What if I already have an existing window (referenced via Display* and Window) and want to change the Colormap and XVisualInfo for the Window for OpenGL rendering? Think ChoosePixelFormat and SetPixelFormat on Windows when creating an OpenGL context. Is this even possible in X11? Do I have to create a Window that's already ready for OpenGL?
Related
I am looking for some information about rendering child windows in specific about how OpenGL interop with GDI. The problem that I have is that I have basically is that I have two windows, first, the main windows are created in qt, and inside of qt, a child window is hosted that leverages an OpenGL renderer.
Now what I wanted to do is to host an overlay on top of my OpenGL window, so I use that to overlay the OpenGL window. The problem that I am having is that when I render with OpenGL, the OpenGL generated graphics seem to obscure the graphics area including and effectively undo the graphics composited by qt.
In the image below the blue area is the qt overlay, in that picture I'm using GDI (BeginPaint/EndPaint) so and the windows seem to interact fine. That is, window order seems correct, the client region is correct. The moment I start to render with Opengl the blue area gets replaced with whatever OpenGL renders.
What I did I basically created to create the overlay I created a second frameless, topmost QMainWindow, and once the platform HWND was initialized I reparent it. Basically I change the new windows parent to be the same parent of my OpenGL window.
What I believed this would do is that the every window, gets drawn separately and the desktop composition manager would make the final composition and basically avoiding the infamous airspace problem as documented by Microsoft in their WPF framework.
What I would like to know is what could cause these issues? At this point, I lack understanding why once i render with OpenGL the pixels by qt overlay are obscured, even though windows hierarchy should say make them composited. What could I do to accomplish what I want?
Mixing OpenGL and GDI drawing on a shared drawable (that also includes sibling / childwindows without the CS_OWNDC windowclass style flag) never was supported. That's not something about Qt, but simply how OpenGL and GDI interact.
But the more important issue is: Why the hell aren't you using the OpenGL support built right into Qt in the first place? Ever since Qt-5 – if available – uses OpenGL to draw everything (all the UI elements). Qt-5 makes it trivial to mix Qt stuff and OpenGL drawing.
I am interested in the task of creating an application using WinAPI, with the ability to use it in a window with OpenGL graphics, along with WinAPI elements. For example, to half of the window occupied by a window with graphics, and the second some elements of WinAPI.
Easiest way to approach this is to create a child window for the OpenGL area. Create with CS_OWNDC class style and WS_CLIPSIBLINGS window style, so that there is a separate device context available and sibling windows (for buttons, etc.) can be placed on top of it on the Z-stack. The rest is initializing the pixelformat and OpenGL context as per usual, but on that child window.
ChoosePixelFormat
SetPixelFormat
wglCreateContext
wglMakeCurrent
Note that if you want modern OpenGL you also need a proxy OpenGL context, to retrieve the attribute based format selection functions. It's described in detail in the official OpenGL wiki.
I have seen a method in SFML called isOpen which checks if the window is open.
Is there any similar equivalent in openGL or GLUT which checks if the window is open?
OpenGL render to a framebuffer attached to an OpenGL rendering context. The rendering context may have been created from a window connecting the (default) framebuffer to the window, but this is out of scope for the OpenGL spec.
As for GLUT you can use glutSetWindow to set the window id you want to check whether or not it exist, and then do glutGetWindow. If it returns the window id previously set the window exist. If not, glutSetWindow obviously failed because the window does not exist.
Whether or not this is true seems implementation dependent, but I doubt anyone would be stupid enough to not implement error handling in such a trivial case.
I was wondering if I can initialize glut in a window I made before in visual c++ , because I tried to initialize openGl using the pixel format descriptor and failed multiple times , so my question is how to initialize GLUT in a specific size in a large window
Because I want to put some buttons and text boxes near the glut viewport
By using (Free)GLUT, you have essentially given up control over the specifics of things like window creation. GLUT has no mechanism to "adopt" a window provided by the user.
So if you want to create the window yourself, you have to also have to manage it yourself, with all the OpenGL context creation stuff that entails.
I have to write an application on Linux using X11 for the interface (in C++). The application uses GLX to render some openGL graphics, but I also need to write some custom UI for this app within the same window.
When I create window I created a GC and a GLX context. Ideally I'd need to "draw" the openGL into a region of the window (say the left part) and the draw the UI on the side of the GL viewport.
How can I do that?
how can i combine GLX and GC drawing calls, such as XDrawString for example.
what would be the best way for me to create a layout within the same window, reserving a region of the window in which I draw the GL content, and having another region of the window in which I draw the UI using X calls. Do I need to create sub-windows for that?
I actually found a useful answer here:
Create GLX context in specific region of a window
The idea is to spawn a sub-window from the current window and draw the GL content to it.
I'd suggest to use BindTexImage extension, draw your X11 (via core / xrender / whatever ) commands to offscreen pixmap and then later composite it as a texture.