Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Fully transparent window with only SFML drawings?  (Read 14167 times)

0 Members and 1 Guest are viewing this topic.

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Fully transparent window with only SFML drawings?
« 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

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Fully transparent window with only SFML drawings?
« Reply #1 on: March 20, 2010, 06:25:30 pm »
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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Fully transparent window with only SFML drawings?
« Reply #2 on: March 21, 2010, 11:38:39 am »
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.

Quote
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?).
Laurent Gomila - SFML developer

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Fully transparent window with only SFML drawings?
« Reply #3 on: March 21, 2010, 02:45:09 pm »
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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Fully transparent window with only SFML drawings?
« Reply #4 on: March 21, 2010, 03:49:18 pm »
Probably this one
Code: [Select]
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.
Laurent Gomila - SFML developer

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Fully transparent window with only SFML drawings?
« Reply #5 on: March 21, 2010, 07:32:20 pm »
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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Fully transparent window with only SFML drawings?
« Reply #6 on: March 21, 2010, 07:47:54 pm »
Quote
Or rather, is it possible to render to image without using a SFML window in SFML 1.5?

No.
Laurent Gomila - SFML developer

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Fully transparent window with only SFML drawings?
« Reply #7 on: March 21, 2010, 08:29:52 pm »
Is that feature usable in SFML 2 already? Can I render to the RenderImage and keep its background fully transparent?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Fully transparent window with only SFML drawings?
« Reply #8 on: March 21, 2010, 08:32:47 pm »
Yes ;)
Laurent Gomila - SFML developer

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Fully transparent window with only SFML drawings?
« Reply #9 on: March 21, 2010, 08:42:30 pm »
Awesome, thanks a lot. Looks like I'll be switching to SFML 2 in a few minutes :).

wixard

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Fully transparent window with only SFML drawings?
« Reply #10 on: October 29, 2012, 11:08:54 pm »
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?

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Re: Fully transparent window with only SFML drawings?
« Reply #11 on: October 29, 2012, 11:16:33 pm »
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.

wixard

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Fully transparent window with only SFML drawings?
« Reply #12 on: October 30, 2012, 12:33:40 am »
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!

 

anything