diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 9c2db1f..bf27740 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -96,12 +96,8 @@ void Window::tick() { float diff = (float) std::chrono::duration_cast(now - this->last_frame).count(); this->last_frame = now; - // TODO: remove debug line at some point - std::cout << 1000.0/diff << " fps\n"; - // input - this->widget->tick(); - + this->widget->tick(1000.0/diff); // tick render glBindFramebuffer(GL_FRAMEBUFFER, 0); diff --git a/src/gui/input/Widget.cpp b/src/gui/input/Widget.cpp index 7f3a87d..f03010c 100644 --- a/src/gui/input/Widget.cpp +++ b/src/gui/input/Widget.cpp @@ -1,6 +1,8 @@ #include "Widget.h" #include "linalg/linalg.h" #include "consts.h" +#include +#include Widget::Widget(GLFWwindow* window) { @@ -15,11 +17,13 @@ Widget::Widget(GLFWwindow* window) { this->cameraPos = Point3::init(-0.7, -1.0, -2.0); this->cameraUp = Vec3::init(0.0, 1.0, 0.0).normalize(); this->lightPos = Point3::init(1.5, 2.0, -1.0); + + this->fps = (char*)malloc(512*sizeof(char)); this->paused = true; this->renderOnce = false; }; -void Widget::tick() { +void Widget::tick(double fps) { if (this->renderOnce) { this->renderOnce = false; this->paused = true; @@ -38,12 +42,15 @@ void Widget::tick() { ImGui::DragScalar("Z coordinate", ImGuiDataType_Double, &this->lightPos.z, 0.005f, &min, &max, "%.3f"); ImGui::End(); - ImGui::Begin("Pause"); + ImGui::Begin("Miscellaneous"); if (ImGui::Button(this->paused ? "Unpause" : "Pause")) this->paused = !this->paused; + ImGui::SameLine(); if (ImGui::Button("render Once")) { this->paused = !this->paused; this->renderOnce = true; } + sprintf(this->fps, "%.3f fps\n", fps); + ImGui::Text(this->fps); ImGui::End(); ImGui::Begin("Camera Controls"); @@ -74,4 +81,5 @@ Widget::~Widget() { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); + free(this->fps); } diff --git a/src/gui/input/Widget.h b/src/gui/input/Widget.h index 9eb243d..ed4cce1 100644 --- a/src/gui/input/Widget.h +++ b/src/gui/input/Widget.h @@ -13,12 +13,14 @@ public: Vec3 cameraPos; Vec3 cameraUp; Point3 lightPos; + bool paused; bool renderOnce; + char* fps; ImGuiIO io; - void tick(); + void tick(double fps); void render(); void copyToDevice();