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

Author Topic: Can't draw text and either load font  (Read 4103 times)

0 Members and 1 Guest are viewing this topic.

Carlows

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Can't draw text and either load font
« 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?




FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Can't draw text and either load font
« Reply #1 on: June 21, 2013, 02:47:04 am »
Place your font in main.
Back to C++ gamedev with SFML in May 2023

Carlows

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Can't draw text and either load font
« Reply #2 on: June 21, 2013, 02:49:24 am »
It doesn't change anything, same error

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Can't draw text and either load font
« Reply #3 on: June 21, 2013, 02:55:41 am »
Maybe you mixed debug and release of your program and dlls?
Back to C++ gamedev with SFML in May 2023

Carlows

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Can't draw text and either load font
« Reply #4 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

Carlows

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Can't draw text and either load font
« Reply #5 on: June 21, 2013, 03:11:34 am »
Well, I link the debug version of the libraries and it works, thanks :)