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

Author Topic: [SOLVED] sf::Text not drawed  (Read 5235 times)

0 Members and 1 Guest are viewing this topic.

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
[SOLVED] sf::Text not drawed
« on: September 02, 2013, 08:56:15 pm »
Here is code:
/* virtual */ void Info::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
        SIMPLE_LOCK

        if (!mVisible || !mIsInitiated)
        {
                return;
        }

        sf::View old = target.getView();
        target.setView(mView);
        target.draw(mDrawText, states);
        target.setView(old);
}

About one hour ago text was on the screeen, after little refactoring - no text drawed. Target is active, GLstate reseted... Is there any simple reason for such behavior?


Solved: Use sf::InputStream with care!
« Last Edit: September 03, 2013, 08:03:07 am by ChronicRat »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Text not drawed
« Reply #1 on: September 02, 2013, 09:11:21 pm »
It could be anything. Only you knows what you changed during that hour. It can't be that much, right? So revert your changes step by step and you should find the error ;)
Laurent Gomila - SFML developer

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: sf::Text not drawed
« Reply #2 on: September 02, 2013, 09:26:23 pm »
Yes, i reverted all changes (as  i think), and i left only this object in render queue... Nothing on screen. May be sf::View is wrong? It is created by this code:

void Info::RecalcView(int x, int y)
{
        mScreenSize.x = (float) x;
        mScreenSize.y = (float) y;
        mView.reset(sf::FloatRect(0.0f, 0.0f, mScreenSize.x, mScreenSize.y));
}
All is looking good, but m_inverseTransform is equal to m_transform. They both are the identity matrixes. Is it correct?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Text not drawed
« Reply #3 on: September 02, 2013, 09:45:30 pm »
Obviously, you can't have reverted everything, if it worked before and doesn't work anymore now. Don't you use a versioning system? That's one of the huge advantages: You can roll back at any time, where stuff still works.

The view looks good. You have to debug further, or if you want us to see the error, reduce the code until you have a minimal and complete example, otherwise we can only guess.

By the way, what is SIMPLE_LOCK? It looks dangerous ???
« Last Edit: September 02, 2013, 09:47:54 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

G.

  • Hero Member
  • *****
  • Posts: 1590
    • View Profile
Re: sf::Text not drawed
« Reply #4 on: September 02, 2013, 09:52:40 pm »
Are you sure your "return;" isn't executed?

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: sf::Text not drawed
« Reply #5 on: September 02, 2013, 09:54:52 pm »
Yes, i use Bitbucket and have Mercurial repo. This is very simple class to show debug (mostly) info without SFGUI. So i did the class, the text has been drawn. Source code was not committed to repository because of simplicity of class. =) Then i made some changes...  :o

Quote
Are you sure your "return;" isn't executed?
Yes, i'm sure.

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: sf::Text not drawed
« Reply #6 on: September 02, 2013, 09:56:45 pm »
By the way, what is SIMPLE_LOCK? It looks dangerous ???
It is macro where can be mutex lock. It is empty now.

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: sf::Text not drawed
« Reply #7 on: September 02, 2013, 09:58:45 pm »
otherwise we can only guess.
Yep, i will continue to guess too. =)

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: sf::Text not drawed
« Reply #8 on: September 03, 2013, 07:50:59 am »
Well, if i initialising font before main loop, and if i creating sf::Text with some text - font will be created. But only will be available letters from previously defined sf::Text.

This code is before main loop:
        sf::Font* font = RES_MGR.InstantGetFont("sansation.ttf");
        sf::Text text("123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", *font);
 
Without both of these lines - no text displayed...  :o

Font is loaded via loadFromStream function. Is this function loads entire font?
« Last Edit: September 03, 2013, 07:54:55 am by ChronicRat »

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: sf::Text not drawed
« Reply #9 on: September 03, 2013, 07:57:25 am »
Well, yes, here it is:
Quote
Common mistakes

Some resource classes are not loaded completely after loadFromStream has been called. Instead, they continue to read from their data source as long as they are used. This is the case for sf::Music, which streams audio samples as they are played, and for sf::Font, which loads glyphs on the fly depending on the texts content.
I have to rewrite my resource manager...  :'( He was so cute.
And now i understand why i'm taking a rare crash with one texture. =)
« Last Edit: September 03, 2013, 08:00:57 am by ChronicRat »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Text not drawed
« Reply #10 on: September 03, 2013, 10:40:38 pm »
I have to rewrite my resource manager...  :'( He was so cute.
You can also use an existing one, such as thor::ResourceCache ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: [SOLVED] sf::Text not drawed
« Reply #11 on: September 04, 2013, 07:14:52 am »
Yes, thank you, looks almost as my manager, but i tried to not use smart pointers. Now i'm ready to think that smart pointers are the best solution for Resource Manager.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SOLVED] sf::Text not drawed
« Reply #12 on: September 04, 2013, 11:26:36 am »
Note that std::shared_ptr which I use is only appropriate if you have true shared ownership, i.e. the manager/cache does not store the resources. Instead, the resources live (at least) as long as they are being referred to. Every user of a resource keeps a shared pointer to it.

For simpler cases, you might just have a centralized class that stores the resources and ensures their lifetime. You can then give away raw pointers to resources, since they are not owning.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: [SOLVED] sf::Text not drawed
« Reply #13 on: September 04, 2013, 04:39:38 pm »
For simpler cases, you might just have a centralized class that stores the resources and ensures their lifetime. You can then give away raw pointers to resources, since they are not owning.
I have the same now. Font problem was solved with a simple stream manager. By the way, how about to add sf::InputStream flag, or callback, that data was readed fully?