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

Author Topic: Screen flash on SFML programm start  (Read 5091 times)

0 Members and 1 Guest are viewing this topic.

lzedl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Screen flash on SFML programm start
« on: August 04, 2012, 05:43:45 pm »
First issue:
When i start programm writing using SFML it flash on start?
Why it happens and can i somehow avoid it?

Second issue:
I try to make some text area that holds text that non fully render at the same time.
I think that prerender is good idea for this. First of all i break text to lines and store it in strings vector "lines_".
Than i found only one way to make texture with text on it - it's sf::TextureRender
Code:
    //strH - is any string height
    texture_.create(width(), (strH+lineInterval_)*lines_.size());
    texture_.clear(sf::Color::Transparent);
    sf::Text txt("", font_, 8);
    txt.setColor(sf::Color::White);
    sf::Text shdw("", font_, 8);
    shdw.setColor(sf::Color::Black);
    for(uint i = 0; i < lines_.size(); i++)
    {
        txt.setString(lines_.at(i));
        shdw.setString(lines_.at(i));
        txt.setPosition(i*(strH+lineInterval_), 0);
        switch(align())
        {
        case LEFT:
            txt.setPosition(0, i*(strH+lineInterval_));
            shdw.setPosition(1, i*(strH+lineInterval_)+1);
            break;
        case RIGHT:
            txt.setPosition(width()-txt.getGlobalBounds().width, i*(strH+lineInterval_));
            shdw.setPosition(width()-txt.getGlobalBounds().width+1, i*(strH+lineInterval_)+1);
            break;
        case CENTER:
            txt.setPosition((width()-txt.getGlobalBounds().width)/2, i*(strH+lineInterval_));
            shdw.setPosition((width()-txt.getGlobalBounds().width)/2+1, i*(strH+lineInterval_)+1);
            break;
        }
        texture_.draw(shdw);
        texture_.draw(txt);
    }
    sprite_.setTexture(texture_.getTexture());
 
Every time i use this code screen flashs... I know about texture size limit, but can i somehow avoid it?
May be use some other way to prerender text and make a texture with it.

Just in case when i make large sf::Image and later make a sf::Texture using this image screen didn't flash, why?

I'll be glad for any help with it

P.S.: Sorry for bad English

lzedl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Screen flash on SFML programm start
« Reply #1 on: August 04, 2012, 05:51:29 pm »
forgot to mention:
when i render with sf::TextureRender all text is drawn head over heels =)
Why? )

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10226
    • View Profile
    • development blog
    • Email
Re: Screen flash on SFML programm start
« Reply #2 on: August 04, 2012, 08:06:48 pm »
I've no idea what you mean with 'flashing', this could be anything and nothing. Also your very vague when and where it happens... :-\

What is the problem with the 'second issue'?
If you have an issue with texture size limit, then you should get an error on the console. Also there are a few ways to work around this, by splitting the texture into a few smaller ones, but I don't think that's really what you want/need.

when i render with sf::TextureRender all text is drawn head over heels =)
You probably use the transformation wrong or similar.

You should also keep this thread in mind!
If you want our help you need to provide a minimal code example and describe your problems better (e.g. what sort of flashing are you mentioning) this can be illustrated with images or videos.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

lzedl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Screen flash on SFML programm start
« Reply #3 on: August 04, 2012, 09:26:27 pm »
Sorry, my english is very bad and may be this is the main reason why nothing is clear.

First issue:
I've no idea what you mean with 'flashing', this could be anything and nothing. Also your very vague when and where it happens... :-\

All code of program:
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(400, 300), "SFML works!");

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
    }
    return 0;
}
 

When i "run" this code all all screen goes black, then everything goes back and window appears. All last for about a second.
What i mean with 'flashing'.

Second issue:
When i create an sf::RenderTexture i get the same effect with all screen as i write above. I try to understand why it heppens and can i avoid it.

I gave the code above. But now i get more simple example:
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <unistd.h>

int main()
{
    sf::RenderWindow window(sf::VideoMode(400, 300), "SFML works!");
    usleep(5000000); //wait 5 second to see second screen effect
    sf::RenderTexture texture;
    texture.create(200, 200);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear();
        window.display();
    }

    return 0;
}
 

So, when i do "texture.create(200, 200);" screen goes black... everything as I described above.


You probably use the transformation wrong or similar.

The problem is that I did not use transformation.

You should also keep this thread in mind!
If you want our help you need to provide a minimal code example and describe your problems better (e.g. what sort of flashing are you mentioning) this can be illustrated with images or videos.
Most of problems cannot be illustrated with images or video. I try to describe my problems clearly, but i failed...

System:
OS: Linux (Archlinux) x86
Kernel: Linux version 3.0.38-1-lts (tobias@T-POWA-LX) (gcc version 4.7.1 (GCC) )
Video: NVIDIA Corporation G71 [GeForce 7900 GT/GTO]
Video driver: proprietary (nvidia)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10226
    • View Profile
    • development blog
    • Email
Re: Screen flash on SFML programm start
« Reply #4 on: August 04, 2012, 09:34:14 pm »
I see, thanks for making things a bit more  clearer.
Although you don't call window.display() nor window.clear() in the first example code it sounds like this is not related to SFML, but rather a graphics card driver problem.
To test this, can you execute the examples that come with SFML? If the same thing happens it's defently not related to SFML. You could also try other applications that use OpenGL to check if there's also some flashing happening. If so you probably will have to find another graphics card driver.

I guess you've compiled SFML on your own, since you're using GCC 4.7, right?
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

lzedl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Screen flash on SFML programm start
« Reply #5 on: August 04, 2012, 10:17:11 pm »
I see, thanks for making things a bit more  clearer.
Although you don't call window.display() nor window.clear() in the first example code it sounds like this is not related to SFML, but rather a graphics card driver problem.
To test this, can you execute the examples that come with SFML? If the same thing happens it's defently not related to SFML. You could also try other applications that use OpenGL to check if there's also some flashing happening. If so you probably will have to find another graphics card driver.
Exactly. It heppens when i create window (i think). I try exmple code from http://www.sfml-dev.org/tutorials/2.0/start-linux.php and it gives me same result  :(
I try other OpenGL games, but no problems occurs with them  :-\

I guess you've compiled SFML on your own, since you're using GCC 4.7, right?
No, i use complete package from official repository of ArchLinux version 2.0rc1-2. Build from 29.07.2012

Later i'll try another driver again and write about the results.

Thanks for the reply  :)  May be you have other ideas why this is happening?

lzedl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Screen flash on SFML programm start
« Reply #6 on: August 05, 2012, 11:45:29 am »
In addition to the issue about sf::TextureRender. I gave the code above.
This is result of drawing text on sf::TextureRender:


Please notice carefully. The original text is:
1
Lorem ipsum dolor sit
amet, consectetur
adipisicing elit, sed do
eiusmod tempor
incididunt ut labore et
dolore magna aliqua. Ut
enim ad minim veniam,
quis nostrud
exercitation ullamco
laboris nisi ut aliquip ex
ea commodo consequat.
Duis aute irure dolor in
reprehenderit in
...
 

It's hard to describe. All letters are reversed, but the text goes from left to right and from bottom to top

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Screen flash on SFML programm start
« Reply #7 on: August 05, 2012, 12:12:57 pm »
Don't forget to call RenderTexture::display().
Laurent Gomila - SFML developer

lzedl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Screen flash on SFML programm start
« Reply #8 on: August 05, 2012, 12:40:25 pm »
Don't forget to call RenderTexture::display().
Sorry. My fault  :)

But issue about "flashing" is still open :)
Is it a problem only in the driver?

lzedl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Screen flash on SFML programm start
« Reply #9 on: August 05, 2012, 01:27:31 pm »
I returning back to nouveau driver (open source) and problem with "flashing" disappeared.
But why in other OpenGL games there were no problems? :(
« Last Edit: August 05, 2012, 03:06:22 pm by lzedl »

lzedl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Screen flash on SFML programm start
« Reply #10 on: August 05, 2012, 03:05:57 pm »
In addition to the issue about sf::TextureRender. I gave the code above.
Now text problem:


All of this text is a one sf::Text object.

font in attachments.

[attachment deleted by admin]

lzedl

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Screen flash on SFML programm start
« Reply #11 on: August 05, 2012, 09:12:59 pm »
The open source driver is quite slow =(
Problems with the appear with both OpenSource and proprietary driver.


slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: Screen flash on SFML programm start
« Reply #12 on: August 06, 2012, 10:13:39 pm »
I have a similar issue, where my game is started from a menu system, and works fine until you click the screen the first time, where the screen goes black for 1 frame or so.

I think its related to the window not having focus, or needing to be raised, but I haven't had time to look into this yet.
SFML 2.1

 

anything