Add more ui

This commit is contained in:
Nathan Chapman 2025-07-13 13:09:57 -06:00
parent fd9162ef64
commit 0373b7581e
7 changed files with 37 additions and 7 deletions

View File

@ -4,7 +4,7 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Window window; 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__); log(1, "%s error: Window init error\n", __FUNCTION__);
return -1; return -1;
} }

View File

@ -22,4 +22,6 @@ struct Render_Data {
s32 triangle_count = 0; s32 triangle_count = 0;
f32 frame_time = 0.0f; f32 frame_time = 0.0f;
f32 user_interface_generate_time = 0.0f; f32 user_interface_generate_time = 0.0f;
bool use_alt_shader = false;
s32 field_of_view = 90;
}; };

View File

@ -111,12 +111,12 @@ void draw_renderer(Renderer *renderer) {
Vector3 camera_look_at_position = Vector3(0.0f, 0.0f, 0.0f); Vector3 camera_look_at_position = Vector3(0.0f, 0.0f, 0.0f);
Vector3 camera_up_vector = Vector3(0.0f, 1.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<f32>(renderer->render_data.width) / static_cast<f32>(renderer->render_data.height), 0.1f, 100.0f); renderer->projection_matrix = glm::perspective(glm::radians(static_cast<f32>(renderer->render_data.field_of_view)), static_cast<f32>(renderer->render_data.width) / static_cast<f32>(renderer->render_data.height), 0.1f, 10.0f);
f32 dt = glfwGetTime(); f32 dt = glfwGetTime();
Matrix4 model = Matrix4(1.0); Matrix4 model = Matrix4(1.0);
if (!renderer->use_alt_shader) { if (!renderer->render_data.use_alt_shader) {
use_shader(&renderer->shader); use_shader(&renderer->shader);
model = glm::rotate(Matrix4(1.0f), dt, Vector3(0.0f, 0.0f, 1.0f)); model = glm::rotate(Matrix4(1.0f), dt, Vector3(0.0f, 0.0f, 1.0f));
} else { } else {

View File

@ -47,7 +47,6 @@ struct Renderer {
Uniform_Buffer uniform_buffer; Uniform_Buffer uniform_buffer;
Texture texture; Texture texture;
Mesh mesh; Mesh mesh;
bool use_alt_shader = false;
Matrix4 view_matrix = Matrix4(1.0f); Matrix4 view_matrix = Matrix4(1.0f);
Matrix4 projection_matrix = Matrix4(1.0f); Matrix4 projection_matrix = Matrix4(1.0f);
User_Interface user_interface; User_Interface user_interface;

View File

@ -49,6 +49,35 @@ void create_user_interface_frame(User_Interface *user_interface, Render_Data *re
ImGui::Text("ImGui Window Position:"); ImGui::Text("ImGui Window Position:");
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text(img_window_position.c_str()); 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(); ImGui::End();
} }

View File

@ -1,7 +1,7 @@
#include "window.h" #include "window.h"
#include "logger.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); glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
if (!glfwInit()) { if (!glfwInit()) {
@ -85,7 +85,7 @@ void handle_key_events(GLFWwindow *gl_window, s32 key, s32 scancode, s32 action,
Window *window = static_cast<Window *>(glfwGetWindowUserPointer(gl_window)); Window *window = static_cast<Window *>(glfwGetWindowUserPointer(gl_window));
if (glfwGetKey(window->glfw_window, GLFW_KEY_SPACE) == GLFW_PRESS) { 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;
} }
} }

View File

@ -9,7 +9,7 @@ struct Window {
Model* model = nullptr; 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 main_loop(Window *window);
void cleanup(Window *window); void cleanup(Window *window);
void handle_close(GLFWwindow *gl_window); void handle_close(GLFWwindow *gl_window);