void logprint(LogLevel level, const char* format, ...);
void logvprint(LogLevel level, const char* format, va_list va);
-#endif //LOG_H
+#endif //LOG_H
\ No newline at end of file
V2f v2f_norm(V2f a);
V2f v2f_proj(V2f a, V2f onto);
+typedef float mat4[16];
+
+void mat4_identity(mat4 mat);
+void mat4_ortho(mat4 mat,
+ f32 left, f32 right,
+ f32 top, f32 bottom,
+ f32 near, f32 far);
+void mat4_proj(mat4 mat);
+
#endif //VECMATH_H
layout(location = 1) in vec2 a_obj_pos;
layout(location = 2) in float a_mass;
+uniform mat4 u_proj;
+
void main() {
- gl_Position = vec4(a_shape_pos, 0, 1);
+ gl_Position = u_proj * vec4(a_shape_pos, 0, 1);
}
\ No newline at end of file
"ERROR",
};
-void logprint(LogLevel level, const char *format, ...) {
+void
+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) {
+void
+logvprint(LogLevel level, const char* format, va_list va) {
if (level < LOG_LEVEL_MINIMUM) return;
printf("[%s] ", log_level_strs[level]);
glfwSetKeyCallback(window, glfw_key_handler);
glfwSetFramebufferSizeCallback(window, glfw_resize_handler);
- glEnable(GL_CULL_FACE);
- glFrontFace(GL_CCW);
- glCullFace(GL_BACK);
+ //glEnable(GL_CULL_FACE);
+ //glFrontFace(GL_CW);
+ //glCullFace(GL_BACK);
}
internal GLuint
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;
- circle_points[i].y = sin(t * 2 * PI) / 2.0f;
+ circle_points[i].x = cos(t * 2 * PI) * 100.0f + 400.0f;
+ circle_points[i].y = sin(t * 2 * PI) * 100.0f + 200.0f;
}
GLsizei vertex_buffer;
}
}
-i32 main(i32 argc, char* argv[]) {
+i32
+main(i32 argc, char* argv[]) {
init_glfw();
circle_mesh = create_circle_mesh(NULL);
GLuint v_shader = load_shader(GL_VERTEX_SHADER, "res/shaders/planet_vert.glsl");
GLuint f_shader = load_shader(GL_FRAGMENT_SHADER, "res/shaders/planet_frag.glsl");
GLuint program = create_program(v_shader, f_shader);
-
glUseProgram(program);
- loop();
- deinit_opengl();
+ mat4 ortho_mat;
+ mat4_ortho(ortho_mat, 0, 800, 0, 600, 0.0f, 100.0f);
+
+ GLuint ortho_mat_loc = glGetUniformLocation(program, "u_proj");
+ glUniformMatrix4fv(ortho_mat_loc, 1, false, (f32 *) ortho_mat);
+
+ loop();
+
+ deinit_opengl();
- return 0;
+ return 0;
}
\ No newline at end of file
#include "log.h"
-void panic_and_die(const char* msg, ...) {
+void
+panic_and_die(const char* msg, ...) {
puts("************ PANIC ************");
va_list va;
#include "vecmath.h"
#include <math.h>
-V2f v2f_add(V2f a, V2f b) {
+#include "utils.h"
+
+V2f
+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
+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
+v2f_mul(V2f a, f32 scalar) {
return (V2f) { .x = a.x * scalar, .y = a.y * scalar };
}
-f32 v2f_dot(V2f a, V2f b) {
+f32
+v2f_dot(V2f a, V2f b) {
return a.x * b.x + a.y * b.y;
}
-f32 v2f_smag(V2f a) {
+f32
+v2f_smag(V2f a) {
return v2f_dot(a, a);
}
-f32 v2f_mag(V2f a) {
+f32
+v2f_mag(V2f a) {
return sqrt(v2f_smag(a));
}
-V2f v2f_norm(V2f a) {
+V2f
+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
+v2f_proj(V2f a, V2f onto) {
const f32 dp = v2f_dot(a, onto) / v2f_mag(onto);
return v2f_mul(onto, dp);
-}
\ No newline at end of file
+}
+
+
+
+void
+mat4_identity(mat4 mat)
+{
+ foreach(i, 0, 16) mat[i] = 0.0f;
+ mat[0 * 4 + 0] = 1.0f;
+ mat[1 * 4 + 1] = 1.0f;
+ mat[2 * 4 + 2] = 1.0f;
+ mat[3 * 4 + 3] = 1.0f;
+}
+
+void
+mat4_ortho(mat4 mat,
+ f32 left, f32 right,
+ f32 top, f32 bottom,
+ f32 near, f32 far)
+{
+ foreach(i, 0, 16) mat[i] = 0.0;
+
+ mat[0 * 4 + 0] = 2.0f / (right - left);
+ mat[1 * 4 + 1] = 2.0f / (top - bottom);
+ mat[2 * 4 + 2] = -2.0f / (far - near);
+ mat[3 * 4 + 3] = 1.0f;
+
+ mat[3 * 4 + 0] = -(right + left) / (right - left);
+ mat[3 * 4 + 1] = -(top + bottom) / (top - bottom);
+ mat[3 * 4 + 2] = -(far + near) / (far - near);
+}