Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Transparent windows

Credits go to Edgar Reynaldo for helping out!
This thread is locked; no one can reply to it. rss feed Print
Transparent windows
urskogshumla
Member #16,942
January 2019
avatar

Hi!

So, when developing with GLFW on linux, it was very straightforward to achieve this goal. I just used the GLFW_TRANSPARENT_FRAMEBUFFER window hint and a glClearColor with an alpha of 0.0, fired up my compositor and it was working dandy. Now, all cozy with allegro instead, I can't find any such solutions. So my question is: Are there any?

And follow up question: Can allegro alternatively use a glwf window to do its rendering? If so; then I could just spin up a glfw window, tell allegro to use that rendering context/window, and use glClear/hints/clearcolor as usual. Is this possible?

I'm pretty new to the allegro library, so sorry if these are questions with obvious answers or so.

Hugs

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

The key to transparent windows is the gl context creation. Since allegro doesn't support using a custom context, you can't currently do it with Allegro.

However, allegro can still give you a HWND on Windows, which you can use to set the window properties and the color key which allows shaping the window with a single transparent color. This does not work for translucency though, for that, again, you need a custom gl context.

urskogshumla
Member #16,942
January 2019
avatar

Thank you!

I downloaded the git version of allegro from the arch user repositories instead, and made a few changes with help from a GLX example by datenwolf:

GLX example: https://github.com/datenwolf/codesamples/blob/master/samples/OpenGL/x11argb_opengl/x11argb_opengl.c
Changes made to 'src/x/xglx_config.c': https://pastebin.com/e1F1S8W4

And I ended up with translucent windows, using ALLEGRO_ALPHA_SIZE 8, al_map_rgba colors and compton as compositor.
See the attached image for a screenshot of an allegro window with translucent background.

Hugs

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

So that gray square is your transparent window? Neat!

Do you think you could do the same for Windows? I don't know the specifics of making a WGL context transparent, but it would be awesome if Allegro could do this for all platforms. For OpenGL at least.

EDIT
I found this :
https://stackoverflow.com/questions/4052940/how-to-make-an-opengl-rendering-context-with-transparent-background

Which shows a few different ways. I never used dhpoware's demo code because I didn't understand pbuffers. It looks like all you have to do is change the PIXELFORMATDESCRIPTOR a little bit before you pass it to the rest of the routine.

Maybe I can make a patch for this, not sure.

I've made transparent mice windows before using DIBs but that is no good for anything larger than an icon. And it's way too messy trying to bitblt to the HDC all the time.

urskogshumla
Member #16,942
January 2019
avatar

Nice!

I haven't had a windows machine since elementary school; so I am of no help in that department. But if someone more windows-oriented makes a patch then maybe we could begin to formulate some kind of PR?

And yeah, transparency totally is neat, for example it makes live overlays possible during screen capture (logos, info, key presses and such). I myself am doing some kind of interactive audiovisual thing for a concert, using a lot of nodes in separate windows that react to screen position and each other. It aint the most beautiful solution but hey, it utilizes the existing window manager for dragging the nodes around, that idea has got to score some unix philosophy points ;)

Hugs

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I found datenwolf's wglarb demo, and I'm trying to get it to work as we speak. Right now it draws a white window, not a transparent one, so it's not working yet.

As for the PR, for X11, you'd need to incorporate the changes into the window creation system. Can't just enable translucency for every window.

On #allegro on IRC on freenode, I was talking to SiegeLord, and he said adding ALLEGRO_TRANSLUCENT_WINDOW to the new display flags was okay. But the meat of the matter still needs to be implemented.

EDIT
Some progress.

This (https://pastebin.com/BfaHf1NJ) is one way to do it using PFD_SUPPORT_COMPOSITION, and it works on Vista up, simply by asking for a different pixel format.

You can see it here :

{"name":"WNhv2if.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/5\/a5a937eda446b908fdffe4292fd0a591.png","w":1403,"h":509,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/5\/a5a937eda446b908fdffe4292fd0a591"}WNhv2if.png

EDIT2
You can get identical results using WGL_TRANSPARENT_ARB. I got datenwolf's layered.c demo to work, but I had to edit it. He made the window style WS_OVERLAPPED_WINDOW, which doesn't work. It needs to be WS_POPUP style to work properly.

I'm in the process of modifying a local fork of Allegro 5.

Go to: