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

Author Topic: Splash screen not showing  (Read 6172 times)

0 Members and 1 Guest are viewing this topic.

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Splash screen not showing
« on: April 07, 2014, 09:26:24 am »
I'm trying to create a splash screen on startup, but it seems that calling window.display() isn't sufficient to make the contents of the window instantly visible, for some reason. My procedure can be summed up as follows:
  • Fill the window with black (using a RectangleShape)
  • Load the splash screen into a texture.
  • Create a Sprite and draw it centred in the window.
  • Call display() on the window.
  • Play the sound. (This is the only part that works perfectly.)
  • Institute some sort of delay.
  • Repeat all the above steps a second time.

I actually have two problems; the main problem is that nothing shows up until the main event loop, by which point the splash screen has been erased; also, I'm unsure how to create the sort of delay where pressing a key ends it prematurely.

I'm not sure what portion of the code would be best to post here. It uses several utility functions, so simply copy-pasting the splash code would probably not be very instructive. The window does get created prior to the splash code, incidentally.

Stepping through the code in the debugger hasn't helped much, although somehow I'm sometimes able to see the second splash screen when I set certain breakpoints and hop between them with F9 (continue). With breakpoints disabled, this never seems to happen.

Any ideas? Or requests for particular parts of the code?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Splash screen not showing
« Reply #1 on: April 07, 2014, 09:30:14 am »
Like every other window, a splash screen must also be updated. Handle events and adhere to the usual clear/draw/display cycle.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Splash screen not showing
« Reply #2 on: April 07, 2014, 09:37:51 am »
Or to rephrase that answer: How do you expect something to show up, when you never draw anything? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Splash screen not showing
« Reply #3 on: April 07, 2014, 04:35:51 pm »
Uh, I did draw something. I called both the draw() and the display() functions. How does this not count as drawing something?

Like every other window, a splash screen must also be updated. Handle events and adhere to the usual clear/draw/display cycle.
Are you trying to say the window only updates if you're handling events? That seems odd.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Splash screen not showing
« Reply #4 on: April 07, 2014, 04:38:15 pm »
Uh, I did draw something. I called both the draw() and the display() functions. How does this not count as drawing something?
You have to call them repeatedly, not once, and you also have to call clear().

Are you trying to say the window only updates if you're handling events?
Yes, you must handle events to keep the window responsive.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Splash screen not showing
« Reply #5 on: April 07, 2014, 04:50:47 pm »
Are you trying to say the window only updates if you're handling events?
Yes, you must handle events to keep the window responsive.
Keeping it responsive implies I want the window to respond to input, which at this point isn't the case. Do you have to handle events even just for the window to be displayed?

As for clear(), I'm pretty sure you don't need to call it. Other stuff seems to be working perfectly fine without ever calling it.

EDIT: That said, this is a perfect situation for calling it, since I just want to fill the screen with black. (I actually forgot it existed.)
« Last Edit: April 07, 2014, 04:54:38 pm by Celtic Minstrel »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Splash screen not showing
« Reply #6 on: April 07, 2014, 04:54:01 pm »
You must handle events, even if you don't care for input. This is required or the OS will mark your process as unresponsive and window manager will most likely ask the user if they want to end the unresponsive process.

You must call clear or you may see graphics artifacts, there is no reason why you shouldn't call it.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Splash screen not showing
« Reply #7 on: April 07, 2014, 04:56:04 pm »
You must handle events, even if you don't care for input. This is required or the OS will mark your process as unresponsive and window manager will most likely ask the user if they want to end the unresponsive process.
I know the OS does this, but this is still during the initialization process. Normally you don't start handling events until after initialization is finished, right?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Splash screen not showing
« Reply #8 on: April 07, 2014, 05:06:59 pm »
As soon as there's a window on your screen, you should be handling events.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Splash screen not showing
« Reply #9 on: April 07, 2014, 05:12:14 pm »
You seem to mix two thing: handling events and using events.
They are two different things. Handling mean you support them. That is something you should always do as soon as you have a window.
Using them mean that you assign an event to an action in some sort of way.

In your case, you want to handle them, but not use them.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Splash screen not showing
« Reply #10 on: April 07, 2014, 05:30:24 pm »
That still seems very counterintuitive.

Anyway, I got it to work with what feels like a hack — loop the lines drawing the first splash 10 times and add an extraneous pollEvent() to that loop, and everything suddenly works perfectly. It doesn't make sense that I should need to draw the exact same thing 10 times for it to work (simply adding a pollEvent() without looping didn't help), but whatever. At least it works.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Splash screen not showing
« Reply #11 on: April 07, 2014, 05:35:00 pm »
Anyway, I got it to work with what feels like a hack
What about solving it properly? That is, draw it as long as it lives, not 10 times (what kind of magic number is that?!) and have an empty event polling loop.

It doesn't make sense that I should need to draw the exact same thing 10 times for it to work
I agree, 10 times really makes no sense. You should read the big red box in the SFML Graphics tutorial.

Why are you so scared of drawing and processing events? I really don't see why you try to find excuses why you wouldn't need either...
« Last Edit: April 07, 2014, 05:38:15 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Splash screen not showing
« Reply #12 on: April 08, 2014, 03:12:03 am »
Anyway, I got it to work with what feels like a hack
What about solving it properly? That is, draw it as long as it lives, not 10 times (what kind of magic number is that?!) and have an empty event polling loop.
10 was pretty much a random number. "As long as it lives" is roughly "until the sound finishes playing", so I might look into doing it properly later, but for now all I'm concerned with is that it works. At the moment I have other more important issues to focus on.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Splash screen not showing
« Reply #13 on: April 08, 2014, 07:02:20 am »
It's of course your choice, but the easiest, quickest and most robust solution would simply have been to do it like in every other window: clear/draw/display and pollEvents, as you are used to it. It's a matter of minutes, I wouldn't risk user-unfriendly behavior to save them ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: