SFML community forums

Help => Graphics => Topic started by: StDH on May 11, 2014, 12:27:13 pm

Title: onCreate() text glitch
Post by: StDH on May 11, 2014, 12:27:13 pm
language: c++
visual studio ultimate 2013
sfml 2.1 static [20.02.2014]

minimal code:
namespace game
{
        class Window : public sf::RenderWindow
        {
                public:
                        void onCreate();
        };
};

void game::Window::onCreate()
{
        // load files
}

first time it appears when i tried loading files inside onCreate(),
so i removed line that load files in onCreate() but it was still
appearing .... then i removed whole function onCreate() and
glitch disappeared.
I tried this more time to be sure it isn't my fault
Title: Re: onCreate() text glitch
Post by: Nexus on May 11, 2014, 12:51:43 pm
I have no idea what's the purpose of your onCreate() method, let alone how it relates to the font problem.

Please read this thread (http://en.sfml-dev.org/forums/index.php?topic=5559.0) carefully and edit your post accordingly, so that we can help you in a meaningful way.
Title: Re: onCreate() text glitch
Post by: StDH on May 11, 2014, 12:53:41 pm
I have no idea what's the purpose of your onCreate() method, let alone how it relates to the font problem.

Please read this thread (http://en.sfml-dev.org/forums/index.php?topic=5559.0) carefully and edit your post accordingly, so that we can help you in a meaningful way.

some search may help you:
http://www.sfml-dev.org/documentation/2.1/classsf_1_1Window.php#a106633b9be49b27f83d4712689b493eb
Title: Re: onCreate() text glitch
Post by: Nexus on May 11, 2014, 12:57:45 pm
I'm aware of this function, but I still don't know how you use it and how what problems you get exactly. And to be honest I doubt you really need inheritance here -- what does your custom window class do that cannot be achieved through composition?

Anyway, please come up with a minimal complete example as described in the thread I linked.
Title: Re: onCreate() text glitch
Post by: StDH on May 11, 2014, 01:12:29 pm
class Window : public sf::RenderWindow
{
        private:
                sf::Font font;
                sf::Text text;

        public:
                void onCreate()
                {
                        font.loadFromFile("assets/fnt/orbitron/medium.otf");

       
                        text.setFont(font);
                        text.setCharacterSize(14);
                        text.setColor(sf::Color::White);
                        text.setString("0123456789-\nabcdefghijklmo\npqrstuvwxyz");
                }

                void draw_()
                {
                        draw(text);
                }
};

void main()
{
        Window window;
        window.create(sf::VideoMode(800,600,32), "...");

        while (window.isOpen())
        {
                window.clear();
                window.draw_();
                window.display();
        }
}
Title: Re: onCreate() text glitch
Post by: Laurent on May 11, 2014, 04:15:45 pm
Don't expect sf::RenderWindow to work well if you don't call its onCreate function ;)

        void onCreate()
        {
            sf::RenderWindow::onCreate();
            ...
        }

This function is not really meant to be used publicly, you should really think about another design, not involving SFML internal stuff.
Title: Re: onCreate() text glitch
Post by: StDH on May 11, 2014, 04:44:06 pm
I was just curious, so i tested that function. :)