From 2821847ce25855ce8832be9cd64549ab5ce9aa5f Mon Sep 17 00:00:00 2001 From: Seth Hamilton Date: Thu, 11 Sep 2025 08:23:02 -0500 Subject: [PATCH] Can build the project. Now trying to isolate opengl problem --- .gitignore | 1 + bin/LivePlotter.exp | Bin 1420 -> 1420 bytes bin/LivePlotter.lib | 2 +- build.sh | 19 +++-- compile_commands.json | 13 ++-- debug.cap | 28 +++++++ debug.rad | 15 ++++ export_compdb.sh | 2 +- inc/gldebug.hpp | 97 ++++++++++++++++++++++++ src/{plotter => }/body.cpp | 0 src/{plotter => }/camera.cpp | 3 +- src/{plotter => }/glad.c | 0 src/{plotter => }/live_plotter.cpp | 40 +++++++--- src/{plotter => }/shaders.cpp | 1 + src/{plotter => }/shaders/fragment.glsl | 0 src/{plotter => }/shaders/vertex.glsl | 0 src/{plotter => }/util.cpp | 3 +- 17 files changed, 197 insertions(+), 27 deletions(-) create mode 100644 debug.cap create mode 100644 debug.rad create mode 100644 inc/gldebug.hpp rename src/{plotter => }/body.cpp (100%) rename src/{plotter => }/camera.cpp (93%) rename src/{plotter => }/glad.c (100%) rename src/{plotter => }/live_plotter.cpp (88%) rename src/{plotter => }/shaders.cpp (99%) rename src/{plotter => }/shaders/fragment.glsl (100%) rename src/{plotter => }/shaders/vertex.glsl (100%) rename src/{plotter => }/util.cpp (93%) diff --git a/.gitignore b/.gitignore index 3e3a9ac..93a592c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ x64** **.exe .cache** tags +bin/* diff --git a/bin/LivePlotter.exp b/bin/LivePlotter.exp index d455879af4c012bd7d365888dde2f5dc0a79c7fc..f369791ff134842eb9e9d902c7bffb28e339004d 100644 GIT binary patch delta 36 scmeC-?&02G$Hbz;Frjm@6Vq&V6Fp;7BLnlvPnfncP3YV_oB1On0L9V^&;S4c delta 36 scmeC-?&02G$Hbz=(9$;9iD@>wk)E-MiLvqICrn$JTG}?xX8y compile_commands.json -find src -iname "*.cpp" -exec sh -c 'echo { \"directory\": \"$(cygpath -m $(pwd))\", \"command\": \"cl "$(cygpath -m {})" -I inc -I ext/glm -I ../ext/glfw/include -Od -std:c++20 -Fo\", \"file\": \"$(cygpath -m {})\" }, >> compile_commands.json' \; +find src -iname "*.cpp" -exec sh -c 'echo { \"directory\": \"$(cygpath -m $(pwd))\", \"command\": \"cl "$(cygpath -m {})" -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo\", \"file\": \"$(cygpath -m {})\" }, >> compile_commands.json' \; echo ] >> compile_commands.json diff --git a/inc/gldebug.hpp b/inc/gldebug.hpp new file mode 100644 index 0000000..6ba036a --- /dev/null +++ b/inc/gldebug.hpp @@ -0,0 +1,97 @@ +#pragma once + +#include + +#include +#include + +void APIENTRY gl_debug_cb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) +{ + // Some debug messages are just annoying informational messages + switch (id) + { + case 131185: // glBufferData + return; + } + + printf("Message: %s\n", message); + printf("Source: "); + + switch (source) + { + case GL_DEBUG_SOURCE_API: + printf("API"); + break; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM: + printf("Window System"); + break; + case GL_DEBUG_SOURCE_SHADER_COMPILER: + printf("Shader Compiler"); + break; + case GL_DEBUG_SOURCE_THIRD_PARTY: + printf("Third Party"); + break; + case GL_DEBUG_SOURCE_APPLICATION: + printf("Application"); + break; + case GL_DEBUG_SOURCE_OTHER: + printf("Other"); + break; + } + + printf("\n"); + printf("Type: "); + + switch (type) + { + case GL_DEBUG_TYPE_ERROR: + printf("Error"); + break; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: + printf("Deprecated Behavior"); + break; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: + printf("Undefined Behavior"); + break; + case GL_DEBUG_TYPE_PORTABILITY: + printf("Portability"); + break; + case GL_DEBUG_TYPE_PERFORMANCE: + printf("Performance"); + break; + case GL_DEBUG_TYPE_MARKER: + printf("Marker"); + break; + case GL_DEBUG_TYPE_PUSH_GROUP: + printf("Push Group"); + break; + case GL_DEBUG_TYPE_POP_GROUP: + printf("Pop Group"); + break; + case GL_DEBUG_TYPE_OTHER: + printf("Other"); + break; + } + + printf("\n"); + printf("ID: %d\n", id); + printf("Severity: "); + + switch (severity) + { + case GL_DEBUG_SEVERITY_HIGH: + printf("High"); + break; + case GL_DEBUG_SEVERITY_MEDIUM: + printf("Medium"); + break; + case GL_DEBUG_SEVERITY_LOW: + printf("Low"); + break; + case GL_DEBUG_SEVERITY_NOTIFICATION: + printf("Notification"); + break; + } + + printf("\n\n"); +} diff --git a/src/plotter/body.cpp b/src/body.cpp similarity index 100% rename from src/plotter/body.cpp rename to src/body.cpp diff --git a/src/plotter/camera.cpp b/src/camera.cpp similarity index 93% rename from src/plotter/camera.cpp rename to src/camera.cpp index ff5b7d5..e923b70 100644 --- a/src/plotter/camera.cpp +++ b/src/camera.cpp @@ -42,7 +42,8 @@ glm::mat4 world_to_camera(Camera& c) { glm::mat4 rotation_theta = glm::rotate(glm::mat4(1), c.theta, {0, 1, 0}); glm::mat4 rotation_phi = glm::rotate(glm::mat4(1), c.phi, {1, 0, 0}); glm::mat4 rotated_focus_to_camera = glm::translate(glm::mat4(1), { 0, 0, -c.distance }); - return rotated_focus_to_camera * rotation_phi * rotation_theta * world_to_focus; + glm::mat4 res = rotated_focus_to_camera * rotation_phi * rotation_theta * world_to_focus; + return res; } glm::mat4 camera_to_world(Camera& c) { return glm::inverse(world_to_camera(c)); } diff --git a/src/plotter/glad.c b/src/glad.c similarity index 100% rename from src/plotter/glad.c rename to src/glad.c diff --git a/src/plotter/live_plotter.cpp b/src/live_plotter.cpp similarity index 88% rename from src/plotter/live_plotter.cpp rename to src/live_plotter.cpp index 24df280..17255dc 100644 --- a/src/plotter/live_plotter.cpp +++ b/src/live_plotter.cpp @@ -1,28 +1,29 @@ #include #include +#include +#include +#include #include #include #include #include #include -#include #include #include #include #include #include #include -#include -#include -#include +#include "glm/gtc/type_ptr.hpp" #include "sync.hpp" #include "util.hpp" #include "shaders.hpp" #include "body.hpp" #include "camera.hpp" #include "live_plotter.hpp" +#include "gldebug.hpp" using namespace sync; @@ -69,6 +70,7 @@ bool _glfw_setup(); void _refresh_win(); double _time(); + extern DllExport bool __cdecl start(int win_w, int win_h) { if (running) { printf("Already running! Call stop before calling stop again\n"); @@ -112,7 +114,8 @@ extern DllExport bool __cdecl stop() { extern DllExport pointid __cdecl create_point(float x, float y, float z) { lock(m); - // This is stupid. Please fix + // TODO: This system is really stupid. Please fix + // Also what happens if there isn't a replaceable point? int slot = -1; int start_loc = point_buf_i; do { @@ -125,7 +128,7 @@ extern DllExport pointid __cdecl create_point(float x, float y, float z) { assert(slot > -1); - point_buf[slot] = { + point_buf[slot] = { .initialized = false, .replaceable = false, .startloc = glm::vec3(x, y, z), @@ -206,8 +209,8 @@ void _scroll_cb(GLFWwindow* win, double xoffset, double yoffset) { zoom_camera(c DWORD _win_thread(LPVOID args) { glm::vec2* winsize = (glm::vec2*)args; camera = make_camera({ 0, 0, 0 }, 10); - camera.theta = glm::radians(90.0f); - camera.phi = glm::radians(30.0f); + camera.theta = glm::radians(0.0f); + camera.phi = glm::radians(0.0f); viewport = make_viewport(winsize->x, winsize->y, 45.0f); if (!_glfw_setup()) { printf("Failed to initialize glfw window\n"); @@ -219,6 +222,17 @@ DWORD _win_thread(LPVOID args) { return -1; } + printf("Open GL Vendor: %s\n", glGetString(GL_VENDOR)); + printf("Open GL Renderer: %s\n", glGetString(GL_RENDERER)); + printf("Open GL Version: %s\n", glGetString(GL_VERSION)); + printf("Open GL Shader Language Version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); + + // Enable debug messages + glEnable(GL_DEBUG_OUTPUT); + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + glDebugMessageCallback(gl_debug_cb, 0); + glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE); + if (!load_shader(&shader, vertex_filepath, fragment_filepath)) { printf("Failed to compile shaders\n"); return -1; @@ -243,9 +257,11 @@ DWORD _win_thread(LPVOID args) { bool _glfw_setup() { glfwInit(); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + win = glfwCreateWindow(viewport.width, viewport.height, "LivePlotter", NULL, NULL); if (win == NULL) { printf("Failed to create GLFW window\n"); @@ -258,6 +274,7 @@ bool _glfw_setup() { glfwSetMouseButtonCallback(win, _mouse_button_cb); glfwSetScrollCallback(win, _scroll_cb); + _cursor_pos_cb(win, 0, 0); return true; } @@ -267,6 +284,11 @@ void _refresh_win() { set_uniform(shader, "camera_t", world_to_camera(camera)); set_uniform(shader, "projection_t", camera_to_projection(viewport)); + /*glm::mat4 cam = world_to_camera(camera); + glm::mat4 view = camera_to_projection(viewport); + glUniformMatrix4fv(glGetUniformLocation(shader, "camera_t"), 1, GL_FALSE, glm::value_ptr(cam)); + glUniformMatrix4fv(glGetUniformLocation(shader, "projection_t"), 1, GL_FALSE, glm::value_ptr(view));*/ + if (trylock(m)) { for (int i = 0; i < point_buf_len; i++) { Point &p = point_buf[i]; diff --git a/src/plotter/shaders.cpp b/src/shaders.cpp similarity index 99% rename from src/plotter/shaders.cpp rename to src/shaders.cpp index e5691f5..a6e472d 100644 --- a/src/plotter/shaders.cpp +++ b/src/shaders.cpp @@ -85,6 +85,7 @@ bool _compile_shader(uint *out_id, const char* filepath, int shader_type) { glGetShaderInfoLog(id, MAX_ERR_MSG_LEN, NULL, err_msg); printf("Error compiling shader %s\n", filepath); printf("Error msg: %s\n", err_msg); + return false; } *out_id = id; return status == GL_TRUE; diff --git a/src/plotter/shaders/fragment.glsl b/src/shaders/fragment.glsl similarity index 100% rename from src/plotter/shaders/fragment.glsl rename to src/shaders/fragment.glsl diff --git a/src/plotter/shaders/vertex.glsl b/src/shaders/vertex.glsl similarity index 100% rename from src/plotter/shaders/vertex.glsl rename to src/shaders/vertex.glsl diff --git a/src/plotter/util.cpp b/src/util.cpp similarity index 93% rename from src/plotter/util.cpp rename to src/util.cpp index 51900e5..cb45249 100644 --- a/src/plotter/util.cpp +++ b/src/util.cpp @@ -12,6 +12,7 @@ bool read_file(string* s, const char* filepath) { return false; } *s = { istreambuf_iterator(file), istreambuf_iterator() }; + return true; } vector split_str(string s, char delim) { @@ -40,4 +41,4 @@ glm::mat4 quat_to_mat4(glm::quat q) { return glm::mat4(col0, col1, col2, col3); } -float randf() { return (float)rand() / (float)RAND_MAX; } \ No newline at end of file +float randf() { return (float)rand() / (float)RAND_MAX; }