From 35a70d71f62e41d78d68247075ce174f2b6d997a Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Wed, 7 Feb 2024 22:49:00 +0100 Subject: inital commit -- THE CUBES SPIN Signed-off-by: Anna (navi) Figueiredo Gomes --- src/main.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') 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 +#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; +} -- cgit v1.2.3