1
Graphics / [solved] Embedding fonts like arial.hpp
« on: October 04, 2011, 11:48:33 am »
By int I just meant a standard int32_t
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
window->SetFramerateLimit(60);
it results in an FPS that fluctuates between 62.5 and 67 FPS.#include <stdint.h>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
sf::Text* fpstext;
sf::Font* pixelfont;
sf::RenderWindow* window;
sf::Event event;
double gameFPS = 0.0f;
bool PROGRAM_EXIT = false;
void handleEvents()
{
while (window->PollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
{
PROGRAM_EXIT = true;
}
}
}
void init()
{
window = new sf::RenderWindow(sf::VideoMode(1024, 768), "FPS Test", sf::Style::Default | sf::Style::Resize, sf::ContextSettings(32, 8, 0));
window->SetFramerateLimit(60);
window->EnableVerticalSync(false);
sf::Event event = sf::Event();
pixelfont = new sf::Font();
fpstext = new sf::Text("Fps!");
fpstext->SetCharacterSize(16);
fpstext->SetPosition(0, 0);
//fpstext->SetFont(*pixelfont);
fpstext->SetColor(sf::Color::Red);
}
void drawFPS()
{
static sf::String fps;
static char buf[128];
memset(buf, 0, 128);
sprintf(buf, "FPS: %8.4f", gameFPS);
fps = buf;
fpstext->SetString(fps);
window->Draw(*fpstext);
}
int main(int argc, char** argv)
{
init();
while (!PROGRAM_EXIT)
{
handleEvents();
window->Clear();
drawFPS();
window->Display();
gameFPS = 1.f / window->GetFrameTime() * 1000;
}
return 0;
}