Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third-party/SDL"]
path = third-party/SDL
url = https://github.com/libsdl-org/SDL.git
[submodule "third-party/imgui"]
path = third-party/imgui
url = https://github.com/ocornut/imgui.git
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})

add_library(glad STATIC third-party/glad/glad.c)

# ImGui setup
set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party/imgui)
add_library(imgui STATIC
${IMGUI_DIR}/imgui.cpp
${IMGUI_DIR}/imgui_draw.cpp
${IMGUI_DIR}/imgui_tables.cpp
${IMGUI_DIR}/imgui_widgets.cpp
${IMGUI_DIR}/imgui_demo.cpp
${IMGUI_DIR}/backends/imgui_impl_sdl3.cpp
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
)
target_include_directories(imgui
PUBLIC
${IMGUI_DIR}
${IMGUI_DIR}/backends
${CMAKE_CURRENT_SOURCE_DIR}/third-party/SDL/include
)

target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
Expand Down Expand Up @@ -73,6 +91,7 @@ target_include_directories(glad
# handles their include paths and other properties for you.
target_link_libraries(${PROJECT_NAME} PUBLIC glad)
target_link_libraries(${PROJECT_NAME} PUBLIC SDL3::SDL3)
target_link_libraries(${PROJECT_NAME} PUBLIC imgui)


# Shaders
Expand Down
16 changes: 16 additions & 0 deletions include/weird-engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#define ENGINE_PATH "../weird-engine"
#endif // !ENGINE_PATH

#include <SDL3/SDL.h>
#include <SDL3/SDL_timer.h>
#include <imgui.h>
#include <imgui_impl_sdl3.h>

#include "weird-engine/Input.h"
#include "weird-engine/Profiler.h"
#include "weird-engine/SceneManager.h"
Expand Down Expand Up @@ -79,6 +84,15 @@ namespace WeirdEngine
// Capture window input
Input::update(ctx.renderer.getWindow());

// Suppress game input when ImGui has focus
{
const ImGuiIO& io = ImGui::GetIO();
if (io.WantCaptureMouse)
Input::suppressMouseInput();
if (io.WantCaptureKeyboard)
Input::suppressKeyboardInput();
}

if (Input::GetKeyDown(Input::T))
{
WeirdEngine::Profiler::Get().startRecording();
Expand All @@ -91,6 +105,8 @@ namespace WeirdEngine
SDL_Event event;
while (SDL_PollEvent(&event))
{
ImGui_ImplSDL3_ProcessEvent(&event);

if (event.type == SDL_EVENT_QUIT)
{
ctx.quit = true;
Expand Down
26 changes: 26 additions & 0 deletions include/weird-engine/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,32 @@ namespace WeirdEngine

#pragma endregion

static void suppressMouseInput()
{
auto& instance = getInstance();
for (int i = 0; i < 5; ++i)
{
if (instance.m_mouseKeysTable[i] > NOT_PRESSED) // IS_PRESSED or FIRST_PRESSED
instance.m_mouseKeysTable[i] = RELEASED_THIS_FRAME; // fire key-up
else if (instance.m_mouseKeysTable[i] == RELEASED_THIS_FRAME)
instance.m_mouseKeysTable[i] = NOT_PRESSED; // clear existing key-up
// NOT_PRESSED stays NOT_PRESSED — no spurious key-ups
}
}

static void suppressKeyboardInput()
{
auto& instance = getInstance();
for (int i = 0; i < SDL_SCANCODE_COUNT; ++i)
{
if (instance.m_keyTable[i] > NOT_PRESSED) // IS_PRESSED or FIRST_PRESSED
instance.m_keyTable[i] = RELEASED_THIS_FRAME; // fire key-up
else if (instance.m_keyTable[i] == RELEASED_THIS_FRAME)
instance.m_keyTable[i] = NOT_PRESSED; // clear existing key-up
// NOT_PRESSED stays NOT_PRESSED — no spurious key-ups
}
}

#pragma region Keyboard

static bool GetKey(KeyCode key)
Expand Down
3 changes: 1 addition & 2 deletions include/weird-renderer/core/SDF2DRenderPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace WeirdEngine
double delta, Texture* backgroundTexture = nullptr);
void resize(unsigned int newWidth, unsigned int newHeight);
void free();
void handleDebugInputs();

private:
Config m_config;
Expand Down Expand Up @@ -124,8 +125,6 @@ namespace WeirdEngine
void blendMaterials(double time);
void renderBackground(const Camera& camera, double time);
void applyLighting(const Camera& camera, double time, Texture* backgroundTexture);
void handleDebugInputs();

static int largestPowerOfTwoBelow(int n);
};
} // namespace WeirdRenderer
Expand Down
3 changes: 2 additions & 1 deletion include/weird-renderer/core/SDLInitializer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include "weird-renderer/audio/AudioEngine.h"
#include <SDL3/SDL.h>

#include "weird-renderer/audio/AudioEngine.h"

namespace WeirdEngine
{
namespace WeirdRenderer
Expand Down
33 changes: 31 additions & 2 deletions src/weird-renderer/core/Renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#include "weird-renderer/core/Renderer.h"

#include "weird-engine/Profiler.h"
#include <sys/stat.h>

#include <SDL3/SDL.h>
#include <SDL3/SDL_hints.h>
#include <sys/stat.h>
#include <imgui.h>
#include <imgui_impl_sdl3.h>
#include <imgui_impl_opengl3.h>

#include "weird-engine/Profiler.h"

namespace WeirdEngine
{
Expand Down Expand Up @@ -117,6 +122,30 @@ namespace WeirdEngine
auto& result = renderScene(scene, time, clampedDelta);
output(scene, result, clampedDelta);

static bool showDebugUI = false;

if(Input::GetKeyDown(Input::F3))
{
showDebugUI = !showDebugUI;
}

if(showDebugUI)
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame();

ImGui::Begin("Renderer Settings");
m_worldPipeline->handleDebugInputs();
m_uiPipeline->handleDebugInputs();
ImGui::End();

ImGui::Render();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, m_windowWidth, m_windowHeight);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

{
PROFILE_SCOPE("Synchronization");
SDL_GL_SwapWindow(m_window);
Expand Down
101 changes: 61 additions & 40 deletions src/weird-renderer/core/SDF2DRenderPipeline.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "weird-renderer/core/SDF2DRenderPipeline.h"
#include "weird-engine/vec.h"

#include <algorithm>

#include <imgui.h>

#include "weird-engine/vec.h"

namespace WeirdEngine
{
namespace WeirdRenderer
Expand Down Expand Up @@ -528,45 +532,62 @@ namespace WeirdEngine

void SDF2DRenderPipeline::handleDebugInputs()
{
// if (Input::GetKey(Input::LeftCtrl) && Input::GetKeyDown(Input::L))
// {
// m_2DLightingShader.toggleDefine("SHADOWS_ENABLED");
// }
//
// if (Input::GetKey(Input::LeftCtrl) && Input::GetKeyDown(Input::D))
// {
// if (Input::GetKey(Input::LeftShift)) {
// m_finalUIShader.toggleDefine("DITHERING");
// } else {
// m_finalUIShader.toggleDefine("DEBUG_SHOW_DISTANCE");
// }
// }
//
// if (Input::GetKey(Input::LeftCtrl) && Input::GetKeyDown(Input::C))
// {
// m_2DLightingShader.toggleDefine("DEBUG_SHOW_COLORS");
// }
//
// if (Input::GetKey(Input::LeftCtrl) && Input::GetKeyDown(Input::A))
// {
// m_2DLightingShader.toggleDefine("ANTIALIASING");
// }
//
// if (Input::GetKey(Input::LeftCtrl) && Input::GetKeyDown(Input::B))
// {
// m_2DDistanceShader.toggleDefine("BLEND_SHAPES");
// }
//
// if (Input::GetKey(Input::LeftCtrl) && Input::GetKeyDown(Input::M))
// {
// m_2DDistanceShader.toggleDefine("MOTION_BLUR");
// m_uiDistanceShader.toggleDefine("MOTION_BLUR");
// }
//
// if (Input::GetKey(Input::LeftCtrl) && Input::GetKeyDown(Input::F))
// {
// USE_CORRECTED_DISTANCE_TEXTURE = !USE_CORRECTED_DISTANCE_TEXTURE;
// }
const char* label = m_config.isUI ? "UI Pipeline" : "World Pipeline";
if (!ImGui::CollapsingHeader(label))
return;

ImGui::PushID(label);

ImGui::SeparatorText("Shadows");
if (ImGui::Checkbox("Shadows", &m_config.enableShadows))
{
if (m_config.enableShadows) m_lightingShader.addDefine("SHADOWS_ENABLED");
else m_lightingShader.removeDefine("SHADOWS_ENABLED");
}
if (ImGui::Checkbox("Long Shadows", &m_config.enableLongShadows))
{
if (m_config.enableLongShadows) m_lightingShader.addDefine("LONG_SHADOWS");
else m_lightingShader.removeDefine("LONG_SHADOWS");
}

ImGui::SeparatorText("Rendering");
if (ImGui::Checkbox("Antialiasing", &m_config.enableAntialiasing))
{
if (m_config.enableAntialiasing) m_lightingShader.addDefine("ANTIALIASING");
else m_lightingShader.removeDefine("ANTIALIASING");
}
if (ImGui::Checkbox("Motion Blur", &m_config.enableMotionBlur))
{
if (m_config.enableMotionBlur) m_distanceShader.addDefine("MOTION_BLUR");
else m_distanceShader.removeDefine("MOTION_BLUR");
}
if (ImGui::Checkbox("Refraction", &m_config.enableRefraction))
{
if (m_config.enableRefraction) m_lightingShader.addDefine("REFRACTION");
else m_lightingShader.removeDefine("REFRACTION");
}

ImGui::SeparatorText("Debug");
if (ImGui::Checkbox("Show Distance Field", &m_config.debugDistanceField))
{
if (m_config.debugDistanceField) m_lightingShader.addDefine("DEBUG_SHOW_DISTANCE");
else m_lightingShader.removeDefine("DEBUG_SHOW_DISTANCE");
}
if (ImGui::Checkbox("Show Material Colors", &m_config.debugMaterialColors))
{
if (m_config.debugMaterialColors) m_lightingShader.addDefine("DEBUG_SHOW_COLORS");
else m_lightingShader.removeDefine("DEBUG_SHOW_COLORS");
}

ImGui::SeparatorText("Ambient Occlusion");
ImGui::SliderFloat("AO Radius", &m_config.ambienOcclusionRadius, 0.0f, 20.0f);
ImGui::SliderFloat("AO Strength", &m_config.ambienOcclusionStrength, 0.0f, 1.0f);

ImGui::SeparatorText("Materials");
ImGui::SliderFloat("Blend Speed", &m_config.materialBlendSpeed, 0.0f, 20.0f);
ImGui::SliderFloat("Smooth Factor (k)", &m_config.ballK, 0.0f, 50.0f);

ImGui::PopID();
}

Shader& SDF2DRenderPipeline::getDistanceShader()
Expand Down
19 changes: 17 additions & 2 deletions src/weird-renderer/core/SDLInitializer.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "weird-renderer/core/SDLInitializer.h"
#include "weird-renderer/audio/AudioEngine.h"

#include <csignal>
#include <glad/glad.h>
#include <iostream>
#include <stdexcept>

#include <glad/glad.h>
#include <imgui.h>
#include <imgui_impl_sdl3.h>
#include <imgui_impl_opengl3.h>

namespace WeirdEngine
{
namespace WeirdRenderer
Expand Down Expand Up @@ -91,6 +95,13 @@ namespace WeirdEngine
throw std::runtime_error("Failed to initialize GLAD.");
}

IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui::StyleColorsDark();

ImGui_ImplSDL3_InitForOpenGL(m_window, m_glContext);
ImGui_ImplOpenGL3_Init("#version 300 es"); // matches your GL ES 3.0 context

#ifndef NDEBUG
// Enable debug output via KHR_debug extension if supported
if (GLAD_GL_KHR_debug)
Expand Down Expand Up @@ -134,6 +145,10 @@ namespace WeirdEngine

SDLInitializer::~SDLInitializer()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL3_Shutdown();
ImGui::DestroyContext();

SDL_DestroyAudioStream(m_audioStream);
SDL_GL_DestroyContext(m_glContext);
SDL_DestroyWindow(m_window);
Expand Down
1 change: 1 addition & 0 deletions third-party/imgui
Submodule imgui added at 691b89
Loading