Created
August 28, 2014 09:52
-
-
Save TankOs/baad3ff67281a0de7df6 to your computer and use it in GitHub Desktop.
SFML underline text test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
#include <iostream> | |
int main() { | |
sf::RenderWindow window( | |
sf::VideoMode( 1024, 768 ), | |
"Fonts test", | |
sf::Style::Close | sf::Style::Titlebar | |
); | |
std::vector<sf::Text> texts; | |
std::vector<std::string> font_filenames = { | |
"arial.ttf", "verdana.ttf", "DejaVuSans.ttf", "couri.ttf" | |
}; | |
std::vector<sf::Font> fonts( font_filenames.size() ); | |
sf::Vector2f text_position( 0.0f, 0.0f ); | |
for( | |
std::size_t font_idx = 0; | |
font_idx < font_filenames.size(); | |
++font_idx | |
) { | |
auto& font = fonts[font_idx]; | |
font.loadFromFile( font_filenames[font_idx] ); | |
if( font_idx > 0 ) { | |
text_position.x += texts.back().getGlobalBounds().width + 15.0f; | |
} | |
text_position.y = 0.0f; | |
for( unsigned int text_size = 4; text_size <= 36; text_size += 2 ) { | |
sf::Text text( "Hello SFML!", font, text_size ); | |
text.setPosition( text_position ); | |
text.setStyle( sf::Text::Style::Underlined ); | |
texts.push_back( text ); | |
text_position.y += text.getLocalBounds().height + 15.0f; | |
} | |
} | |
bool run = true; | |
sf::Event event; | |
while( run == true ) { | |
while( window.pollEvent( event ) == true ) { | |
if( event.type == sf::Event::Closed ) { | |
run = false; | |
} | |
} | |
window.clear(); | |
for( const auto& text : texts ) { | |
window.draw( text ); | |
} | |
window.display(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment