SFML community forums

Help => Graphics => Topic started by: Carlows on June 21, 2013, 02:45:48 am

Title: Can't draw text and either load font
Post by: Carlows on June 21, 2013, 02:45:48 am
I'm trying to draw some text to a game, but I'm having trouble with it.




#include <SFML\Graphics.hpp>

sf::Font font;

int main()
{
   sf::RenderWindow window( sf::VideoMode( 800, 600 ), "Texto" );

   font.loadFromFile("BROADW.ttf");

   sf::Text text;
   text.setFont(font);
   text.setCharacterSize(40);
   text.setColor(sf::Color::Blue);
   text.setPosition( 100.0f, 100.0f );
   text.setString( "Hola Mundo!" );

   while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
         if (event.type == sf::Event::Closed)
                window.close();
        }

      window.clear( sf::Color::Black );
      window.draw(text);
      window.display();
   }

   return 0;
}




When I try to load the font, I'm getting this error: "Unhandled exception in 0x66c41f34 (msvcr100.dll) in Text.exe: 0xC0000005: Access violation reading location 0x00357000."
Even if I try to draw text without font, It doesn't draw anything. What's going on?



Title: Re: Can't draw text and either load font
Post by: FRex on June 21, 2013, 02:47:04 am
Place your font in main.
Title: Re: Can't draw text and either load font
Post by: Carlows on June 21, 2013, 02:49:24 am
It doesn't change anything, same error
Title: Re: Can't draw text and either load font
Post by: FRex on June 21, 2013, 02:55:41 am
Maybe you mixed debug and release of your program and dlls?
Title: Re: Can't draw text and either load font
Post by: Carlows on June 21, 2013, 03:06:14 am
What do you mean? I paste all the files in /bin folder to system32 directly, is it wrong? I didn't understand how to setup the dll's when I read the tutorial yesterday, lol
Title: Re: Can't draw text and either load font
Post by: Carlows on June 21, 2013, 03:11:34 am
Well, I link the debug version of the libraries and it works, thanks :)