SFML community forums
Help => Window => Topic started by: Svenstaro on March 20, 2010, 05:55:24 pm
-
Hi,
I'm aware this question has been asked before but it has not been solved. I looked into this quite a bit and it turns out that this is a complex problem after all. I "only" want to have a fully transparent window with per-pixel alpha SFML drawings on top. I also aware that this is a non-trivial task. I settled on using Qt and SFML in combination to get the best odds in solving this.
Basically, I figured I'll want two codepaths for my window-less application:
Path 1 is without a compositing window manager (No Kwin, Aero or Compiz active). It will just take a screenshot at the beginning using Qt since SFML can't do that for me yet, sadly (hint, hint), and put it as the window background with the correct subrect. This works and obviously is sub-optimal.
Path 2 is the part I'm struggling with. I'd like to make use of an available desktop compositor as many modern desktops are running one. This will save me from the screenshotting but presents me with other problems. SFML can't make a transparent window and thus I used Qt with the window attributes Qt::WA_NoSystemBackground and Qt::WA_TranslucentBackground. This works (the window is transparent when a compositor is active) but this is also the place where I'm struggling.
I now need to get my SFML data into Qt somehow draw it on top. Or can I directly use the SFML canvas trick from the tutorials and somehow make it transparent? Clear() can't clear to alpha.
Help :D
-
Further research has shown that QImage can be constructed from a memory location. I thought I could use sf::Image's .GetPixelPtr() but so far I failed to find the right parameters for QImage (http://doc.trolltech.com/4.6/qimage.html) to make it load correctly.
Would this even be a fast enough way to transfer the images between Qt and SFML to play back a fluent animation?
-
I'm not sure that what you want to do is possible. The window manager / Qt / whatever may not be able to link the alpha chanel of the OpenGL backbuffer to the opacity of the window.
It will just take a screenshot at the beginning using Qt since SFML can't do that for me yet, sadly (hint, hint)
SFML can give you the contents of the windows that it manages, but nothing which is outside (you want the full desktop, right?).
-
Yup, I wanted to do the fake transparency using a subrect of a full screen shot and thus I used Qt for it.
Now basically I just need to get my images from SFML into the QImage format without losing transparency. Could you help me? I still haven't figured out which of the constructors of QImage I should use how in order to load the sf::Image structure.
-
Probably this one
QImage ( const uchar * data, int width, int height, Format format )
However it doesn't seem that there is a format for RGBA, the closest one is QImage::Format_ARGB32. So you'll probably have to manually swap the channels.
-
Would I have to use to use SFML 2 in order to render to an image directly without having to render to a (hidden?) window first and then retrieving the sf::Image?
Or rather, is it possible to render to image without using a SFML window in SFML 1.5?
-
Or rather, is it possible to render to image without using a SFML window in SFML 1.5?
No.
-
Is that feature usable in SFML 2 already? Can I render to the RenderImage and keep its background fully transparent?
-
Yes ;)
-
Awesome, thanks a lot. Looks like I'll be switching to SFML 2 in a few minutes :).
-
Awesome, thanks a lot. Looks like I'll be switching to SFML 2 in a few minutes :).
I realize this is an ancient thread - but any chance you can share some code in how you achieved this?
-
I ended up using straight Qt for it and it was fairly easy. The code for that is here: https://github.com/svenstaro/qponies
It doesn't use any SFML though.
-
I ended up using straight Qt for it and it was fairly easy. The code for that is here: https://github.com/svenstaro/qponies
It doesn't use any SFML though.
Cool thanks for the quick reply. I'm not familiar with QT but I will check it out (and your GIT repo). Thanks!