Hi, I'm new to both SFML and C++ development (from C#/Java background) and I want to know if I'm doing something wrong that is negatively affecting my frame time.
I have a method that draws the current FPS in a new sf::Text, and I call this method ~100 times per frame. This brings the app to 100 FPS. However, when I was drawing the sf::Text object 1 time per frame, I was seeing 500 FPS.
This FPS drop is way more dramatic than I expected. If this were a 2D tile-based game that has 10x10 tiles in your line-of-sight, that could be 100 sprites drawn per second and when you consider the Tile layer, Item layer, Player layer, Effects layer... I don't see how this would handle it. That is unless drawing Sprites is somehow much cheaper/faster.
I'm using Windows XP, Visual C++ 2010 Express.
Dell Inspiron 6000 laptop (7 years old?), Intel processor 1.73GHz, integrated graphics.
Are CPU and GPU specs my problem?
#include <cstdlib>
#include "stdafx.h"
#include "SFML\Window.hpp"
#include "SFML\Graphics.hpp"
#include "SFML\System.hpp"
#include "SFML\System\Time.hpp"
using namespace std;
void drawString(std::string s, float x, float y, sf::RenderWindow* window)
{
sf::String sfString(s);
sf::Text sfText;
sfText.setString(sfString);
sfText.setPosition(x,y);
(*window).draw(sfText);
}
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
sf::RenderWindow *pwindow = &window;
window.setVerticalSyncEnabled(true); // call it once, after creating the window
sf::Clock fps_clock;
while(window.isOpen())
{
window.clear(sf::Color::Black);
// show fps
char *fps_str = new char[30];
char *ct_str = new char[30];
float frame_time = fps_clock.restart().asSeconds();
float fps = 1.f / frame_time;
sprintf(fps_str, "FPS: %.1f", fps);
// draw text a few times...
for(int i=0; i<19; i++)
for(int j=0; j<5; j++)
drawString(fps_str,j*160,i*30, pwindow);
delete fps_str;
delete ct_str;
window.display();
sf::sleep(sf::milliseconds(0));
}
delete pwindow;
return 0;
}