SFML community forums

Help => Graphics => Topic started by: Drraven on December 14, 2010, 04:36:11 pm

Title: Drawing variables
Post by: Drraven on December 14, 2010, 04:36:11 pm
Hi,
At the beginning of the English language I mean I know that he was not disappointment ;p
Can someone explain to me how can I display a variable of type int or float in sfml?
I will be grateful.
Title: Drawing variables
Post by: Drektar on December 14, 2010, 05:39:51 pm
In the console or on a sf::RenderWindow?
Title: Drawing variables
Post by: Drraven on December 14, 2010, 05:44:14 pm
in RenderWindow
Title: Drawing variables
Post by: Drektar on December 14, 2010, 06:21:21 pm
You can display text on the screen with sf::String (sf::Text in SFML 2.0)

I suggest you to read the tuto:
http://www.sfml-dev.org/tutorials/1.6/graphics-fonts-fr.php

To display variable like a float it's the same thing but you have to convert your number into string before.

For this he have more than one method.
You can read that : How to convert a numeric type to a string? (http://www.codeguru.com/forum/showthread.php?s=&threadid=231056)

Laurent also give an example of a converter somewhere on the forum...

[Edit] I find it :
Code: [Select]
namespace Converter
{
    template <typename T>
    std::string ToString(const T& i)
    {
        std::ostringstream stream;
        stream << i;
        return stream.str();
    }

    template <typename T>
    T FromString(const std::string& str)
    {
        std::istringstream stream(str);
        T tmp;
        stream >> tmp;
       
        return tmp;
    }
}
Title: Drawing variables
Post by: Drraven on December 14, 2010, 08:51:34 pm
I need to convert int to string and then just display this string.
Thanks Drektar
Title: Drawing variables
Post by: Silvah on December 14, 2010, 09:43:00 pm
Quote from: "Drektar"
I suggest you to read the tuto:
http://www.sfml-dev.org/tutorials/1.6/graphics-fonts-fr.php
It's a tutorial? Looks rather like a totally random bunch of characters.
Title: Drawing variables
Post by: Hiura on December 14, 2010, 10:01:54 pm
hum... maybe fr stands for french.  :roll:
http://www.sfml-dev.org/tutorials/1.6/graphics-fonts.php