#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, 0.5f } }, { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f, 0.5f } }, { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f, 0.5f } }, { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f, 0.5f } }, { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f, 0.5f } }, { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f, 0.5f } }, { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f, 0.5f } }, { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f, 0.5f } }, { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f, 0.5f } }, { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f, 0.5f } }, { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f, 0.5f } }, { .position = { 0.25, 0.25, 0.25,}, .color = { 1.f, 1.f, 1.f, 0.5f } }, { .position = { 0.25, 0.25, 0.25,}, .color = { 1.f, 1.f, 1.f, 0.5f } }, { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f, 0.5f } }, { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f, 0.5f } }, { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f, 0.5f } }, { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f, 0.5f } }, { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f, 0.5f } }, { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f, 0.5f } }, { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f, 0.5f } }, { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f, 0.5f } }, { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f, 0.5f } }, { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f, 0.5f } }, { .position = { -0.25, -0.25, -0.25,}, .color = { 0.f, 0.f, 0.f, 0.5f } }, { .position = { 0.25, 0.25, 0.25,}, .color = { 1.f, 1.f, 1.f, 0.5f } }, { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f, 0.5f } }, { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f, 0.5f } }, { .position = { 0.25, 0.25, -0.25,}, .color = { 1.f, 1.f, 0.f, 0.5f } }, { .position = { -0.25, 0.25, 0.25,}, .color = { 0.f, 1.f, 1.f, 0.5f } }, { .position = { -0.25, 0.25, -0.25,}, .color = { 0.f, 1.f, 0.f, 0.5f } }, { .position = { 0.25, -0.25, 0.25,}, .color = { 1.f, 0.f, 1.f, 0.5f } }, { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f, 0.5f } }, { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f, 0.5f } }, { .position = { -0.25, -0.25, 0.25,}, .color = { 0.f, 0.f, 1.f, 0.5f } }, { .position = { 0.25, -0.25, -0.25,}, .color = { 1.f, 0.f, 0.f, 0.5f } }, { .position = { -0.25, -0.25, -0.25,}, .color = { 0.f, 0.f, 0.f, 0.5f } }, }; 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; }