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

Author Topic: New renderWindow makes main renderWindow white  (Read 2482 times)

0 Members and 1 Guest are viewing this topic.

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
New renderWindow makes main renderWindow white
« on: August 27, 2014, 10:26:34 pm »
Hey guys, I encountered a bit of an issue. I want to create a new renderWindow so I can manipulate images, but when I do it the screen flashes. It is different depending on the main window style (none, closed or fullscreen).
None/closed: the screen flashes for a really short (but noticeable) time and then regains focus
Fullscreen: the screen goes white for a really short (but noticeable) time and then regains focus

Both of them are a little bit annoying, but the fullscreen it is even worse, as the screen goes white for a moment.

I think it is because the new renderWindow gets the focus as it is a new window, but I don't know how to solve it. Tried using setVisible(false) but didn't work out as I wanted.

Minimal code:
#include <SFML/Graphics.hpp>

using namespace sf;

int main()
{
    //RenderWindow mainWindow(VideoMode(1680, 1050, 32), "SFML Windowed Fullscreen", sf::Style::None);
    //RenderWindow mainWindow(VideoMode(1280, 720, 32), "SFML Windowed", sf::Style::Close);
    RenderWindow mainWindow(VideoMode(1680, 1050, 32), "SFML Fullscreen", sf::Style::Fullscreen);

    while (mainWindow.isOpen()){
        Event event;
        while (mainWindow.pollEvent(event)){
            if (event.type == Event::KeyPressed && event.key.code == Keyboard::Escape){
                mainWindow.close();
            }
            if(event.type == Event::KeyPressed && event.key.code == Keyboard::F){
                RenderWindow newWindow(sf::VideoMode(320, 128, 32), "Creating character", sf::Style::None);
                ///do stuff with the newWindow, and then it is useless
                newWindow.close();
            }

        }

        mainWindow.clear();
        ///draw main window stuff
        mainWindow.display();
    }

    return 0;
}

 

Note: My monitor goes up to 1680x1050, so that is my max resolution.

Any help, or hunches apprecieated! :D

Hapax

  • Hero Member
  • *****
  • Posts: 3058
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: New renderWindow makes main renderWindow white
« Reply #1 on: August 28, 2014, 12:05:56 am »
I've noticed this too and my "solutions" were just to make it easier for me to look at, nothing solid really.
1) Sometimes, just adding a renderWindow.clear(sf::Color::Black); seemed to removed the flash. If not, it can reduce the duration that it is white for
2) Bit more work but I end up using this if it annoys me: create a quick fade animation that transitions from white to black (or whichever colour). Looks better than that strobe thing.
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: New renderWindow makes main renderWindow white
« Reply #2 on: August 28, 2014, 01:39:04 am »
Thanks for your solutions, but none seemed to work so well on my side.

What I am using it for, it's to create an in-game character creator. I use the extra render window to manipulate images, and then turn them with capture() and then save them to a file with saveToFile().

If there is no other solution, I might try not to use the window, and use only sf::Image.

EDIT: Not using render window was way cleaner, and effective. My personal conclusion is that renderWindows shouldn't be used for what I was using them. Want image manipulation? Use sf::Image
« Last Edit: August 28, 2014, 01:50:35 am by santiaboy »

Hapax

  • Hero Member
  • *****
  • Posts: 3058
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: New renderWindow makes main renderWindow white
« Reply #3 on: August 28, 2014, 04:28:24 am »
My first "solution" should have been:
Sometimes, just adding a renderWindow.clear(sf::Color::Black); immediately after window creation seemed to removed the flash. If not, it can reduce the duration that it is white for.
It's not the ideal solution by any means.

Are you creating a RenderWindow to draw to it and then capture those drawings as an image? Why not use a RenderTexture instead? It does things the same way that a RenderWindow does but doesn't display a window.
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: New renderWindow makes main renderWindow white
« Reply #4 on: August 28, 2014, 07:27:33 am »
RenderTexture doesn't have "capture". I would have had to something like getTexture().copyToImage().

In any case, using only Image turned out to be better for the thing I wanted.

Hapax

  • Hero Member
  • *****
  • Posts: 3058
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: New renderWindow makes main renderWindow white
« Reply #5 on: August 28, 2014, 02:08:08 pm »
Ah, fair enough. I thought you needed the render part and that's why you were using a render window  :D
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter