GLX translucent window

Hi to all,
I don’t know if this is the correct forum to post this question so first of all sorry if it isn’t.

I’m making a glx application which shows the image captured with a webcam as a texture over a quad.
I want the glx window to be translucent so the desktop and other windows that are behind it are blended with the glx’s window content.
I’ve actually managed to create a traslucent glx window (the window borders are traslucent) and a traslucent texture that displays the webcam image, but the background of the glx window remains black.
I’m really a noob in OpenGL / GLX so my question if this can be achieved (I suppose so as Compiz is able to do it) and if so, where could I find some example / tutorial to achieve this.

Many thanks in advance.

No experience there, but check out the “GLX composite extension”. Google that for info. Also check out “AddARGBGLXVisuals” in the NVidia driver README.

Many thanks Dark Photon (nice nick ;)).

I’ve already checked those links, as they are almost the only related links I’ve found during google searching. Maybe my first post isn’t clear enough, so let me reformulate it.
As far as I’ve been able to search and read, I think I have all the neccessary elements to make my GLX ap. translucent (well, sure I haven’t as it doesn’t work :frowning: )

  • My card Is an ATI Radeon X1300, and I’ve installed the latest drivers provided by ATI, and checked “xorg.conf” so the composite extension is available.
  • I’ve selected a visual that supports “GLX_RGBA_BIT”.
  • I’ve made the GLX window translucent changing it’s attributes with Xlib.
  • I’ve made the texture I’m displaying also translucent.

But the GL scene background is always opaque. I’ve tried with different values of R,G,B and alpha with the glClearColor function but I only obtain a black / gray / white background but with no translucent effect.

What I would like to know is if managing a translucent GLX background is related to openGL programming or if it should be related to maybe any other issue such as a bad display selection, bad configuration of the ATI drivers or so on.

Many thanks again.

No experience on this (using xinerama so no Composite) but according to the nvidia page, all you need is the boilerplate code they provide.
Do you get alpha ? ie does (i < numfbconfigs) ?
Do you render premultiplied graphics ? black +alpha=0 should be transparent.

Sorry for my lack of GL knowledge (all I have done so far is follow Nehe’s tutorials) but premultiplied graphics means that if my texture image is a normal RGB image then using:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

should “convert” it’s values to premultiplied alpha values? That’s what I’ve got in my code and texture displays with translucency.
I’m affraid this is going to be a silly question but, are there other means of setting premultiplied alpha to the GLX scene background as well?

Yes, i < numfbconfigs, so the selected FBConfig has alpha. I’ve added some more checks to my code and I’ve noticed that the visual that is selected which supports alpha does not support direct rendering. That means that even if I manage to get translucency in my window it won’t be hardware accelerated or that I won’t be able to achieve translucency at all?
I’m really lost here, I’m running Compiz with translucent windows with relatively low CPU usage. How do they do it :(?

No worry, premultiplied alpha still confuses a lot of people :slight_smile:
2 things :

  1. in this case, it is the window compositor that does the blending of your window, so what you set as your blending mode is not directly relevant. Only that you have to make sure that what you draw has alpha multiplied to rgb, some examples :
    fully transparent is black rgba=0,0,0,0=0R,0G,0B,0
    full red half transparent rgba= 1
    0.5,0,0,0.5=0.5,0,0,0.5
  2. correct blendfunc for premultiplied alpha is glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    For tests, just glClear with semi-transparent grey rgba=0.5,0.5,0.5,0.5 if composite works you should see a bit trough the window.

Not sure about the DRI thing, it may even be irrelevant. Sorry I can not help more.

Here’s my display func:

void display_func(void)
{
// Clear Screen And Depth Buffer
glClearColor (.5f, .5f, .5f, .5f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);

#define ZERO 0.0f
#define ONE 1.0f
glLoadIdentity(); // Reset The Modelview Matrix
glBegin(GL_QUADS);
glTexCoord2f(ONE , ONE ); glVertex3f( ONE, ONE, 0);
glTexCoord2f(ZERO, ONE ); glVertex3f(-ONE, ONE, 0);
glTexCoord2f(ZERO, ZERO); glVertex3f(-ONE,-ONE, 0);
glTexCoord2f(ONE , ZERO); glVertex3f( ONE , -ONE, 0);
glEnd();

}

if I use glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); I don’t get translucent texture image, but if I set glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
the texture is shown with translucency.

Either way the background is Opaque.

Also I call:

glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);

When initializing and I don’t change it any more.

Well it looks your code is correct, maybe some added magic is needed on the glx initialisation, or more probably the driver/compositing manager do not play well together.
Can you provide exact version of your drivers, linux distribution, desktop manager (gnome or kde), etc ? Somebody more knowledgable may help.

Is the texture created as premultiplied alpha ? Ie. transparent parts are black ? This is kind of moot anyway if the window alpha is not taken in account.

I’m using Slax with kde, I’m now finishing some work in Windows, as soon as I’ve finished I’ll restart my machine in Linux and try to be more precise.

Texture data is obtained from the webcam using “V4L2_PIX_FMT_BGR24” color palette. I create the openGL texture just as Nehe’s lesson 35 example for displaying avi files does.

What I don’t quite get is why does the texture appear with translucency and blended with the scene background but the scene background isn’t blended with the windows behind it. If I drag the window border to make it bigger than the quad and let the background visible I can see this issue perfectly clear.

It seems you’re right and it has more to do with glx initialisation. In that case, is this forum the correct place to post this question or should I move this to another more especific on glx (which I haven’t found yet :wink: )?

Again, many thanks for your advice.

Here is a good place for glx questions.

However as the compositing issue crosses a lot of projects (gl driver, glx, X server, compositer, desktop manager) maybe you can find elsewhere a mailing list able to provide more definitive answers.

In any case, please followup on this thread too :slight_smile:

Ok, here are some specs:

slax 2.6.24.4

KDE version 3.5.9

X.Org X Server 1.4.0.90

OpenGL vendor string: ATI Technologies Inc.

OpenGL renderer string: Radeon X1300/X1550 Series

OpenGL version string: 2.1.7415 Release

client glx version string: 1.4

server glx version string: 1.2

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.