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

Author Topic: sf::Text not declaring properly?  (Read 2159 times)

0 Members and 1 Guest are viewing this topic.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
sf::Text not declaring properly?
« on: June 20, 2013, 02:19:06 pm »
I wonder if I should just make a thread for all my queries here to be honest :P I'm trying not to spam the forum but I've run into annoying problem with sf::Text. I thought I'd try it out since I'm still working on the other problem in my head but I found that no matter what I try the command isn't declaring my objects properly.


#include <Iostream>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{

    sf::RenderWindow window(sf::VideoMode( 800, 600 ), "C++ Programming Test");

    sf::Font arial;
    if ( !arial.loadFromFile ( "arial.ttf" ) )

    sf::Text lineone;

    lineone.setFont( arial );
    lineone.setString ( "SFML Text is working!" );
    lineone.setCharacterSize ( 12 );
    lineone.setPosition ( 400, 300 );





    while (window.isOpen())
    {

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


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

        window.clear();
        window.draw ( lineone );
        window.display();

    }

    return 0;

}

 

Quote
|15|error: 'lineone' was not declared in this scope

It's clearly complaining about me naming my text but the problem is I can't see where I've gone wrong, I think I need a fresh pair of eyes to just have a look over it. I've probably missed something really obvious like a typo or the way it's laid out.
« Last Edit: June 20, 2013, 02:36:01 pm by Laurent »

Sqasher

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: sf::Text not declaring properly?
« Reply #1 on: June 20, 2013, 02:31:54 pm »
Your lineone is in the scope of the if condition.

if ( !arial.loadFromFile ( "arial.ttf" ) )
{ }
sf::Text lineone;

that should fix your problem.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: sf::Text not declaring properly?
« Reply #2 on: June 20, 2013, 02:36:41 pm »
ahhh okay, so it's okay to leave the empty brackets in there, thanks.

Edit: Yep, working now.