#include #include #include #include #include #include "Game.h" sp::Font smallFont; sp::Font myFont; sp::Font fntLarge; sp::Text myText; sp::Text txtLarge; sp::Text txtKerning; sp::Text fpsText; sp::Text txtSmall; sp::Camera2D guiCamera; sp::BatchRenderer2D *renderer; void TextExample::init() { sp::Graphics* g = getGraphics(); std::cout << g->getVersion() << std::endl; g->setClearColor(52.0f / 255.0f, 58.0f / 255.0f, 80.0f / 255.0f); smallFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf"); myFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf"); fntLarge.loadFromFile("assets/fonts/OPTIBelwe-Medium.otf"); myText.setFont(myFont); myText.setColor(sp::Color::Green); myText.setString("Hello"); myText.setPosition(25.0f, 50.0f); txtLarge.setFont(myFont); txtLarge.setColor(sp::Color(200, 100, 0)); txtLarge.setString("Large Text, Looks good?"); txtLarge.setPosition(300.0f, 150.0f); txtLarge.setScale(2.0f); txtKerning.setFont(fntLarge); txtKerning.setColor(sp::Color(150, 0, 230)); txtKerning.setString("Kerning: VA Ta"); txtKerning.setPosition(150.0f, 200.0f); txtSmall.setFont(smallFont); txtSmall.setString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a rhoncus odio, nec finibus libero."); txtSmall.setPosition(50.0f, 450.0f); fpsText.setFont(myFont); fpsText.setString("FPS: 0"); fpsText.setPosition(10.0f, 10.0f); renderer = new sp::BatchRenderer2D(); } void TextExample::update(double dt) { sp::InputModule* input = getInput(); input->update(); if (getFpsCounter().update()) { std::string str = "FPS: " + sp::core::to_string(getFpsCounter().getFPS(), 0); fpsText.setString(str); } } void TextExample::render() { sp::Graphics* g = getGraphics(); g->clearBuffer(); renderer->begin(); renderer->submit(fpsText); renderer->submit(myText); renderer->submit(txtLarge); renderer->submit(txtKerning); renderer->submit(txtSmall); renderer->setCamera(guiCamera); renderer->render(); g->swapBuffers(); }