Remove unused typedef from API header & add simple example to README

This commit is contained in:
KitsuneAlex 2024-05-02 14:15:57 +02:00
parent df74428a86
commit 021fc8af79
No known key found for this signature in database
GPG Key ID: 6B0CE864BB69B7D0
2 changed files with 42 additions and 8 deletions

View File

@ -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 <msdfgen.h>
#include <msdfgen-ext.h>
using namespace msdfgen;
@ -144,6 +144,45 @@ int main() {
```
**Example using the C API:**
```c++
#include <msdfgen_c.h>
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.

View File

@ -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;