Compare commits

...

3 Commits

4 changed files with 35 additions and 8 deletions

View File

@@ -6,7 +6,6 @@
#include "SDL3/SDL_render.h"
#include "imgui.h"
#include "imgui_impl_sdl3.h"
#include "imgui_impl_sdlrenderer3.h"
#define SDL_MAIN_HANDLED 1
@@ -82,10 +81,13 @@ void Application::Run() {
float time = 0;
// Update functions before rendereing
for (auto layer : m_LayerStack) {
layer->OnFrame(time);
}
// Events
// can i connect my events to sdl events and use their dispatcher?
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -108,11 +110,21 @@ void Application::Run() {
}
//
// Rendering
ImGui::Render();
m_ImGuiLayer->Begin();
SDL_SetRenderScale(m_Renderer, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
SDL_SetRenderDrawColor(m_Renderer, (Uint8)255, (Uint8)255, (Uint8)255, (Uint8)255);
SDL_SetRenderDrawColor(m_Renderer, (Uint8)111, (Uint8)232, (Uint8)168, (Uint8)0);
SDL_RenderClear(m_Renderer);
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), m_Renderer);
// the above 3 lines go before implsdl3 render
// or not?
for (auto layer : m_LayerStack) {
layer->OnImGuiRender();
}
m_ImGuiLayer->End();
SDL_RenderPresent(m_Renderer);
}
}

View File

@@ -8,12 +8,11 @@ public:
Layer(const std::string &name = "Layer");
virtual ~Layer() = default;
virtual void OnStart() {}
virtual void OnFrame(float timestamp) {}
virtual void OnEnd() {}
virtual void OnEvent() {}
virtual void OnAttach() {}
virtual void OnDetach() {}
virtual void OnImGuiRender() {}
const std::string &GetName() const { return m_LayerName; }

View File

@@ -42,5 +42,22 @@ void ImGuiLayer::End() {
Application &app = Application::Get();
io.DisplaySize = ImVec2((float)app.GetWindowData().width, (float)app.GetWindowData().height);
ImGui::Render();
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), Application::Get().GetSDLRenderer());
ImGui::EndFrame();
}
void ImGuiLayer::OnImGuiRender() {
ImGuiIO &io = ImGui::GetIO();
bool demoWindow = true;
ImGui::Begin("Test window");
ImGui::ShowDemoWindow(&demoWindow);
ImGui::Text("Application avg %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
if (ImGui::Button("Quit")) {
Application::Get().SetRunningState(false);
}
ImGui::End();
}
} // namespace SakuraVNE

View File

@@ -8,11 +8,10 @@ public:
ImGuiLayer();
~ImGuiLayer() = default;
// virtual void OnStart() override;
// virtual void OnFrame(float timestamp) override;
// virtual void OnEnd() override;
virtual void OnAttach() override;
virtual void OnDetach() override;
virtual void OnImGuiRender() override;
// virtual void OnEvent() override;
void Begin();