|
|
|
@ -14,7 +14,7 @@ ColoredRect colored_rect(float width, float height, float r, float g, float b, f
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult load_font(const char* atlas_file, const char* metadata_file, FontData* font) {
|
|
|
|
|
VkResult load_font(const char* atlas_file, const char* metadata_file, FontData* font, SymbolInfo** symbols, uint32_t** image) {
|
|
|
|
|
FILE* atlas = fopen(atlas_file, "rb");
|
|
|
|
|
if(atlas == NULL) {
|
|
|
|
|
return VK_ERROR_UNKNOWN;
|
|
|
|
@ -44,9 +44,9 @@ VkResult load_font(const char* atlas_file, const char* metadata_file, FontData*
|
|
|
|
|
return VK_ERROR_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
font->data = malloc(out_size);
|
|
|
|
|
*image = malloc(out_size);
|
|
|
|
|
|
|
|
|
|
result = spng_decode_image(ctx, font->data, out_size, SPNG_FMT_RGBA8, 0);
|
|
|
|
|
result = spng_decode_image(ctx, *image, out_size, SPNG_FMT_RGBA8, 0);
|
|
|
|
|
if(result != SPNG_OK) {
|
|
|
|
|
return VK_ERROR_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
@ -66,6 +66,32 @@ VkResult load_font(const char* atlas_file, const char* metadata_file, FontData*
|
|
|
|
|
if(atlas == NULL) {
|
|
|
|
|
return VK_ERROR_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
uint16_t symbol_count;
|
|
|
|
|
uint8_t ascent, descent;
|
|
|
|
|
fread(&symbol_count, 2, 1, metadata);
|
|
|
|
|
fread(&ascent, 1, 1, metadata);
|
|
|
|
|
fread(&descent, 1, 1, metadata);
|
|
|
|
|
|
|
|
|
|
font->info.num_symbols = ntohs(symbol_count);
|
|
|
|
|
|
|
|
|
|
*symbols = malloc(sizeof(SymbolInfo)*symbol_count);
|
|
|
|
|
font->codes = malloc(sizeof(uint16_t)*symbol_count);
|
|
|
|
|
|
|
|
|
|
uint8_t width;
|
|
|
|
|
uint8_t top;
|
|
|
|
|
uint16_t code;
|
|
|
|
|
uint32_t x;
|
|
|
|
|
for(uint16_t i = 0; i < symbol_count; i++) {
|
|
|
|
|
fread(&code, 2, 1, metadata);
|
|
|
|
|
font->codes[i] = ntohs(code);
|
|
|
|
|
fread(&x, 4, 1, metadata);
|
|
|
|
|
(*symbols)[i].x = ntohl(x);
|
|
|
|
|
fread(&width, 1, 1, metadata);
|
|
|
|
|
(*symbols)[i].width = width;
|
|
|
|
|
fread(&top, 1, 1, metadata);
|
|
|
|
|
(*symbols)[i].top = top;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(metadata);
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
@ -85,13 +111,15 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FontData test_font = {};
|
|
|
|
|
result = load_font("tools/test.png", "tools/test.meta", &test_font);
|
|
|
|
|
uint32_t* test_atlas;
|
|
|
|
|
SymbolInfo* test_symbols;
|
|
|
|
|
result = load_font("tools/test.png", "tools/test.meta", &test_font, &test_symbols, &test_atlas);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FontDescriptor test_font_descriptor;
|
|
|
|
|
result = create_text_descriptor(render_context->device, render_context->allocator, ui_context.font_layout, ui_context.font_pool, &test_font, render_context->transfer_pool, render_context->transfer_queue, &test_font_descriptor);
|
|
|
|
|
result = create_text_descriptor(render_context->device, render_context->allocator, ui_context.font_layout, ui_context.font_pool, &test_font, test_symbols, test_atlas, render_context->transfer_pool, render_context->transfer_queue, &test_font_descriptor);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|