Skip to content

Commit 7ee3436

Browse files
authored
feat: add fps overlay in play mode (#16)
1 parent 95f1f55 commit 7ee3436

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/states/play-state.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ class Playstate : public our::State {
1414
our::FreeCameraControllerSystem cameraController;
1515
our::MovementSystem movementSystem;
1616

17+
void displayFPS() const {
18+
// Pin a transparent overlay window to the top-left corner
19+
ImGui::SetNextWindowPos(ImVec2(10.0f, 10.0f), ImGuiCond_Always);
20+
21+
// Red if below 120 FPS, green otherwise
22+
float fps = ImGui::GetIO().Framerate;
23+
ImVec4 fpsColor = (fps < 120.0f) ? fpsColor = ImVec4(1.0f, 0.0f, 0.0f, 1.0f) : ImVec4(0.0f, 1.0f, 0.0f, 1.0f);
24+
25+
ImGuiWindowFlags textWindowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
26+
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing |
27+
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoMove;
28+
ImGui::SetNextWindowBgAlpha(0.35f);
29+
if (ImGui::Begin("FPS Overlay", nullptr, textWindowFlags)) {
30+
ImGui::TextColored(fpsColor, "FPS: %.1f", fps);
31+
}
32+
ImGui::End();
33+
}
34+
35+
void onImmediateGui() override {
36+
displayFPS();
37+
}
38+
1739
void onInitialize() override {
1840
// First of all, we get the scene configuration from the app config
1941
auto& config = getApp()->getConfig()["scene"];

0 commit comments

Comments
 (0)