tags:

views:

313

answers:

2

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!

+1  A: 

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.

ypnos
A: 

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.

Nathan Kidd
How to create a child window of the root window that really is not a top level window?
ypnos
Why do you want to do that? You said "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."So you have a top-level window, with root as parent, then create a new window with this top-level window as parent, and position it in whatever "subregion" you want.
Nathan Kidd