Create GLX context in specific region of a window

2019-07-29 10:13发布

I would like to create an OpenGL context with GLX inside a window. However, I do not want it to span over the whole window region. Instead, it should only cover a subregion.

For example, GLUT provides a function for this behaviour. Also major toolkits like GTK+ or QT provide GL widgets, which are only subregions of X windows. However I need to work low-level.

glXMakeCurrent() accepts a X Drawable identifier. Is it possible to define a Drawable as being a subregion of a window? Or are there other ways to bind the context to a window region?

GLX reference (Blue Book)

Edit: Added awesome bounty!

标签: x11 drawable glx
2条回答
仙女界的扛把子
2楼-- · 2019-07-29 10:21

I found this helpful piece of information in a BSD manpage:

In almost every regard that is important to you, a subwindow is like a top-level window. It has a window id; it has its own set of event callbacks; you can render to it; you are notified of its creation; ...

A subwindow lives inside of some other window (possibly a top-level window, possibly another subwindow). Because of this, it generally only interacts with other windows of your own creation, hence it is not subjected to a window manager. This is the primary source for its differences from a top-level window:

So I assume that GL widgets in popular toolkits also act in fact as a distinct (sub)window. The interesting part is that this is transparent to the window manager, and therefore the user.

查看更多
做自己的国王
3楼-- · 2019-07-29 10:31

You can only glXMakeCurrent() an X Drawable, not a subsection of it, however your solution is simple: stop thinking about an X window as if it is your application. Each X application is typically made up of 10's or 100's of X windows. Create a child window in the area you want and draw into it.

Alternately, you could create a pixmap, render into it and then copy to an area of a window, but that would be slower.

查看更多
登录 后发表回答