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

Author Topic: loadFromFile() from sf::Texture makes RenderWindow blank and unusable  (Read 2356 times)

0 Members and 2 Guests are viewing this topic.

gryczany

  • Newbie
  • *
  • Posts: 4
    • View Profile
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.


gryczany

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
« Reply #2 on: September 15, 2015, 09:56:36 pm »
Still same, I used following values: 0, 1, 60.

Satus

  • Guest
Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
« Reply #3 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 )
 

gryczany

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
« Reply #4 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?
« Last Edit: September 16, 2015, 03:46:16 pm by gryczany »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
« Reply #5 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.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

gryczany

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: loadFromFile() from sf::Texture makes RenderWindow blank and unusable
« Reply #6 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.

 

anything