Chlumsky / msdfgen

Multi-channel signed distance field generator
MIT License
3.9k stars 404 forks source link

Implement C-API & FreeType runtime loader to allow other languages to interop with the library #200

Closed KitsuneAlex closed 3 months ago

KitsuneAlex commented 4 months ago

As the title suggests, i went ahead and implemented a C-API wrapper for msdfgen-core and the FreeType extensions. Originally this wrapper was supposed to be a part of my upcoming LWJGL PR for adding msdfgen bindings, but i thought the project itself could maybe use it even better :)

UPDATE: Another thing i implemented out of personnal necessity is a runtime loader for FreeType which doesn't require linking msdfgen against it statically and offers an API to set a custom function load callback.

Also adds a reasonable default configuration for clang-format and clang-tidy, so IDEs like CLion don't permanently mess up the code formatting.

I am open for any improvement suggestions or nitpicks. Cheers.

Type1J commented 4 months ago

I haven't looked at the code, but a C API would be nice.

KitsuneAlex commented 4 months ago

I haven't looked at the code, but a C API would be nice.

Any specific features you need/expect from a C-API beyond the core capabilities? ^^ Might as well add them while i'm at it if you have any suggestions.

zmarlon commented 4 months ago

Looks good!

DietrichPaul commented 4 months ago

We have been looking for a C API fork for a long time, implementation would be great. The code is clean.

lunarydess commented 4 months ago

Looks clean :)

KitsuneAlex commented 4 months ago

There is a rough, but working implementation draft for LWJGL now which is based on this PR.

KitsuneAlex commented 4 months ago

I think i'm quite happy with how this looks now @Chlumsky :)

KitsuneAlex commented 4 months ago

Not sure about the header/source files names tbh, i think you might prefer msdfgen-c over msdfgen_c judging by your other files 😄

KitsuneAlex commented 4 months ago

Messed up title of the last commit but you might wanna squash anyways if you want to merge.

KitsuneAlex commented 4 months ago

Gonna leave this as-is for now until you have time to take a look. But i found another inconsistency in my API draft i might wanna address.

KitsuneAlex commented 4 months ago

I removed the allocator API for now as it would require a larger refactor to implement properly throughout the codeebasee. I also added support for the FreeType font import API with a fitting msdfgen-ext-c.h :) Just needs some documentation.

KitsuneAlex commented 4 months ago

Tested implementation in LWJGL using a custom runtime loader. Works like a charm.

Chlumsky commented 3 months ago

Sorry, but if I merged this, I would have to support it for eternity, even though I don't use it, so I think it will be better if you keep it updated in your own fork.

KitsuneAlex commented 3 months ago

No hard feelings, i'll keep maintaining a fork. Just thought you might wanna add it to your own project.