diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-11-10 21:30:33 +0200 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-11-10 21:30:33 +0200 |
commit | 2a733f3d513a7279c1df4efe88fc5386ced2ed14 (patch) | |
tree | 800bd6d5c63034b9408d38c7a2b6264297981fbd /src/main.c | |
parent | 4512fafc57d2ad95b83c8476781ce105a2cdc4e5 (diff) |
uniform buffer added
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 41 |
1 files changed, 38 insertions, 3 deletions
@@ -1,14 +1,27 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/times.h> +#include <cglm/cglm.h> +#include <cglm/struct.h> #include "graphics.h" #include "window.h" #include "common.h" +#define SW 640 +#define SH 480 + window_t window; graphics_t graphics; int _create_surface(VkInstance instance, VkSurfaceKHR *surface); +int update_ubo(void *uniform_buffer); + +struct ubo { + mat4 model; + mat4 view; + mat4 proj; +}; vertex_t vertices[] = { {{-0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}}, @@ -33,9 +46,9 @@ int main(void) // populate window info struct window_info win_info = {0}; win_info.title = "Test App"; - win_info.flags = SDL_WINDOW_RESIZABLE; - win_info.w = 640; - win_info.h = 480; + // win_info.flags = SDL_WINDOW_RESIZABLE; + win_info.w = SW; + win_info.h = SH; // create window window = window_create(&win_info); @@ -64,6 +77,9 @@ int main(void) grph_info.indices = indices; grph_info.nindices = ARR_SIZE(indices); + grph_info.ubo_size = sizeof(struct ubo); + grph_info.update_ubo = update_ubo; + grph_info.surface_func = _create_surface; // create the device @@ -96,6 +112,25 @@ f2: SDL_Quit(); f1: return ret; } +int update_ubo(void *uniform_buffer) +{ + struct ubo *ubo = (struct ubo *)uniform_buffer; + + static float time = 1.0f; + time += 0.01f; + + memcpy(ubo->model, glms_mat4_identity().raw, sizeof(ubo->model)); + glm_rotate(&ubo->model, time * glm_rad(90.0f), + (vec3){0.0f, 0.0f, 1.0f}); + + glm_lookat((vec3){1.0f, 1.0f, 2.0f}, (vec3){0.0f, 0.0f, 0.0f}, (vec3){0.0f, 0.0f, 1.0f}, ubo->view); + + glm_perspective(glm_rad(45.0f), (float)SW/(float)SH, 0.1f, 10.0f, ubo->proj); + + ubo->proj[1][1] *= -1; + return 0; +} + int _create_surface(VkInstance instance, VkSurfaceKHR *surface) { return window_create_surface(window, instance, surface); |