Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to display some text and numerical data over my OpenGL scene in SFML 2.0. I've looked at the SFML 1.6 text tutorials here. But I can't get the code to work. There is (as of yet) no text tutorial for 2.0

share|improve this question
SFML 1.6 and 2.0 are very different. I suggest you follow the 2.0 documentation rather than the 1.6 one. –  Bugster Nov 9 '12 at 19:52
@ThePlan, SFML 2.0 documentation is still fairly sparse, that's why I put this question and answer here –  Ken Nov 9 '12 at 21:20
add comment

1 Answer

up vote 3 down vote accepted

A lot of the method names have changed in the transition from SFML 1.6 to 2.0. So the 1.6 tutorials will not work without modification.

First you will need to creat a font, you can do this using a .ttf file

//create a font
sf::Font font;

// Load it from a file
if (!font.loadFromFile("../sansation.ttf"))
    //find this file in the "pong" example in the SFML examples folder
    std::cout << "Error loading font\n" ;

Inside your render loop, after drawing your scene, you can add this code to render some text and numerical data:

//Draw scene
//.........Draw Scene stuff......

//save the openGLstate if using OpenGL
//becase text drawing may well change some OpenGL settings

static float frameCount=0;

std::ostringstream ss; //string buffer to convert numbers to string
ss << "Hello World , frame count is: " << frameCount;// put float into string buffer

//set up text properties
sf::Text atext;

atext.setString(ss.str()); //ss.str() converts the string buffer into a regular string 

//draw the string

//restore OpenGL setting that were saved earlier
share|improve this answer
It's also worth noting that unlike in 1.6, there isn't a default font in SFML 2.0. –  Alayric Dec 1 '12 at 15:22
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.