Fixed small ifdef bug, added quick-sfml-templates fps graph

master
MitchellHansen 8 years ago
parent b7d4191d82
commit 033e29d9b1

@ -3,7 +3,7 @@
#include <util.hpp> #include <util.hpp>
#include <cstring> #include <cstring>
#ifdef defined _WIN32 #ifdef _WIN32
#define GLEW_STATIC #define GLEW_STATIC
#include <GL/glew.h> #include <GL/glew.h>

@ -14,19 +14,26 @@
const double PI = 3.141592653589793238463; const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f; const float PI_F = 3.14159265358979f;
struct fps_counter { struct fps_counter {
public: public:
fps_counter(){ fps_counter() :
if(!f.loadFromFile("../assets/fonts/Arial.ttf")){ backdrop(sf::Vector2f(200, 100)), vertex_array(sf::LinesStrip) {
backdrop.setFillColor(sf::Color(0x0000003F));
if (!f.loadFromFile("../assets/fonts/Arial.ttf")) {
std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl; std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl;
} else { }
else {
t.setFont(f); t.setFont(f);
t.setCharacterSize(18);
t.setColor(sf::Color::White);
} }
} }
void frame(double delta_time){ void frame(double delta_time) {
if (frame_count == 100){ // Apply 100 units of smoothing
if (frame_count == 100) {
frame_count = 0; frame_count = 0;
fps_average = 0; fps_average = 0;
} }
@ -41,8 +48,35 @@ public:
milliseconds = true; milliseconds = true;
} }
void draw(sf::RenderWindow *r){ void set_position(sf::Vector2f position) {
backdrop.setPosition(position);
}
sf::Vector2f get_position() {
return backdrop.getPosition();
}
void draw(sf::RenderWindow *r) {
// FPS Line graph
r->draw(backdrop);
if (vertex_position == 200)
vertex_position = 0;
sf::Vector2f origin = backdrop.getPosition();
sf::Vector2f point = origin + sf::Vector2f(vertex_position, backdrop.getSize().y - (1.0 / fps_average));
if (vertex_array.getVertexCount() < 200)
vertex_array.append(sf::Vertex(point, sf::Color::Red));
else
vertex_array[vertex_position] = sf::Vertex(point, sf::Color::Red);
r->draw(vertex_array);
vertex_position++;
// FPS Text
std::string out; std::string out;
if (milliseconds) if (milliseconds)
@ -50,16 +84,24 @@ public:
else else
out = std::to_string(floor(1 / fps_average)); out = std::to_string(floor(1 / fps_average));
t.setPosition(origin);
t.setString(out); t.setString(out);
r->draw(t); r->draw(t);
} }
private: private:
bool milliseconds = false;
sf::RectangleShape backdrop;
sf::VertexArray vertex_array;
sf::Font f; sf::Font f;
sf::Text t; sf::Text t;
int frame_count = 0; int frame_count = 0;
double fps_average = 0; double fps_average = 0;
bool milliseconds = false;
int vertex_position = 0;
}; };
struct debug_text { struct debug_text {

@ -166,6 +166,7 @@ int main() {
// ========== DEBUG ========== // ========== DEBUG ==========
fps_counter fps; fps_counter fps;
fps.set_position(sf::Vector2f(WINDOW_X - 200, WINDOW_Y - 100));
sf::Vector2f *dp = camera->get_direction_pointer(); sf::Vector2f *dp = camera->get_direction_pointer();
debug_text cam_text_x(1, 30, &dp->x, "incli: "); debug_text cam_text_x(1, 30, &dp->x, "incli: ");

Loading…
Cancel
Save