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

Author Topic: My game run really slow when using sf::Text ? : (  (Read 4547 times)

0 Members and 1 Guest are viewing this topic.

virus7

  • Newbie
  • *
  • Posts: 11
    • View Profile
My game run really slow when using sf::Text ? : (
« on: August 02, 2012, 01:35:08 pm »
Hello,

I'm using SFML 2.0.

I only have three instances of the Text class :


sf::Text heroText("Get of my face ... ");
sf::Text instText("Press 'Space' to speak with people, 'Z' or 'X' to rotate \n and arrows to move");
sf::Text anonyText("?");
 

However, when I draw those instances like this :


window.draw(heroText);
window.draw(instText);
window.draw(anonyText);
 

the program at first run slow, but then after like 15 seconds it return to it's normal speed.
So why when I remove the window.draw functions it run at normal speed , but when I use them it run slow at first ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: My game run really slow when using sf::Text ? : (
« Reply #1 on: August 02, 2012, 01:37:37 pm »
Can you write a complete and minimal example that reproduces this problem, so that we can test it?

It doesn't need to be your complete game, just a minimal app that shows the problem.
Laurent Gomila - SFML developer

virus7

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: My game run really slow when using sf::Text ? : (
« Reply #2 on: August 02, 2012, 02:26:25 pm »
Ok, here is a part of the game code

you can download the two images ( background and character ) from mediafire

http://www.mediafire.com/?9iiwjt6n6ij5jmi

sorry it's too big for the attachment :  )

also I can upload a video on youtube to show you the problem

I'm using Visual C++ 2008, and I'am using dynamic linking


#include <SFML/Graphics.hpp>

int main() {

    sf::RenderWindow window(sf::VideoMode(900, 550), "SFML works!");

        sf::Sprite spriteBg;
        sf::Sprite spriteHero;
        sf::RectangleShape Rect;
       
 
        sf::Text heroText("Get of my face ... ");
        sf::Text instText("Press 'Space' to speak with people, 'Z' or 'X' to rotate \n and arrows to move");
        sf::Text anonyText("?");

        sf::Image heroCharCK;
       
        sf::Texture background;
        sf::Texture heroChar;
       
        if(!heroCharCK.loadFromFile("heroChar.png")) {
                return EXIT_FAILURE;
        }
        heroCharCK.createMaskFromColor(sf::Color(255, 255, 255), 0);
        if(!background.loadFromFile("background.png")) {
                return EXIT_FAILURE;
        }
        if(!heroChar.loadFromImage(heroCharCK)) {
                return EXIT_FAILURE;
        }
               
        spriteBg.setTexture(background);
        spriteBg.setPosition(1.0f, 1.0f);

        spriteHero.setTexture(heroChar);
        spriteHero.setTextureRect(sf::IntRect(0, 0, 32, 32));
        spriteHero.setPosition(600.0f, 200.0f);

        Rect.setSize(sf::Vector2f(40, 70));
        Rect.setFillColor(sf::Color(41, 14, 152, 200));
        Rect.setPosition(100, 100);

        heroText.setPosition(spriteHero.getPosition().x + 32, spriteHero.getPosition().y);
        heroText.setCharacterSize(15);
        heroText.setStyle(sf::Text::Bold);

        instText.setPosition(200, 0);
        instText.setCharacterSize(15);
        instText.setStyle(sf::Text::Bold);

    while (window.isOpen()) {

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
                                Rect.move(-3, 0);
                        }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
                                Rect.move(3, 0);
                        }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
                                Rect.move(0, -3);
                        }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
                                Rect.move(0, 3);
                        }
               
        window.clear();        

        window.draw(spriteBg);
        window.draw(spriteHero);
               
        window.draw(Rect);
               
        window.draw(heroText);
        window.draw(instText);
        window.draw(anonyText);

        window.display();
    }

    return EXIT_SUCCESS;
}

 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: My game run really slow when using sf::Text ? : (
« Reply #3 on: August 02, 2012, 02:31:48 pm »
Thanks :)

Have you tried with only the text?

Have you tried to add an event loop (even if it's empty)?
Laurent Gomila - SFML developer

virus7

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: My game run really slow when using sf::Text ? : (
« Reply #4 on: August 02, 2012, 02:48:03 pm »
Yes , I was actually using this code :
but I removed it since it's not really useful in this demonstration : )


sf::Event event;       
while(window.pollEvent(event)){

                if (event.type == sf::Event::Closed) {
                     window.close();
                }
}
 

virus7

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: My game run really slow when using sf::Text ? : (
« Reply #5 on: August 02, 2012, 02:51:13 pm »

I just removed everything even the images and only kept the Rectangle and the text and it work perfectly !
so, I'm not sure if the problem is from the text or the images : (

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: My game run really slow when using sf::Text ? : (
« Reply #6 on: August 02, 2012, 02:58:17 pm »
Then try with only the sprites :P

Maybe it's just the number of entity that you draw, regardless of what they are. To verify that you can try to draw an increasing number of texts (and then sprites), and see what effect it has on the performances.

The only way to solve your problem is to clearly identify it, so you must run as many tests as possible in order to understand why your program behaves this way.
Laurent Gomila - SFML developer

virus7

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: My game run really slow when using sf::Text ? : (
« Reply #7 on: August 02, 2012, 03:02:48 pm »
Ok , know I'm really confused , when I run the game through visual C++ it behaves slow just I explained but then I tried to run the .exe file alone by clicking on it , and it runs just fine .

I have no idea why this happens .. is the problem from Visual C++ ?

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: My game run really slow when using sf::Text ? : (
« Reply #8 on: August 02, 2012, 03:14:29 pm »
When you run it from Visual C++ the debugger is usually attached to the executable, that may be the reason of the slowdown. It should not have this kind of impact nevertheless...

Even when you restart your machine it doesn't work better? What kind of hardware do you have?

virus7

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: My game run really slow when using sf::Text ? : (
« Reply #9 on: August 02, 2012, 03:15:55 pm »
Should I use ( sf::Texture and sf::Sprite ) every time I load an image ? isn't there another way ?

virus7

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: My game run really slow when using sf::Text ? : (
« Reply #10 on: August 02, 2012, 03:21:33 pm »
When you run it from Visual C++ the debugger is usually attached to the executable, that may be the reason of the slowdown. It should not have this kind of impact nevertheless...

Even when you restart your machine it doesn't work better? What kind of hardware do you have?

Even if I restart my computer it doesn't work better, my laptop is new 2011 , I'm using win7 64bit but now I'm using the integrated graphics card ( IntelĀ® HD Graphics 3000 ) not ATI , though I can use ATI graphics card

virus7

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: My game run really slow when using sf::Text ? : (
« Reply #11 on: August 02, 2012, 03:34:55 pm »
I guess i'm gonna have to use mingw command line for now till I find a solution for the Visual C++ thing
thanks Laurent for helping me out to know what's the problem : )
« Last Edit: August 02, 2012, 03:36:55 pm by virus7 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: My game run really slow when using sf::Text ? : (
« Reply #12 on: August 02, 2012, 03:43:09 pm »
What if you run it with CTRL + F5 (no debugger) from inside Visual Studio ?
Laurent Gomila - SFML developer

virus7

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: My game run really slow when using sf::Text ? : (
« Reply #13 on: August 02, 2012, 03:51:43 pm »
oh ! .. lol .. it works .. thank you so much .. brilliant idea xD

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: My game run really slow when using sf::Text ? : (
« Reply #14 on: August 02, 2012, 04:08:50 pm »
So it's the debugger. Strange...
Laurent Gomila - SFML developer

 

anything