Compare commits
3 Commits
370e0f9c5a
...
b05badcf90
| Author | SHA1 | Date | |
|---|---|---|---|
| b05badcf90 | |||
| 9b64e0b065 | |||
| fed67c7baa |
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user