roleplay/client/src/main.c

97 lines
2.6 KiB
C

2024-10-09 10:54:19 -06:00
#include "render.h"
#include "pipeline.h"
#include "vk_mem_alloc.h"
#include "vulkan/vk_enum_string_helper.h"
2024-10-09 10:54:19 -06:00
ColoredRect colored_rect(float width, float height, float r, float g, float b, float a, float x, float y, float z) {
ColoredRect rect = {
.size = {width, height},
.pos = {x, y, z},
.color = {r, g, b, a},
};
return rect;
}
VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
VkResult result;
UIContext ui_context;
VkBuffer colored_rect_buffer;
VmaAllocation colored_rect_memory;
result = init_pipelines(render_context->device, render_context->allocator, render_context->swapchain_extent, render_context->world_render_pass, render_context->transfer_queue, render_context->transfer_pool, &ui_context);
if(result != VK_SUCCESS) {
return result;
}
VkBufferCreateInfo colored_rect_buffer_info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
.size = 3*sizeof(ColoredRect),
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
};
VmaAllocationCreateInfo colored_rect_memory_info = {
.usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
};
result = vmaCreateBuffer(render_context->allocator, &colored_rect_buffer_info, &colored_rect_memory_info, &colored_rect_buffer, &colored_rect_memory, NULL);
if(result != VK_SUCCESS) {
return result;
}
ColoredRect* colored_rects;
result = vmaMapMemory(render_context->allocator, colored_rect_memory, (void**)&colored_rects);
if(result != VK_SUCCESS) {
return result;
}
colored_rects[0] = colored_rect(100.0, 100.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.5);
colored_rects[1] = colored_rect(100.0, 100.0, 0.0, 1.0, 0.0, 1.0, 0.0, 100.0, 0.5);
colored_rects[2] = colored_rect(100.0, 100.0, 0.0, 0.0, 1.0, 1.0, 100.0, 0.0, 0.5);
vmaUnmapMemory(render_context->allocator, colored_rect_memory);
UILayer test_layer = {
.colored_rects = colored_rect_buffer,
.colored_rect_count = 3,
};
2024-10-09 10:54:19 -06:00
while(glfwWindowShouldClose(window) == 0) {
glfwPollEvents();
result = draw_frame(render_context, &ui_context, &test_layer, 1);
if(result != VK_SUCCESS) {
fprintf(stderr, "draw_frame error: %s\n", string_VkResult(result));
return result;
}
2024-10-09 10:54:19 -06:00
}
return 0;
}
int logic_thread() {
return 0;
}
int network_thread() {
return 0;
}
int main() {
GLFWwindow* window = init_window();
if(window == NULL) {
return 1;
}
RenderContext render_context = {};
if(init_vulkan(window, &render_context) != VK_SUCCESS) {
return 2;
}
if(render_thread(window, &render_context) != VK_SUCCESS) {
2024-10-09 10:54:19 -06:00
return 3;
}
return 0;
}