floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.92k stars 487 forks source link

[sokol_imgui] add the optional backend interface for font management #994

Closed Dvad closed 7 months ago

Dvad commented 7 months ago

As a happy sokol_imgui user, I am humbling proposing this PR. It splits the font texture creation in a API function and add a function for the font texture destruction. Those functions are considered optional function of the imgui backends.

For instance they are implemented for opengl3 on the main imgui repo:

https://github.com/ocornut/imgui/blob/659fb41d0a23efbb9ea6cf74f51ecae0a51575b5/backends/imgui_impl_opengl3.h#L39C1-L42C3

I find those functions are useful in two cases:

Does this proposal make sense?

floooh commented 7 months ago

Good idea! But I wonder if we should make the create-fonts function a bit more flexible by passing some data in.

For instance, it would be nice if I could replace this code block in the imgui-highdpi-sapp.c sample which sets up a TTF font texture with the new function:

https://github.com/floooh/sokol-samples/blob/6a03725117ce0175a45fa2d0c51ad3272c955cb5/sapp/imgui-highdpi-sapp.cc#L45-L67

...but as you can see here I'm also using a different sampler with LINEAR filtering:

https://github.com/floooh/sokol-samples/blob/6a03725117ce0175a45fa2d0c51ad3272c955cb5/sapp/imgui-highdpi-sapp.cc#L58-L63

Maybe simgui_create_fonts_texture() should allow to pass in optional parameters (like either a sampler object, or maybe better just a minimal set of sampler params, like min+mag filter?

Or do you solve this same problem currently in some other way? (since you are writing: "...when testing different fonts raterization config...").

Dvad commented 7 months ago

This is good suggestion!

I have not played with the sampler in my testing so far, the tool I linked allow to switch from freetype to stb_truetype with different parameters but the texture sampler was not one.

Dvad commented 7 months ago

I gave it a shot and submitted the sister PR: https://github.com/floooh/sokol-samples/pull/135

floooh commented 7 months ago

Ok, looking into this PR now.

floooh commented 7 months ago

And merged, many thanks! (also updated the changelog)