131 lines
2.5 KiB
C
131 lines
2.5 KiB
C
#include "ui.h"
|
|
#include "gpu.h"
|
|
#include "draw.h"
|
|
|
|
#include "arpa/inet.h"
|
|
#include "vk_mem_alloc.h"
|
|
#include "vulkan/vk_enum_string_helper.h"
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
#include "ft2build.h"
|
|
#include FT_FREETYPE_H
|
|
|
|
VkResult render_thread(GLFWwindow* window, RenderContext* render) {
|
|
FT_Library library;
|
|
|
|
UIContextStorage ui;
|
|
|
|
uint32_t font_index;
|
|
uint32_t texture_index;
|
|
|
|
VkResult result;
|
|
|
|
VK_RESULT(create_ui_context(
|
|
10,
|
|
10,
|
|
10,
|
|
render,
|
|
&ui));
|
|
|
|
if(FT_Init_FreeType(&library) != FT_Err_Ok) {
|
|
return VK_ERROR_UNKNOWN;
|
|
}
|
|
|
|
VK_RESULT(load_font("test.ttf", 16, VK_TRUE, library, render, &ui, &font_index));
|
|
|
|
VK_RESULT(load_texture("test.png", render, &ui, &texture_index));
|
|
|
|
UIDrawable image = {
|
|
.pos = {0.0, 0.0},
|
|
.size = {100.0, 200.0},
|
|
.color = {1.0, 1.0, 1.0, 1.0},
|
|
.type = 2,
|
|
.code = 0,
|
|
.id = 0x01,
|
|
};
|
|
|
|
UIDrawable rect = {
|
|
.pos = {100.0, 0.0},
|
|
.size = {100.0, 200.0},
|
|
.color = {1.0, 0.0, 0.0, 1.0},
|
|
.type = 0,
|
|
.id = 0x02,
|
|
};
|
|
|
|
UIString string = {
|
|
.pos = {0.0, 100.0},
|
|
.color = {1.0, 1.0, 1.0, 1.0},
|
|
.size = 32.0,
|
|
.length = strlen("Hello, World!"),
|
|
.offset = 0,
|
|
.id = 0x03,
|
|
};
|
|
|
|
UILayerInput layers[] = {
|
|
{
|
|
.num_drawables = 1,
|
|
.drawables = &image,
|
|
},
|
|
{
|
|
.num_strings = 1,
|
|
.strings = &string,
|
|
.num_codes = strlen("Hello, World!"),
|
|
.codes = malloc(strlen("Hello, World!")*sizeof(uint32_t)),
|
|
.num_drawables = 1,
|
|
.drawables = &rect,
|
|
.font = font_index,
|
|
},
|
|
};
|
|
|
|
map_string("Hello, World!", layers[1].codes, 0, ui.fonts[0].charmap, ui.fonts[0].num_symbols);
|
|
|
|
UIContainerInput container_info = {
|
|
.id = 0xDEADBEEF,
|
|
.pos = {0.0, 0.0},
|
|
.size = {200.0, 200.0},
|
|
.layer_count = sizeof(layers)/sizeof(UILayerInput),
|
|
.layers = layers,
|
|
};
|
|
|
|
VK_RESULT(create_container(&container_info, render, &ui));
|
|
|
|
VK_RESULT(record_draw_commands(render, &ui));
|
|
|
|
while(glfwWindowShouldClose(window) == 0) {
|
|
glfwPollEvents();
|
|
|
|
result = draw_frame(render);
|
|
if(result != VK_SUCCESS) {
|
|
fprintf(stderr, "draw_frame error: %s\n", string_VkResult(result));
|
|
return result;
|
|
}
|
|
}
|
|
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 = {};
|
|
if(init_vulkan(window, &render) != VK_SUCCESS) {
|
|
return 2;
|
|
}
|
|
|
|
if(render_thread(window, &render) != VK_SUCCESS) {
|
|
return 3;
|
|
}
|
|
|
|
return 0;
|
|
}
|