Dont use glut for fps measure.

This commit is contained in:
tamasmeszaros 2019-12-17 18:39:01 +01:00
parent e25cd1ce1a
commit acfaff3741
2 changed files with 38 additions and 23 deletions

View File

@ -11,7 +11,7 @@ find_package(wxWidgets 3.1 REQUIRED COMPONENTS core base gl html)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
find_package(OpenCSG REQUIRED) find_package(OpenCSG REQUIRED)
# find_package(GLUT REQUIRED) find_package(GLUT REQUIRED)
include(${wxWidgets_USE_FILE}) include(${wxWidgets_USE_FILE})
@ -22,6 +22,7 @@ target_compile_definitions(opencsg_example PRIVATE ${wxWidgets_DEFINITIONS})
target_link_libraries(opencsg_example ${wxWidgets_LIBRARIES} target_link_libraries(opencsg_example ${wxWidgets_LIBRARIES}
OpenCSG::opencsg OpenCSG::opencsg
GLEW::GLEW GLEW::GLEW
GLUT::GLUT
OpenGL::GL OpenGL::GL
#-lXrandr -lXext -lX11 #-lXrandr -lXext -lX11
) )

View File

@ -1,3 +1,5 @@
#include <chrono>
#include "GLScene.hpp" #include "GLScene.hpp"
#include <libslic3r/Utils.hpp> #include <libslic3r/Utils.hpp>
#include <libslic3r/SLAPrint.hpp> #include <libslic3r/SLAPrint.hpp>
@ -5,11 +7,11 @@
#include <GL/glew.h> #include <GL/glew.h>
//#ifdef __APPLE__ #ifdef __APPLE__
//#include <GLUT/glut.h> #include <GLUT/glut.h>
//#else #else
//#include <GL/glut.h> #include <GL/glut.h>
//#endif #endif
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
@ -56,23 +58,36 @@ Scene::Scene() = default;
Scene::~Scene() = default; Scene::~Scene() = default;
void renderfps () { void renderfps () {
using Clock = std::chrono::high_resolution_clock;
using Duration = Clock::duration;
using TimePoint = Clock::time_point;
static std::ostringstream fpsStream; static std::ostringstream fpsStream;
static int fps = 0; static int frames = 0;
static int ancient = 0; static TimePoint last = Clock::now();
static int last = 0;
static int msec = 0;
last = msec; static const double resolution = 0.01;
// msec = glutGet(GLUT_ELAPSED_TIME); static double fps = 0.;
if (last / 1000 != msec / 1000) {
auto to_sec = [](Duration d) -> double {
return d.count() * double(Duration::period::num) / Duration::period::den;
};
++frames;
TimePoint msec = Clock::now();
double seconds = to_sec(msec - last);
if (seconds >= resolution) {
last = msec;
fps = 0.5 * (fps + frames / seconds);
float correctedFps = fps * 1000.0f / float(msec - ancient);
fpsStream.str(""); fpsStream.str("");
fpsStream << "fps: " << correctedFps << std::ends; fpsStream << "fps: " << std::setprecision(4) << fps << std::ends;
ancient = msec; frames = 0;
fps = 0;
} }
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glLoadIdentity(); glLoadIdentity();
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
@ -82,15 +97,14 @@ void renderfps () {
glRasterPos2f(-1.0f, -1.0f); glRasterPos2f(-1.0f, -1.0f);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
std::string s = fpsStream.str(); std::string s = fpsStream.str();
// for (unsigned int i=0; i<s.size(); ++i) { for (unsigned int i=0; i<s.size(); ++i) {
// glutBitmapCharacter(GLUT_BITMAP_8_BY_13, s[i]); glutBitmapCharacter(GLUT_BITMAP_8_BY_13, s[i]);
// } }
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glPopMatrix(); glPopMatrix();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
++fps;
glFlush(); glFlush();
} }
@ -358,7 +372,7 @@ void Display::set_active(long width, long height)
if (!m_initialized) { if (!m_initialized) {
glewInit(); glewInit();
// glutInit(&argc, nullptr); glutInit(&argc, nullptr);
m_initialized = true; m_initialized = true;
} }