Comments (2)
I have two examples where a custom font is used, both have the font data embedded in the program though, not loading it from a file (as that wouldn't work in browsers).
See here for an example that just replaces the default font with a TTF font:
sokol-samples/sapp/imgui-highdpi-sapp.cc
Lines 35 to 64 in 6e5d16b
And this example uses the default font, but adds an additional icon font:
https://github.com/floooh/v6502r/blob/f2185ca6ccf0ce18ea3258e8ba163027abeefa0d/src/ui.cc#L46-L87
You need to set .no_default_font = true
when calling simgui_setup(), so that the font isn't already constructed in the call to simgui_setup(), instead this must be done completely by your own code.
So the important steps are:
- call simgui_setup with
.no_default_font
- add your own fonts to ImGui's GetIO().Fonts object
- let ImGui rasterize the font, and get the pixel data and dimensions (
sokol-samples/sapp/imgui-highdpi-sapp.cc
Line 53 in 6e5d16b
- create a sokol-gfx texture from that data and use the returned
sg_image
handle-id as ImGui's TexID:sokol-samples/sapp/imgui-highdpi-sapp.cc
Lines 54 to 64 in 6e5d16b
I haven't used PushFont/PopFont so far though, but with the procedure above to create the custom font, this should work too.
from sokol-samples.
It works, thank you very much @floooh ! Did not know that I need to create an atlas for it to work:)
from sokol-samples.
Related Issues (20)
- Sapp targets on macos failed to load resources HOT 4
- Build fails on Linux ARM64 (sokol-shdc not supported on this platform) HOT 4
- emscripten build error HOT 1
- Shadow contact issue in sample shadow-sapp.c HOT 1
- How to build without a build system.. with 3rd party libs HOT 4
- droptest-sapp segfaulting on drop (ImGuiListClipper related) HOT 1
- how render sg_image in qt window or widget, thx HOT 1
- Incorrect subsystem on windows with VS2022 HOT 18
- running build on any config results in cmake error looking for default directory which doesn't exist HOT 3
- Suggestion: Show labels in validation error messages HOT 1
- Fail to build on macos sonoma HOT 3
- Need to have a make.exe in the PATH when building android samples under Windows HOT 1
- Example of multiple VBOs HOT 1
- RasPi 4 sample compile error HOT 3
- Can't render to float on ios... number of extensions wrongly reported as zero HOT 1
- Fails to clone dependency `fips-imgui-dock` HOT 2
- Samples numbered HOT 1
- Unable to build the samples using fips on my Mac HOT 2
- [Reminder] Provide dummy launch images for iOS. HOT 2
- [Idea] 360 Video
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sokol-samples.