};
void
-logprint(LogLevel level, const char *format, ...) {
+logprint(LogLevel level, const char *format, ...)
+{
va_list va;
va_start(va, format);
logvprint(level, format, va);
// NOTE(Brendan): This always prints a newline.
void
-logvprint(LogLevel level, const char* format, va_list va) {
+logvprint(LogLevel level, const char* format, va_list va)
+{
if (level < LOG_LEVEL_MINIMUM) return;
printf("[%s] ", log_level_strs[level]);
#define WINDOW_TITLE "N-Body Simulation"
internal void
-glfw_key_handler(GLFWwindow* window, i32 key, i32 scancode, i32 action, i32 mods) {
+glfw_key_handler(GLFWwindow* window, i32 key, i32 scancode, i32 action, i32 mods)
+{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, 1);
}
internal void
-glfw_resize_handler(GLFWwindow* window, i32 width, i32 height) {
+glfw_resize_handler(GLFWwindow* window, i32 width, i32 height)
+{
glViewport(0, 0, width, height);
}
internal void
-glfw_error_handler(i32 error, const char* desc) {
+glfw_error_handler(i32 error, const char* desc)
+{
panic_and_die("GLFW Error (%d): %s\n", error, desc);
}
GLFWwindow* window;
internal void
-init_glfw() {
+init_glfw()
+{
logprint(LOG_LEVEL_INFO, "Initializing GLFW");
if (!glfwInit()) panic_and_die("Failed to initalize GLFW.");
glfwSetFramebufferSizeCallback(window, glfw_resize_handler);
// NOTE(Brendan): This may need to be changed if the screen orientation changes.
- glEnable(GL_CULL_FACE);
- glFrontFace(GL_CW);
- glCullFace(GL_BACK);
+ //glEnable(GL_CULL_FACE);
+ //glFrontFace(GL_CW);
+ //glCullFace(GL_BACK);
}
internal void
-deinit_glfw() {
+deinit_glfw()
+{
glfwDestroyWindow(window);
glfwTerminate();
}
internal GLuint
-load_shader(GLenum shader_type, const char* shader_loc) {
+load_shader(GLenum shader_type, const char* shader_loc)
+{
logprint(LOG_LEVEL_INFO, "Loading shader: %s", shader_loc);
GLuint shader = glCreateShader(shader_type);
}
internal GLuint
-create_program(GLuint vertex_shader, GLuint fragment_shader) {
+create_program(GLuint vertex_shader, GLuint fragment_shader)
+{
logprint(LOG_LEVEL_INFO, "Linking GL program");
GLuint program = glCreateProgram();
// NOTE(Brendan): Returns the VAO where the mesh data was bound.
internal GLsizei
-create_circle_mesh() {
+create_circle_mesh()
+{
logprint(LOG_LEVEL_INFO, "Generating circle mesh");
GLsizei vao;
V2f circle_points[CIRCLE_POINT_COUNT] = {};
foreach (i, 0, CIRCLE_POINT_COUNT) {
f32 t = (f32) i / (f32) CIRCLE_POINT_COUNT;
- circle_points[i].x = cos(t * 2 * PI) / 2.0f + 400.0f;
- circle_points[i].y = sin(t * 2 * PI) / 2.0f + 200.0f;
+ circle_points[i].x = cos(t * 2 * PI) * 40.0f + 400.0f;
+ circle_points[i].y = sin(t * 2 * PI) * 40.0f + 200.0f;
}
GLsizei vertex_buffer;
// NOTE(Brendan): dt is expected to be in units of "per second".
internal void
-update(f64 dt) {
+update(f64 dt)
+{
}
internal GLsizei circle_mesh;
internal void
-draw() {
+draw()
+{
glClearColor(0.1, 0.1, 0.1, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
internal void
-loop() {
+loop()
+{
f64 last_time = glfwGetTime();
f64 curr_time = last_time;
f64 delta;
}
i32
-main(i32 argc, char* argv[]) {
+main(i32 argc, char* argv[])
+{
init_glfw();
circle_mesh = create_circle_mesh(NULL);
#include "utils.h"
V2f
-v2f_add(V2f a, V2f b) {
+v2f_add(V2f a, V2f b)
+{
return (V2f) { .x = a.x + b.x, .y = a.y + b.y };
}
V2f
-v2f_sub(V2f a, V2f b) {
+v2f_sub(V2f a, V2f b)
+{
return (V2f) { .x = a.x - b.x, .y = a.y - b.y };
}
V2f
-v2f_mul(V2f a, f32 scalar) {
+v2f_mul(V2f a, f32 scalar)
+{
return (V2f) { .x = a.x * scalar, .y = a.y * scalar };
}
f32
-v2f_dot(V2f a, V2f b) {
+v2f_dot(V2f a, V2f b)
+{
return a.x * b.x + a.y * b.y;
}
f32
-v2f_smag(V2f a) {
+v2f_smag(V2f a)
+{
return v2f_dot(a, a);
}
f32
-v2f_mag(V2f a) {
+v2f_mag(V2f a)
+{
return sqrt(v2f_smag(a));
}
V2f
-v2f_norm(V2f a) {
+v2f_norm(V2f a)
+{
const f32 mag = v2f_mag(a);
return v2f_mul(a, 1.0f / mag);
}
V2f
-v2f_proj(V2f a, V2f onto) {
+v2f_proj(V2f a, V2f onto)
+{
const f32 dp = v2f_dot(a, onto) / v2f_mag(onto);
return v2f_mul(onto, dp);
}