summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-02-07 22:49:00 +0100
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-02-07 22:49:00 +0100
commit35a70d71f62e41d78d68247075ce174f2b6d997a (patch)
treec9af8d8c44256abfc100c396182fd27f1f4c7263 /src/main.c
inital commit -- THE CUBES SPIN
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..763bd4e
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,92 @@
+#include <stdio.h>
+#include "render/window.h"
+#include "render/renderer.h"
+#include "render/mesh.h"
+
+#define len(X) sizeof(X) / sizeof(*X)
+
+int main() {
+ struct window *win = window_init("vk");
+ if (!win)
+ return -1;
+
+ struct renderer *ren = renderer_init(win);
+ if (!ren) {
+ fputs("failed to init renderer\n", stderr);
+ return -1;
+ }
+
+ struct vertex vertices[] = {
+ { .position = { -0.25, -0.25, -0.25 }, .color = { 0.f, 0.f, 0.f} },
+ { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f} },
+ { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f} },
+ { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f} },
+ { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f} },
+ { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f} },
+ { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f} },
+ { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f} },
+ { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f} },
+ { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f} },
+ { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f} },
+ { .position = { 0.25, 0.25, 0.25,}, .color = { 1.f, 1.f, 1.f} },
+ { .position = { 0.25, 0.25, 0.25,}, .color = { 1.f, 1.f, 1.f} },
+ { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f} },
+ { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f} },
+ { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f} },
+ { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f} },
+ { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f} },
+ { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f} },
+ { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f} },
+ { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f} },
+ { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f} },
+ { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f} },
+ { .position = { -0.25, -0.25, -0.25,}, .color = { 0.f, 0.f, 0.f} },
+ { .position = { 0.25, 0.25, 0.25,}, .color = { 1.f, 1.f, 1.f} },
+ { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f} },
+ { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f} },
+ { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f} },
+ { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f} },
+ { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f} },
+ { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f} },
+ { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f} },
+ { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f} },
+ { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f} },
+ { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f} },
+ { .position = { -0.25, -0.25, -0.25,}, .color = { 0.f, 0.f, 0.f} },
+ };
+
+ uint32_t indices[len(vertices)];
+ for (size_t i = 0; i < len(vertices); i++)
+ indices[i] = i;
+
+ struct mesh meshes[] = {
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 1, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {0, 1, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 0, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 1, 0}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 0, 0}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {0, 0, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {0.5, 0, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 1, 0.5}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 1, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 0.5, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 1, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {0.5, 1, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 1, 1}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {2, 1, 3}),
+ upload_mesh(ren, len(vertices), vertices, len(indices), indices, (struct vec3) {1, 0.5, 1}),
+ };
+
+ while (!win->should_close) {
+ renderer_draw(ren, len(meshes), meshes);
+ wl_display_roundtrip(win->dpy);
+ }
+
+ for (size_t i = 0; i < len(meshes); i++)
+ mesh_destroy(ren, &meshes[i]);
+
+ renderer_destroy(ren);
+ window_destroy(win);
+
+ return 0;
+}