From: Brendan Hansen Date: Tue, 13 Oct 2020 16:29:42 +0000 (-0500) Subject: small changes for debugging and error messages X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=fb989202498ad374a234af647709a012bce607c9;p=csc718.git small changes for debugging and error messages --- diff --git a/Makefile b/Makefile index 731481f..56b386b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ endif endif INCLUDES=-I./include -LIBS=-lGL -lglfw +LIBS=-lGL -lglfw -lm TARGET=./sim ifeq ($(RELEASE), 1) diff --git a/doc/plan b/doc/plan new file mode 100644 index 0000000..e69de29 diff --git a/src/sim.c b/src/sim.c index fbd700c..a5dc708 100644 --- a/src/sim.c +++ b/src/sim.c @@ -1,3 +1,5 @@ +#define DEBUG + #include #include #include @@ -11,7 +13,7 @@ #define WINDOW_HEIGHT 900 #define WINDOW_TITLE "N-Body Simulation" -void __attribute__((noreturn)) panic_and_die(char* msg, ...) { +void __attribute__((noreturn)) panic_and_die(const char* msg, ...) { puts("************ PANIC ************"); va_list va; @@ -19,6 +21,11 @@ void __attribute__((noreturn)) panic_and_die(char* msg, ...) { vprintf(msg, va); va_end(va); +#ifdef DEBUG + // NOTE: This allows for a debugger to stop here. + __asm("int $3"); +#endif + exit(1); } @@ -27,20 +34,35 @@ void glfw_key_handler(GLFWwindow* window, int key, int scancode, int action, int glfwSetWindowShouldClose(window, 1); } +void glfw_resize_handler(GLFWwindow* window, int width, int height) { + glViewport(0, 0, width, height); +} + +void glfw_error_handler(int error, const char* desc) { + panic_and_die("GLFW Error (%d): %s\n", error, desc); +} + GLFWwindow* window; void init_opengl() { if (!glfwInit()) panic_and_die("Failed to initalize GLFW."); + glfwSetErrorCallback(glfw_error_handler); window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, NULL, NULL); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwMakeContextCurrent(window); + glfwSwapInterval(1); glfwSetKeyCallback(window, glfw_key_handler); + glfwSetFramebufferSizeCallback(window, glfw_resize_handler); } void deinit_opengl() { glfwDestroyWindow(window); + glfwTerminate(); +} + +void update() { } void draw() { @@ -53,6 +75,7 @@ void loop() { while (!glfwWindowShouldClose(window)) { glfwPollEvents(); + update(); draw(); } } @@ -61,4 +84,6 @@ int main(int argc, char* argv[]) { init_opengl(); loop(); deinit_opengl(); + + return 0; } \ No newline at end of file