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

Author Topic: Window transparency problem - SFML 2  (Read 5564 times)

0 Members and 1 Guest are viewing this topic.

nullByte

  • Newbie
  • *
  • Posts: 6
    • View Profile
Window transparency problem - SFML 2
« on: September 18, 2012, 07:09:21 am »
Im trying to create a simple splash screen which:

1. loads an image (.png that has transparent parts)
2. renders the image and its transparency by itself (no window, titlebar, etc)

My image.png loads fine but the transparency isn't transferring over to the window.
ie. If I load 2 images and position one behind the image with transparency. The second image is shown through the transparent parts of the first image.

If I load the single transparent image and render it my desktop and other windows behind the RenderWindow aren't showing through the image's transparent parts.
It just displays black in those areas.

I have the clear color set to (0, 0, 0, 0), so it has a 0 alpha channel but its not as simple as that.

Im not sure if what Im wanting is even possible.

My code:
// Inside int main()
splashWindow.create(sf::VideoMode(splashTextureSize.x, splashTextureSize.y, 32),
        "None",
        sf::Style::None);

splashWindow.clear(sf::Color(0, 0, 0, 0));
splashWindow.draw(splashSprite);
splashWindow.display();
 

splashShprite is the .png image which contains transparent sections.

Ive also tried messing with different ContextSettings (using different gl versions from 2.0 to 4.3) to no avail.

Any Ideas,
Thanks in advance!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Window transparency problem - SFML 2
« Reply #1 on: September 18, 2012, 08:17:39 am »
The window and what you draw to it are two different things. If you want the window to be transparent, you have to use specific OS functions, which are not abtracted by SFML.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Re: Window transparency problem - SFML 2
« Reply #2 on: September 18, 2012, 01:24:10 pm »
Window  transparency is a bitch in Windows. Also even if you get the window to be transparent I dont think clear takes alphavalues (I know render-textures dont).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Window transparency problem - SFML 2
« Reply #3 on: September 18, 2012, 01:56:44 pm »
Quote
Also even if you get the window to be transparent I dont think clear takes alphavalues (I know render-textures dont).
It does. But it won't help, I think you have to define the alpha mask of your window yourself, it can't magically use the one of your OpenGL back buffer.
Laurent Gomila - SFML developer

nullByte

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Window transparency problem - SFML 2
« Reply #4 on: September 19, 2012, 05:35:57 am »
Thanks for the help, Im going to look more into this when I have time.

Im using linux so if anyone has any information on what Im trying to do using x11 windows Id much appreciate it.
« Last Edit: September 19, 2012, 05:37:32 am by nullByte »

nullByte

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Window transparency problem - SFML 2
« Reply #5 on: September 20, 2012, 03:10:46 am »
Does sfml expose any of the os specific windows functions, like the x window lib?

** Update
Ive been looking through the sfml source while reading about the X window library, what I found is this:

It seems that  for what I want to do, I would have to modify my windows background pixmap and either set it to the parent (unmodifiable image of my desktop) or copy from parent (would allow me to do image filtering etc.).

In the sfml source (src/SFML/Window/Linux/WindowImplX11.cpp) I found this:

    // Define the window attributes
    XSetWindowAttributes attributes;
    attributes.event_mask = eventMask;
    attributes.override_redirect = fullscreen;
 

If I modified it so that I add...
(I would have to ensure that my window has the same depth as the parent too...)

    // Define the window attributes
    XSetWindowAttributes attributes;
    attributes.event_mask = eventMask;
    attributes.override_redirect = fullscreen;
   
    // My code
    attributes.background_pixmap = ParentRelative    // I believe ParentRelative is the x11 const / enum?
 

I intend to test this myself when I have more time (since Ill probably be recompiling sfml a lot to test it Ill probably save it for the weekend  ;D)

In the mean time; do you believe this is the solution im looking for?
Would I even have to recompile sfml, could I just modify the X windows attributes from the window handle provided by sfml?
« Last Edit: September 20, 2012, 05:19:53 am by nullByte »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Window transparency problem - SFML 2
« Reply #6 on: September 20, 2012, 07:52:48 am »
Quote
could I just modify the X windows attributes from the window handle provided by sfml?
Yes, you can probably do that.

http://tronche.com/gui/x/xlib/window/XChangeWindowAttributes.html
Laurent Gomila - SFML developer