PDA

View Full Version : OpenGL rendering under X



JGuilmette
08-21-2008, 11:07 AM
Hi everyone

I don't know if it's the right place to post, because my problem is related both to X and to OpenGL through GLX. I have searched many examples ont the web and looked through the OpenGL and X documentation, but with no good results. I'm quite a beginner in OpenGL for I have begun coding for about 1 month.

What I was able to do from now is to create a X window and do some rendering in it (a famous turning glutSolidTeapot) in order to read this rendered image from the frame buffer to a PBO which I send to a CUDA Kernel. It worked well and had no problem using the GLX functionality. It is based on an example from NVIDIA CUDA SDK, post-process GL.

Now I want to grab a X window, take the content of this window, bind to an glx context in order to do some operations (through CUDA or directly in a C function) on the image and then put it back in the initial X window. For now, I am able to grab the window, get the image via XGetImage and put it back with XPutImage in a new X window, but I am not able to bind it to openGL and do some operations on the pixels like I did in my previous version of my program.

I have read about the subject and I've found the following concerning image operations using openGL.

The basic steps to create a GLX pixmap are:

1. Call XOpenDisplay to open an X display connection.
2. Select an X visual with glXChooseVisual.
3. Create an X pixmap with XCreatePixmap specifying the depth of the X visual.
4. Create the GLX pixmap with glXCreateGLXPixmap.

The GLXPixmap handle returned by glXCreateGLXPixmap may be passed to glXMakeCurrent to bind an OpenGL rendering context to the GLX pixmap. Rendering into the GLX pixmap may then begin.

The contents of a GLX pixmap may be read back with glReadPixels or XGetImage.
source : http://www.mesa3d.org/brianp/sig97/offscrn.htm

I tried this, in fact I was already doing the glx operations in the previous version of my program but it seems I'm not able to get the image into the framebuffer in order to read it using PBO. Has anyone have any idea about how to do this ? Is there a FAQ, tutorial or the like where I would find such information ?

Plus, is there any information that would able me to make the difference between those OpenGL and X concepts: Pictures, pixmaps, direct rendering and indirect rendering ?

Thx to have read it all, I know this is an enormous post.

Jérôme

PaladinOfKaos
08-21-2008, 11:20 AM
Why not something like this:


Ximage *img;
img = XGetImage(dpy, target_win, 0, 0, width, height, plane, XYPixmap);
DoFunCudaStuff(img->data);
XPutImage(dpy, target_win, gc, img, 0, 0, 0, 0, width, height);
XFree(img);


Where DoFunCudaStuff() handles all the necessary CUDA setup to pass the data to CUDA. Instead of pointing CUDA at an OpenGL data element, you just point it at the client memory containing the image data.

If you need to do any format conversion, you can pass along the whole XImage structure to the CUDA function instead of just the data.

If you need to do anything with it in GL, you can use the same XImage->data pointer as the source for a texture.

JGuilmette
08-21-2008, 12:42 PM
hmm ! A way more direct than linking the image to an OpenGL context...

I tried it, I've done some data pixel operations on CPU and it worked. I haven't tried on GPU (through CUDA) yet. I'll see what I can manage to do with it on CUDA, I'll probably post there is I have any interrogations from now on.

Thx for the rapidity of the answer, it was really appreciated.

Jérôme