From 0373b7581eaa37abfcd1e354db509036cf350b1a Mon Sep 17 00:00:00 2001 From: Nathan Chapman Date: Sun, 13 Jul 2025 13:09:57 -0600 Subject: [PATCH] Add more ui --- src/main.cpp | 2 +- src/render_data.h | 2 ++ src/renderer.cpp | 4 ++-- src/renderer.h | 1 - src/user_interface.cpp | 29 +++++++++++++++++++++++++++++ src/window.cpp | 4 ++-- src/window.h | 2 +- 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bde02ac..5083e3d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ int main(int argc, char *argv[]) { Window window; - if (!init(&window, 640, 480, "OpenGL Renderer")) { + if (!init_window(&window, 640, 480, "OpenGL Renderer")) { log(1, "%s error: Window init error\n", __FUNCTION__); return -1; } diff --git a/src/render_data.h b/src/render_data.h index 3cb54a9..a996be9 100644 --- a/src/render_data.h +++ b/src/render_data.h @@ -22,4 +22,6 @@ struct Render_Data { s32 triangle_count = 0; f32 frame_time = 0.0f; f32 user_interface_generate_time = 0.0f; + bool use_alt_shader = false; + s32 field_of_view = 90; }; diff --git a/src/renderer.cpp b/src/renderer.cpp index 2d7960f..8cece55 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -111,12 +111,12 @@ void draw_renderer(Renderer *renderer) { Vector3 camera_look_at_position = Vector3(0.0f, 0.0f, 0.0f); Vector3 camera_up_vector = Vector3(0.0f, 1.0f, 0.0f); - renderer->projection_matrix = glm::perspective(glm::radians(90.0f), static_cast(renderer->render_data.width) / static_cast(renderer->render_data.height), 0.1f, 100.0f); + renderer->projection_matrix = glm::perspective(glm::radians(static_cast(renderer->render_data.field_of_view)), static_cast(renderer->render_data.width) / static_cast(renderer->render_data.height), 0.1f, 10.0f); f32 dt = glfwGetTime(); Matrix4 model = Matrix4(1.0); - if (!renderer->use_alt_shader) { + if (!renderer->render_data.use_alt_shader) { use_shader(&renderer->shader); model = glm::rotate(Matrix4(1.0f), dt, Vector3(0.0f, 0.0f, 1.0f)); } else { diff --git a/src/renderer.h b/src/renderer.h index 0bb839c..8fccba3 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -47,7 +47,6 @@ struct Renderer { Uniform_Buffer uniform_buffer; Texture texture; Mesh mesh; - bool use_alt_shader = false; Matrix4 view_matrix = Matrix4(1.0f); Matrix4 projection_matrix = Matrix4(1.0f); User_Interface user_interface; diff --git a/src/user_interface.cpp b/src/user_interface.cpp index ca77b37..00b4709 100644 --- a/src/user_interface.cpp +++ b/src/user_interface.cpp @@ -49,6 +49,35 @@ void create_user_interface_frame(User_Interface *user_interface, Render_Data *re ImGui::Text("ImGui Window Position:"); ImGui::SameLine(); ImGui::Text(img_window_position.c_str()); + + // Checkbox + static bool checkbox_is_checked = false; + ImGui::Checkbox("Check me", &checkbox_is_checked); + + if (checkbox_is_checked) { + ImGui::SameLine(); + ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255)); + ImGui::Text("Yes"); + ImGui::PopStyleColor(); + } + + // Alt shader toggler + if (ImGui::Button("Toggle shader")) { + render_data->use_alt_shader = !render_data->use_alt_shader; + } + + ImGui::SameLine(); + if (!render_data->use_alt_shader) { + ImGui::Text("Basic shader"); + } else { + ImGui::Text("Alt shader"); + } + + // Field of view slider + ImGui::Text("Field of view"); + ImGui::SameLine(); + ImGui::SliderInt("##FOV", &render_data->field_of_view, 40, 150); + ImGui::End(); } diff --git a/src/window.cpp b/src/window.cpp index 6245ab2..a330580 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,7 +1,7 @@ #include "window.h" #include "logger.h" -bool init(Window *window, u32 width, u32 height, string title) { +bool init_window(Window *window, u32 width, u32 height, string title) { glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND); if (!glfwInit()) { @@ -85,7 +85,7 @@ void handle_key_events(GLFWwindow *gl_window, s32 key, s32 scancode, s32 action, Window *window = static_cast(glfwGetWindowUserPointer(gl_window)); if (glfwGetKey(window->glfw_window, GLFW_KEY_SPACE) == GLFW_PRESS) { - window->renderer->use_alt_shader = !window->renderer->use_alt_shader; + window->renderer->render_data.use_alt_shader = !window->renderer->render_data.use_alt_shader; } } diff --git a/src/window.h b/src/window.h index be575b0..9f974e4 100644 --- a/src/window.h +++ b/src/window.h @@ -9,7 +9,7 @@ struct Window { Model* model = nullptr; }; -bool init(Window *window, u32 width, u32 height, string title); +bool init_window(Window *window, u32 width, u32 height, string title); void main_loop(Window *window); void cleanup(Window *window); void handle_close(GLFWwindow *gl_window);