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 d455879..f369791 100644 Binary files a/bin/LivePlotter.exp and b/bin/LivePlotter.exp differ diff --git a/bin/LivePlotter.lib b/bin/LivePlotter.lib index 2495e10..d9febab 100644 --- a/bin/LivePlotter.lib +++ b/bin/LivePlotter.lib @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e5016b6f4a9202a03ce3439bf5277c921bcaf3dbaff8678254e5fff725513a63 +oid sha256:720a87c22d2acdb782341eea896fadec28cb3485f71026f37efab264e8702229 size 2986 diff --git a/build.sh b/build.sh index 1c56bc6..aabc36d 100644 --- a/build.sh +++ b/build.sh @@ -1,17 +1,22 @@ ( cd bin rm * - demo_srcs=../src/demo/* - plotter_srcs=../src/plotter/*.cpp - glad_src=../src/plotter/glad.c + demo_srcs=../src/demo/*.cpp + demo_srcs+=" ../src/util.cpp" + plotter_srcs=../src/*.cpp + glad_src=../src/glad.c glfw_lib=../ext/glfw/build/src/Debug/glfw3.lib if [ $# -eq 1 ] && [ "$1" == "release" ] then - flags="-O2" + dll_flags="-O2 -MTd" + exe_flags="-O2 -MT" else - flags="-Od -ZI" + dll_flags="-Od -ZI -MDd" + exe_flags="-Od -ZI -MD" fi echo $flags - cl $plotter_srcs $glad_src $glfw_lib -I ../inc -I ../ext/glm -I ../ext/glfw/include $flags -std:c++20 -LD -FeLivePlotter.dll - cl $demo_srcs -I ../inc -I ../ext/glm $flags -std:c++20 -Fedemo.exe + cl $plotter_srcs $glad_src $glfw_lib kernel32.lib user32.lib Gdi32.lib Shell32.lib -I ../inc -I ../ext/glm -I ../ext/glfw/include $dll_flags -MP -std:c++20 -LD -FeLivePlotter.dll + cp ../src/shaders/* . + cp ../assets/* . + cl $demo_srcs -I ../inc -I ../ext/glm $exe_flags -MP -std:c++20 -Fedemo.exe ) diff --git a/compile_commands.json b/compile_commands.json index dcd3e12..7fc0065 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -1,9 +1,8 @@ [ -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/demo/demo.cpp -I inc -I ext/glm -I ../ext/glfw/include -Od -std:c++20 -Fo", "file": "src/demo/demo.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/plotter/body.cpp -I inc -I ext/glm -I ../ext/glfw/include -Od -std:c++20 -Fo", "file": "src/plotter/body.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/plotter/camera.cpp -I inc -I ext/glm -I ../ext/glfw/include -Od -std:c++20 -Fo", "file": "src/plotter/camera.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/plotter/live_plotter.cpp -I inc -I ext/glm -I ../ext/glfw/include -Od -std:c++20 -Fo", "file": "src/plotter/live_plotter.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/plotter/logger.cpp -I inc -I ext/glm -I ../ext/glfw/include -Od -std:c++20 -Fo", "file": "src/plotter/logger.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/plotter/shaders.cpp -I inc -I ext/glm -I ../ext/glfw/include -Od -std:c++20 -Fo", "file": "src/plotter/shaders.cpp" }, -{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/plotter/util.cpp -I inc -I ext/glm -I ../ext/glfw/include -Od -std:c++20 -Fo", "file": "src/plotter/util.cpp" }, +{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/body.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/body.cpp" }, +{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/camera.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/camera.cpp" }, +{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/demo/demo.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/demo/demo.cpp" }, +{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/live_plotter.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/live_plotter.cpp" }, +{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/shaders.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/shaders.cpp" }, +{ "directory": "C:/Users/sethh/Documents/repos/LivePlotter", "command": "cl src/util.cpp -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo", "file": "src/util.cpp" }, ] diff --git a/debug.cap b/debug.cap new file mode 100644 index 0000000..77e5d44 --- /dev/null +++ b/debug.cap @@ -0,0 +1,28 @@ +{ + "rdocCaptureSettings": 1, + "settings": { + "autoStart": false, + "commandLine": "", + "environment": [ + ], + "executable": "C:\\Users\\sethh\\Documents\\repos\\LivePlotter\\bin\\demo.exe", + "inject": false, + "numQueuedFrames": 0, + "options": { + "allowFullscreen": true, + "allowVSync": true, + "apiValidation": false, + "captureAllCmdLists": false, + "captureCallstacks": false, + "captureCallstacksOnlyDraws": false, + "debugOutputMute": true, + "delayForDebugger": 0, + "hookIntoChildren": false, + "refAllResources": false, + "softMemoryLimit": 0, + "verifyBufferAccess": false + }, + "queuedFrameCap": 0, + "workingDir": "" + } +} diff --git a/debug.rad b/debug.rad new file mode 100644 index 0000000..cb9a876 --- /dev/null +++ b/debug.rad @@ -0,0 +1,15 @@ +// raddbg 0.9.21 project file + +recent_file: path: "src/live_plotter.cpp" +recent_file: path: "src/camera.cpp" +recent_file: path: "src/body.cpp" +recent_file: path: "src/shaders.cpp" +recent_file: path: "../../../../../Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/include/variant" +recent_file: path: "../../../../../Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/include/type_traits" +recent_file: path: "src/demo/demo.cpp" +target: +{ + executable: "bin/demo.exe" + working_directory: bin + enabled: 1 +} diff --git a/export_compdb.sh b/export_compdb.sh index 0471cb1..46046a3 100644 --- a/export_compdb.sh +++ b/export_compdb.sh @@ -1,5 +1,5 @@ srcs=src/* echo [ > 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; }