FPS counter

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-12-04 12:18:26 +02:00
parent 4e674c9956
commit 933b7c65fd
2 changed files with 27 additions and 8 deletions

View File

@@ -1,8 +0,0 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
[Window][Dear ImGui Demo]
Pos=551,12
Size=550,680

View File

@@ -6,11 +6,13 @@
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_timer.h>
#include <SDL3/SDL_video.h>
#include <imgui_impl_sdl3.h>
#include <imgui_impl_vulkan.h>
#include "Util.h"
#include "VulkanRenderer.h"
namespace Lunar {
@@ -48,7 +50,19 @@ auto Application::run() -> void
{
SDL_Event e;
ImGuiIO &io = ImGui::GetIO();
io.IniFilename = nullptr;
uint64_t last { 0 };
float fps { 0.0f };
while (m_running) {
uint64_t now { SDL_GetTicks() };
uint64_t dt { now - last };
last = now;
if (dt > 0)
fps = 1000.0f / (float)dt;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) {
m_running = false;
@@ -66,7 +80,20 @@ auto Application::run() -> void
ImGui_ImplVulkan_NewFrame();
ImGui::NewFrame();
ImGui::ShowDemoWindow();
ImGui::SetNextWindowSize({ 100, 50 });
ImGui::SetNextWindowPos({ 0, 0 });
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 { 0, 0, 0, 0.5f });
if (ImGui::Begin("Debug Info", nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize)) {
defer(ImGui::End());
ImGui::Text("%s", std::format("FPS: {:.2f}", fps).c_str());
}
ImGui::PopStyleColor();
ImGui::Render();
m_renderer->render();