Is it possible to create an X11 OpenGL window after creating it?

I want to be able to display in the X Window, only with its identifier.

In this case, I have a window created in python using gtk.

I can get the gtk.Drawable window gtk.Drawable and pass it to my C python module, but can I then render OpenGL rendering?

I know gtkglext, but rather I will not use it, if possible.

Update 1:

Good, therefore (obviously now that I see it). You just do an XCreateWindow with the parent of the window id that you get from gtk.window.xid using the correct flags for the opengl and hey presto windows.

The only problem is that I cannot get it to work if there are not multiple widgets in the window, otherwise it seems that xid represents a window that spans the entire top-level window. Not sure how to fix it.

Update 2: It turns out that if you have a gl window whose size is equal to the size, then the top-level window will not throw events until the gl window replaces its buffers. You just need to continue replacing the buffers and everything will be fine.

Update 3:

To respond to @babele's comment:

This page in python gtk files tells how to make a gtk window from an existing xid. After that, you just need to remember that it calls glXSwapBuffers for this window (if it is an opengl buffered window, otherwise it should just work when you use window_foreign_new).

So the process goes:

  • Create a gtk widget that will contain your OpenGL window ( DrawingArea is a good choice - you cannot use, for example, a shortcut because it will not have its own xid)
  • Get widget gtk.gdk.Window ( docs )
  • Get xid from gtk.gdk.Window (call this window W1)
  • Pass it to C / C ++ code
  • Create a window that supports opengl (W2) as a child of W1
  • Pass xid W2 back to python
  • Use window_foreign_new with W2 xid to create a new gtk.gdk.window object
  • Every time you call glXSwapBuffers on W2 gtk, it should respond to events.

One bit that really threw me away is that if W2 spans all of W1, then W1 will not receive events until the W2 buffers are replaced. This is especially embarrassing if W1 is a top-level window, as it may seem that nothing appears on your screen (there is a window, but it seems that everything is behind until it is drawn, that it will not happen until it appears it receives an event exposure).

Also note that you will have to manually control the W2 resize by connecting to the gtk resize events. You can do this by connecting to this signal , and then call this function in the handler and transfer the results to your c / C ++ module, where you can resize W2 accordingly. It is a good idea to request a minimum size .

+7
opengl x11
source share
1 answer

You do not need to create a new window, you pass the existing window glXMakeCurrent ().
In your current setup you need to:

  • XGetWindowAttributes (), to get a visual window, was created using
  • glXCreateContext () using this visual
  • glXMakeCurrent () using this context and window id

However, it does this backward, forcing OpenGL to use the visual used for CreateWindow. This often works because the visual image has reasonable GLX properties by default, but the correct application would be glXChooseVisual with the desired GLX properties, and then use that visual to create the window.

+6
source share

All Articles