summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index edaf8a3..6cd0252 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,12 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/times.h>
+
+#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
#include <cglm/cglm.h>
#include <cglm/struct.h>
#include "objload.h"
-
#define MONKEY
+
#include "graphics.h"
#include "window.h"
#include "common.h"
@@ -30,15 +32,21 @@ struct ubo {
vertex_t vertices[] = {
{{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}},
- {{ 0.5f, -0.5f, -0.5f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}},
+ {{ 0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}},
{{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}},
+ {{-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}},
+
+ {{-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}},
+ {{ 0.5f, -0.5f, -0.5f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}},
+ {{ 0.5f, 0.5f, -0.5f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}},
{{-0.5f, 0.5f, -0.5f}, {0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}},
};
#endif
u32 indices[] = {
- 0, 1, 2, 2, 3, 0
+ 0, 1, 2, 2, 3, 0,
+ 4, 5, 6, 6, 7, 4,
};
@@ -84,7 +92,6 @@ int main(void)
};
obj_transfer_raw(obj, obj_metadata, &nvertices, NULL);
- // leaks memory
objvertices = xcalloc(nvertices, sizeof(*objvertices));
obj_transfer_raw(obj, obj_metadata, &nvertices, objvertices);
@@ -141,11 +148,19 @@ int main(void)
running = 0;
break;
}
-
- graphics_draw_frame(graphics);
+
+ #ifndef MONKEY
+ graphics_draw_frame(graphics, grph_info.nindices);
+ #else
+ graphics_draw_frame(graphics, grph_info.nvertices);
+ #endif
}
ret = 0;
+
+#ifdef MONKEY
+ free(objvertices);
+#endif
graphics_destroy(graphics);
f3: window_destroy(window);
@@ -164,7 +179,7 @@ int update_ubo(void *uniform_buffer)
glm_rotate(ubo->model, time * glm_rad(90.0f),
(vec3){0.0f, 0.0f, 1.0f});
- glm_lookat((vec3){2.0f, 2.0f, 2.0f}, (vec3){0.0f, 0.0f, 0.0f}, (vec3){0.0f, 0.0f, 1.0f}, ubo->view);
+ glm_lookat((vec3){2.0f, 2.0f, 0.0f}, (vec3){0.0f, 0.0f, 0.0f}, (vec3){0.0f, 0.0f, 1.0f}, ubo->view);
glm_perspective(glm_rad(45.0f), (float)width/(float)height, 0.1f, 10.0f, ubo->proj);