I have an application written in Xt/Motif. I want to incorporate OpenGL for rendering - dynamic rotation, pan, and zoom. The application without OpenGL basically has a main widget (toplevel), a menu bar on top, and an xmDrawingAreaWidget (canvas) for drawing into. It also has an XPixmap copied over the canvas, I believe to better handle expose events.
So, I understand that with OpenGL, I need a GLXPixmap also. I’m having trouble setting it up though. I think I know what the problem is, but I’m not sure how to fix it.
To incorporate the OpenGL, I’ve done the following (I’ve left out much of the code, just these are the important things):
– snip –
dpy = XtDisplay(toplevel);
vi = glXChooseVisual(
cx = glXCreateContext(dpy,
/* no display list sharing / None,
/ favor direct */ GL_TRUE);
cmap = XCreateColormap(
canvas = XtVaCreateManagedWidget(“canvas”,
canvas_dpy = XtDisplay(canvas);
gcv.foreground = background;
gcv.background = WhitePixel(canvas_dpy, curr_screen);
xgc.clear = XtGetGC(canvas, GCForeground | GCBackground, &gcv);
pix = XCreatePixmap(canvas_dpy, RootWindowOfScreen(XtScreen(toplevel)), width, height, depth);
XFillRectangle(canvas_dpy, pix, xgc.clear, 0, 0, width, height);
GLXpix = glXCreateGLXPixmap(canvas_dpy, vi, pix);
glXMakeCurrent(dpy, XtWindow(canvas), cx);
Then, to draw the scene, I do:
(draw vertices and lines)
if (doubleBuffer) glXSwapBuffers(dpy, XtWindow(canvas));
window = XtWindow(canvas);
XCopyArea(canvas_dpy, pix, window, xgc.clear, 0, 0, width, height, 0, 0);
The code compiles and runs, but when I try to render, the screen flickers once then returns to the default white screen. If I remove the XCopyArea command, the scene is drawn correctly, but the background goes to black. If I use GLXPix instead of pix in the XCopyArea command, it crashes with a BadDrawable X error. So, I know my GLXPixmap is not being created correctly, and I assume it is because I created it with XVisualInfo vi, which was created from the toplevel widget instead of the canvas, and Display canvas_dpy, which was created from the canvas.
So, my question is: How can I get an XVisualInfo for the canvas to use with glXCreateGLXPixmap?