+#define DEBUG
+
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#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;
vprintf(msg, va);
va_end(va);
+#ifdef DEBUG
+ // NOTE: This allows for a debugger to stop here.
+ __asm("int $3");
+#endif
+
exit(1);
}
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() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
+ update();
draw();
}
}
init_opengl();
loop();
deinit_opengl();
+
+ return 0;
}
\ No newline at end of file