summaryrefslogtreecommitdiff
path: root/src/demo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/demo.cpp')
-rw-r--r--src/demo.cpp48
1 files changed, 10 insertions, 38 deletions
diff --git a/src/demo.cpp b/src/demo.cpp
index 8e4181a..64d75a7 100644
--- a/src/demo.cpp
+++ b/src/demo.cpp
@@ -1,10 +1,10 @@
#include "demo.hpp"
+#include "gl_context.hpp"
+#include "imgui_context.hpp"
#include "sdl_context.hpp"
#include "sdl_main_window.hpp"
#include "stb_image.h"
-#include "gl_context.hpp"
-#include "imgui_context.hpp"
#include <SDL.h>
#include <SDL_opengl.h>
@@ -85,9 +85,9 @@ bool LoadTextureFromFile(const fud::String& filename, GLuint* out_texture, int*
std::vector<char> fileData{};
fileData.resize(fileSize);
- auto readStatus = inFile.read(fileData.data(), fileSize, fileSize);
- if (readStatus != FileStatus::Success) {
- spdlog::error("bad read {} {}", filename.c_str(), FileStatusToString(readStatus));
+ auto readResult = inFile.read(fileData.data(), fileSize, fileSize);
+ if (readResult.status != FileStatus::Success) {
+ spdlog::error("bad read {} {}", filename.c_str(), FileStatusToString(readResult.status));
return false;
}
@@ -97,30 +97,15 @@ bool LoadTextureFromFile(const fud::String& filename, GLuint* out_texture, int*
int demo(const fud::String& m_filename)
{
- // Setup SDL
SdlContext sdlContext{};
SdlMainWindow mainWindow{sdlContext};
- // Create window with graphics context
GlContext glContext{mainWindow};
- // Setup Dear ImGui context
- IMGUI_CHECKVERSION();
- ImGui::CreateContext();
- ImGuiIO& io = ImGui::GetIO();
- (void)io;
- io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
- io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
-
- // Setup Dear ImGui style
- ImGui::StyleColorsDark();
- // ImGui::StyleColorsLight();
+ ImguiContext imguiContext{glContext, sdlContext, mainWindow};
// Setup Platform/Renderer backends
- ImGui_ImplSDL2_InitForOpenGL(mainWindow.window(), glContext.context());
- ImGui_ImplOpenGL3_Init(sdlContext.glslVersion());
-
int my_image_width = 0;
int my_image_height = 0;
GLuint my_image_texture = 0;
@@ -156,14 +141,7 @@ int demo(const fud::String& m_filename)
// Main loop
bool done = false;
-#ifdef __EMSCRIPTEN__
- // For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the
- // imgui.ini file. You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
- io.IniFilename = nullptr;
- EMSCRIPTEN_MAINLOOP_BEGIN
-#else
while (!done)
-#endif
{
// Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your
@@ -231,7 +209,8 @@ int demo(const fud::String& m_filename)
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
- ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
+ auto framerate = imguiContext.getIO().Framerate;
+ ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / framerate, framerate);
ImGui::End();
}
@@ -248,7 +227,8 @@ int demo(const fud::String& m_filename)
// Rendering
ImGui::Render();
- glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
+ const auto& imguiIO = imguiContext.getIO();
+ glViewport(0, 0, static_cast<int>(imguiIO.DisplaySize.x), static_cast<int>(imguiIO.DisplaySize.y));
glClearColor(
clear_color.x * clear_color.w,
clear_color.y * clear_color.w,
@@ -258,14 +238,6 @@ int demo(const fud::String& m_filename)
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(mainWindow.window());
}
-#ifdef __EMSCRIPTEN__
- EMSCRIPTEN_MAINLOOP_END;
-#endif
-
- // Cleanup
- ImGui_ImplOpenGL3_Shutdown();
- ImGui_ImplSDL2_Shutdown();
- ImGui::DestroyContext();
// return ImageResult::okay(image);