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

Author Topic: OpenGL Context Flashes on Screen when Created  (Read 10283 times)

0 Members and 1 Guest are viewing this topic.

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
OpenGL Context Flashes on Screen when Created
« on: January 25, 2014, 12:24:48 am »
So I am trying to make my program cleaner, and this is one issue that has been bother me for a while.

When I call create() for a new OpenGL window, it displays with a black background, flashes a white background for a second then disappears. This happens as soon as it is created even if I never initialize OpenGL or call display(), also if I do.

This is doubly frustrating as I create a test context to pull OpenGL version and check for the systems compatibility before creating the 'real' context with my OpenGL version as part of the create() call. So I get window->flash->disappear->window->flash->disappear->real window as my start up sequence. It is jarring. I would LOVE to just have a black screen throughout this process!

Anything I can do?

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: OpenGL Context Flashes on Screen when Created
« Reply #1 on: January 26, 2014, 06:11:07 pm »
Can anyone confirm that this happens on their systems/builds as well? Still not sure exactly what is going on here.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: OpenGL Context Flashes on Screen when Created
« Reply #2 on: January 26, 2014, 07:33:28 pm »
Well we couldn't test it, since you didn't provide a minimal and complete example. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: OpenGL Context Flashes on Screen when Created
« Reply #3 on: January 27, 2014, 07:14:15 am »
Using SFML 2.1 running on Window 8 this does it for me:

#include <SFML/Window.hpp>

int main()
{
        sf::Window testWindow;
        testWindow.create(sf::VideoMode::getDesktopMode(), "TEST WINDOW", sf::Style::Fullscreen);
        return(0);
}
 
« Last Edit: January 27, 2014, 07:20:30 am by Acumen »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: OpenGL Context Flashes on Screen when Created
« Reply #4 on: January 27, 2014, 02:32:30 pm »
This is doubly frustrating as I create a test context to pull OpenGL version and check for the systems compatibility before creating the 'real' context with my OpenGL version as part of the create() call.

Anything I can do?

You should use a sf::Context for this task (testing version, compatibility). http://sfml-dev.org/documentation/2.1/classsf_1_1Context.php

So you can check everything without creating a window and then create only one (the real) window...


AlexAUT

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: OpenGL Context Flashes on Screen when Created
« Reply #5 on: January 27, 2014, 05:06:02 pm »
If you create an sf::Context it always initializes as OpenGL 2.0. You have to create the window without passing a context specifying OpenGL version and read the system OpenGL version with window.getSettings(). Then if the system is capable of handling your program you have to create a new window with your correct OpenGL version. At least as far as my testing has shown.

It would be nice to find the OpenGL version without creating a temp Window, but even then I would still get a flash when I create the actual Window for my program.
« Last Edit: January 27, 2014, 05:13:11 pm by Acumen »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: OpenGL Context Flashes on Screen when Created
« Reply #6 on: January 27, 2014, 05:49:45 pm »
The way I think Laurent intended it to work, is by creating the window with the version you want, SFML will then automatically choose the next best context (i.e. it will downgrade if the requested version isn't available) and then you check what version you actually got and react accordingly.

SFML doesn't have all the control over how a window gets created, thus I'd have to look at the source to see whether one could ensure that it stays black through the whole process. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: OpenGL Context Flashes on Screen when Created
« Reply #7 on: January 27, 2014, 06:48:09 pm »
The way I think Laurent intended it to work, is by creating the window with the version you want, SFML will then automatically choose the next best context (i.e. it will downgrade if the requested version isn't available) and then you check what version you actually got and react accordingly.
.
Yeah that makes sense, but it eliminates being able to log the users actual supported version if it is above the target. I guess that is less important than removing a flash to me though and I don't use that number for anything in the program only metrics so I can live with that

SFML doesn't have all the control over how a window gets created, thus I'd have to look at the source to see whether one could ensure that it stays black through the whole process. ;)
To me it seems like during .create() it creates a window, displays it, clears it in white, then hides/destroys it. Possibly to pull the system variables? I would much rather leave it open! Or maybe have a flag to? Also would much much rather have it black, or be able to pass a color. I am not at my dev machine so I can't peek at the source right now.

Is this the kind of thing I should open a ticket for?

Does anyone else even have this issue? Could it be system dependent? Still haven't heard from anyone.

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: OpenGL Context Flashes on Screen when Created
« Reply #8 on: February 08, 2014, 08:31:40 pm »
Still very interested in this, and still have not heard either way what happens with other people in regard to this issue. Anyone have a comment?

I was poking around in the source and possibly have a lead.

window::create()

calls

1) WindowImpl::create which makes a new WindowImplType which is a WindowImplWin32 which calls CreateWindowA() then calls then calls switchToFullscreen() which calls ShowWindow(m_handle, SW_SHOW);

2) GlContext::create which calls:

2A) ensureContext(); calls  getInternalContext() calls sf::priv::GlContext::create() calls GlContext* context = new ContextType(sharedContext); which is a WglContext that calls CreateWindowA() then  ShowWindow(m_window, SW_HIDE);

2B) GlContext* context = new ContextType(sharedContext, settings, width, height); which calls CreateWindowA() then  ShowWindow(m_window, SW_HIDE);

3) window::initialize() which calls setVisible(true); which calls ShowWindow(m_handle, SW_SHOW);

So it looks to me like the important part is the:

SW_SHOW
SW_HIDE
SW_SHOW

that is possibly called every time a fullscreen window is created? I may be way off the mark but this is the best I could find so far. Not sure what the best solution is, but personally I would rather have a window not show at all unless I told it to as part of my initialization instead of the switchToFullScreen and window::create automatically showing.

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: OpenGL Context Flashes on Screen when Created
« Reply #9 on: February 10, 2014, 03:41:33 pm »
Can anyone confirm what happens with their context when a new window is created?

I submitted a bug report but as the issue is not confirmed it was closed. This happens to me every time I open a window, so it is definitely a bug for me, with my minimal example above. I have not had anyone confirm this happens or DOES NOT happen to them either. Coming up on 3 weeks into this thread, anyone?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: OpenGL Context Flashes on Screen when Created
« Reply #10 on: February 10, 2014, 04:34:11 pm »
The issue does not come from the window showing/hiding, but from the fact that you requested a fullscreen window. When you request a fullscreen window, your window will actually takes over the entire screen/device while it is open (and was actually required years ago for performance reasons).

It is impossible to create a fullscreen window at initialization, so the screen flash you see is actually the windows os switching the window to fullscreen mode (and this does in fact take a few seconds and happens with any game that utilizes a true fullscreen window - aka this is not a SFML issue).

What I suggest you do is avoid using sf::Style::Fullscreen and instead use sf::Style::None. On any modern hardware you actually won't gain any real performance (at least on any game you will make with SFML) from using a true fullscreen window vs a borderless window the size of the desktop.  ;)
« Last Edit: February 10, 2014, 05:16:40 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: OpenGL Context Flashes on Screen when Created
« Reply #11 on: February 10, 2014, 07:02:39 pm »
Oh amazing! Definitely a big improvement thank you very much.

I still have a bunch of issues/questions, this is what I currently get. When I say OS event what happens is all monitors flash black then return to normal.

When creating a new window:

sf::Style::Fullscreen:
1) Fullscreen window appears with white background*
2) Background changes to black
3) OS event
4) Displays my draw call

sf::Style::Default:
1) Framed window appears with white background*
3) Displays my draw call

*White background stays long enough to see it even if next line is a display call.

sf::Style::None with size < Desktop:
1) Frameless window appears when I make my first draw call

sf::Style::None with size == Desktop:
1) OS event
1) Frameless window appears when I make my first draw call

When I close a sf::Style::None with size == Desktop or a Fullscreen window there are 2 OS events.

When exactly does the OS event occur?
Is it possible to use sf::Style::None with size == Desktop without the OS event, as it behaves when size < the desktop?
Is it possible to use sf::Style::Default without the white background appearing?

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: OpenGL Context Flashes on Screen when Created
« Reply #12 on: February 10, 2014, 07:25:18 pm »
Does it still flash white if you do this:
testWindow.create(sf::VideoMode::getDesktopMode(), "TEST WINDOW", sf::Style::None);
window.clear(sf::Color::Black);
window.display();
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: OpenGL Context Flashes on Screen when Created
« Reply #13 on: February 10, 2014, 08:08:12 pm »
Clear() is an sf::RenderWindow function not am sf::Window function, but as I list in my last post with sf::Style::Default I get the white background and display() does clear to black but even if it is my next line the white is visible prior. With sf::Style::None I get an OS Event not a white background if the size = desktop.
« Last Edit: February 10, 2014, 08:12:32 pm by Acumen »

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: OpenGL Context Flashes on Screen when Created
« Reply #14 on: February 10, 2014, 09:06:30 pm »
I'm sorry. I missed that part.
I'd maybe try to setup the window at the same time as you create the window object (using its constructor).
But, apart from that, the "OS event", as you call it, of all monitors flashing black sounds a bit odd and I would think that it could be (as mentioned previously) drivers (not up-to-date or just unreliable) or another process running in the background that might be interfering. I'd especially check for video capture software etc..
If you're sure it's not that stuff, I don't know enough to suggest anything else, sorry :p
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything