SFML community forums

Help => Graphics => Topic started by: gryczany on September 15, 2015, 09:06:39 pm

Title: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
Post by: gryczany on September 15, 2015, 09:06:39 pm
Hello,
just started learning SFML. I tried to make my first testing application.
Here's my code
Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "test");
    sf::Texture char_txt;
    if(!char_txt.loadFromFile("char.png"))
    {
        std::cout << "Failed to load char.png... exitting" << std::endl;
        return -1;
    }

    while(window.isOpen())
    {
        sf::Event ev;
        while(window.pollEvent(ev))
        {
            if(ev.type == sf::Event::Closed)
                 window.close();

            if(ev.type == sf::Event::KeyPressed && ev.key.code == sf::Keyboard::Escape)
                 window.close();
        }

        window.clear();
        window.display();
    }
    return 0;
}

After loading any texture, the RendererWindow becomes unusable - it's transparent, even the .clear() method doesn't work (see the picture in the attachment). Any suggestions how to fix this strange issue?

I'm using the latest SMFL version. My IDE is Code::Blocks 13.12, GCC version: 4.7.1 TDM.

Thanks in advance.
Title: Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
Post by: Satus on September 15, 2015, 09:43:10 pm
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php#af4322d315baf93405bf0d5087ad5e784
This will probably help.
Title: Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
Post by: gryczany on September 15, 2015, 09:56:36 pm
Still same, I used following values: 0, 1, 60.
Title: Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
Post by: Satus on September 16, 2015, 08:32:02 am
I have no idea what values you are talking about, but I was talking about
void sf::Window::setFramerateLimit ( unsigned int limit )
 
Title: Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
Post by: gryczany on September 16, 2015, 03:32:35 pm
I meant, I used this function with these values as the first argument (limit).

EDIT: Partially solved.

I moved the texture loading code before creating the RendererWindow, like this:

Code: [Select]
int main()
{
    /* ... */
    sf::Texture txt;
    txt.loadFromFile("txt.png");
   
    sf::RenderWindow window(sf::VideoMode(800, 600), "test");

    /* ... */
}

But I've encountered another problem.
When I load a texture, create a sprite and set the texture for it, then draw it,  the window becomes same as described before (it's transparent).

Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::Texture char_txt;
    if(!char_txt.loadFromFile("char.png"))
    {
        std::cout << "Failed to load char.png... exitting" << std::endl;
        return -1;
    }
    sf::Sprite char_sprite;
    char_sprite.setTexture(char_txt);

    sf::RenderWindow window(sf::VideoMode(800, 600), "test");
    window.setFramerateLimit(60);

    while(window.isOpen())
    {
        sf::Event ev;
        while(window.pollEvent(ev))
        {
            if(ev.type == sf::Event::Closed)
                 window.close();

            if(ev.type == sf::Event::KeyPressed && ev.key.code == sf::Keyboard::Escape)
                 window.close();
        }

        window.clear();
        window.draw(char_sprite);
        window.display();
    }
    return 0;
}
Any ideas?
Title: Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
Post by: binary1248 on September 16, 2015, 04:28:58 pm
Build your application in debug (cause you know... it's meant for de-bugging stuff...) linking to the debug SFML libraries and see if anything shows up in the console output.
Title: Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
Post by: gryczany on September 16, 2015, 08:11:33 pm
In debug mode, nothing is being shown in the console.

I realised that my old integrated Intel GPU or buggy drivers cause this issue. I ran my application on my desktop computer with a dedicated GPU and everything went right - I could load the texture and draw the sprite without any problems.

Thanks for help to you and to the guys on IRC.