From 021fc8af7925d58ef9f8085c9bd42fe405d4269e Mon Sep 17 00:00:00 2001 From: KitsuneAlex Date: Thu, 2 May 2024 14:15:57 +0200 Subject: [PATCH] Remove unused typedef from API header & add simple example to README --- README.md | 45 ++++++++++++++++++++++++++++++++++++++++++--- msdfgen_c.h | 5 ----- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 717698f..860c409 100644 --- a/README.md +++ b/README.md @@ -111,10 +111,10 @@ in order to generate a distance field. Please note that all classes and function - You may also render an image from the distance field using `renderSDF`. Consider calling `simulate8bit` on the distance field beforehand to simulate the standard 8 bits/channel image format. -Example: +**Example using the C++ API:** ```c++ -#include "msdfgen.h" -#include "msdfgen-ext.h" +#include +#include using namespace msdfgen; @@ -144,6 +144,45 @@ int main() { ``` +**Example using the C API:** +```c++ +#include + +inline void create_shape(msdf_shape_handle* shape, char value) { + msdf_shape_handle shape = NULL; + if(msdf_shape_alloc(&shape) != MSDF_SUCCESS) { + return; // Handle error accordingly + } + // Create shape data from font using FreeType, STB etc here.. +} + +int main(int num_args, char** args) { + msdf_bitmap_t* bitmap = NULL; + if(msdf_bitmap_alloc(MSDF_BITMAP_TYPE_MSDF, 16, 16, &bitmap) != MSDF_SUCCESS) { + return 1; + } + msdf_shape_handle shape = NULL; + create_shape(&shape, 'A'); + msdf_transform_t transform; + transform.scale.x = 1.0; + transform.scale.y = 1.0; + transform.translation.x = 4.0; + transform.translation.y = 4.0; + transform.distance_mapping.lower = 4.0; + transform.distance_mapping.upper = 4.0; + if(msdf_generate_msdf(bitmap, shape, &transform) != MSDF_SUCCESS) { + return 1; + } + + // DO SOMETHING WITH THE GENERATED GLYPH BITMAP HERE.. + + // Make sure to free heap allocated resource when we're done + msdf_shape_free(shape); + msdf_bitmap_free(bitmap); + return 0; +} +``` + ## Using a multi-channel distance field Using a multi-channel distance field generated by this program is similarly simple to how a monochrome distance field is used. diff --git a/msdfgen_c.h b/msdfgen_c.h index 842bd4b..e4d81eb 100644 --- a/msdfgen_c.h +++ b/msdfgen_c.h @@ -96,11 +96,6 @@ typedef struct msdf_bounds { double t; } msdf_bounds_t; -typedef struct msdf_projection { - msdf_vector2_t scale; - msdf_vector2_t translation; -} msdf_projection_t; - typedef struct msdf_transform { msdf_vector2_t scale; msdf_vector2_t translation;