-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[reve]Draw text with SDF fonts in screen or world coordinates #15812
[reve]Draw text with SDF fonts in screen or world coordinates #15812
Conversation
This change is related to development in RenderCore UL-FRI-LGM/RenderCore#20 |
Test Results 13 files 13 suites 3d 3h 5m 0s ⏱️ Results for commit 6dcb57a. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have several questions:
-
Do we need to include all these fonts into ROOT repository? Font files are big and used only via random generator in tutorial.
-
How to deal with other fonts? Maybe one can include one default font in
ui5/eve7/
folder, one or two fonts as examples in tutorials and provide recipe where other fonts can be found? -
If I understand correct,
REveText
rendering will be only supported with RenderCore? That about three.js? Beside fonts support it is easy to implement text rendering there. -
Is it possible to support other font formats - like TTF or OTF? ROOT already includes such fonts, is it an option?
Sergey, all good questions, thank you :)
No, we can remove most of them, rebase and force-push to the branch.
Yes, we could do that. Font textures and metrics files are generated from TTF via https://github.com/osschar/sdf_atlas. It's a small tool, easy to build on linux -- so we could provide instructions for this and also a catalog/web-site with a bunch of pre-generated fonts.
Yes, I know ... they have a monster implementation(s) of fonts. Seeing that I went looking for something super simple and still good looking :) Now, this is a bit unfortunate ... but I don't think I have the bandwidth to keep Three fully supported. Also, the low-level, renderer- and shader-level support we are getting from RenderCore (in particular, for picking & rendering of instanced objects and the upcoming spline-based line rendering) is making it possible to support features and performance optimizations that I do not think would be doable in Three with the time budget we all have and the level of changes we can do in core Three (zero, unless we can hack over it locally).
This would be nice, sdf_atlas could be incorporated into root (it requires minimal GL support which we already have) -- and one could then generate the missing SDF fonts during the startup of a demo/application. License is free to use in whatever way, just keep the copyright notice. But it only supports TTF, not OTF. Perhaps we should look for another library ... or at least a new TTF/OTF parser -- I don't know much about low-level font things so this maybe already exists in root?. I understand this is not all perfect -- but at this point our priority is to get something usable in for the existing REve applications. |
Then I propose to reduce number of fonts - one or two for now. And think how one can allow to use external fonts - in this PR or may be later. |
@linev I will add today the change to reduce the number of fonts. Just Serif and Mono Space type fonts in only regular style (no italic and bold). |
f048507
to
0c9b119
Compare
@linev I have pushed changes. I have rebased to master and squashed commits to reduce the load on git repository. There are some pending changes from Matevz. Please wait for his commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change still required
|
||
protected: | ||
std::string fText {"<no-text>"}; | ||
std::string fFont {"LiberationSans-Regular"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be default font name should refer to existing font?
0c9b119
to
fcb3b3f
Compare
OK, I force-pushed a new version, now there are no SDF fonts in the repo -- but I have added two ttf fonts that have all the accented and greek characters. The creator of sdf font stuff is in There is only one thing I couldn't figure out -- how to link against libpng ... so I just added |
Sergey, semi-related, have been running with valgrind (root supressions on), and this came up:
|
It is inside |
Yeah, they probably do some quirky simd stuff in there :) I realized yesterday that the stuff for creation of sdf textures always puts them in $ROOTSYS/ui5/eve7/ ... which will not be writable for experiment-wide / cvmfs installs. Would it be possible to do something like this:
|
Not so simple. Sometime ROOT uses system-wide You have to ensure that your code not linked with
Because you may need to use custom include directories. See here |
OK, I've moved png-writer to asimage. All that remains from my side is to figure out how to handle the case when $ROOTSYS is not writable -- see my comment above: #15812 (comment) |
One can try to load fonts from current directory. Feature available only in master since 2 days - please rebase your code |
Hmmh, but then I'd need to stream path information with every REveText object, now only the font name is streamed. It is indeed a reasonable thing to check if the font files exist before object's json is sent over to the client --- but creating a font during the streaming traversal would be pushing it a bit. Is it possible to register custom prefixes and callbacks from REveManager (via RWebWindow) so they can be handled when requests come in? Like: http://server/sdf-fonts/ I went through the code a bit (but clearly do not have the full picture) ... one way would be to add THttpServer::fActiveLocations, where instead of replacement string one provides a lambda [](TString& prefix, TString& reminder, THttpRequest& req, THttpServer &srv) so one can then do appropriate lookup in the callback, potentially generating the font, and then calling srv->SendFile() (or sending back the default font, if the desired one can not be found/generated). I think this functionality could be useful for other cases in REve, where semi-static data needs to be provided. The font-generation code in REveText invokes TGL generator through the interpreter now, via gROOT->ProcessLine(), to avoid dependency of REve on RGL. Is this OK to do from a request handler thread or should cross-thread request to the main thread be made (and request told to try again in N seconds)? |
In my mind, procedure can be:
|
Hmmh, so you don't want to give me an active directory? :) |
For the moment there is no direct support of such feature with In my mind, solution with direct access of font files via You always can implement active directory - but does it necessary with fonts? |
OK ... done. I have used THttpServer::AddLocation() to register sdf-fonts/ to either $ROOTSYS/ui5/eve7/sdf-fonts or ./sdf-fonts. One can also specify the location manually through REveText::SetSdfFontDir(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add missing docu and adjust LinkDef.h
file in graf3d/gl/
And of course problem with png.h
should be solved.
graf2d/asimage/src/TASPngWriter.cxx
Outdated
@@ -0,0 +1,49 @@ | |||
#include "TASPngWriter.h" | |||
|
|||
#include <png.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On several platforms png.h
is not found!
This peace of code should be placed directly in libAfterImage
- only it has proper configuration for libpng
usage. TASImage
is just C++ decoration around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if one does not use the builtin libAfterImage? This seems to be happening with the CI builds :(
I've moved the png low-level code into libAfterImage, added docs, and added the two classes (TGLSdfFontMaker and TASPngWriter) into appropriate link-defs. |
Hmmh, it seems CI builds can not find the new file from graf2d/asimage/libAfterImage/:
I had to do The F39 CI build log only has this:
while mine has (grepped out AFTERIMAGE parts):
|
Oh, I see now ... builtin_afterimage is not used in the CI builds -- and might or might not be used in an arbitrary build. That means my changes can not go into libAfterImage after all. |
Vincenzo told me Something still goes wrong on macs but there is not much info in the CI log ... it says there is some more in the actual log file. |
I don't know how or why but AFTERIMAGE build did not run for windows and mac. |
Ah, checked on Alja's mac ... me R an idiot ... forgot to include config.h :) |
Grate! Now it compiles! Last question. Why you include Maybe one just can create special small library within |
Yay, thanks for your help Sergey! I put Alja and I have checked it on mac and it works ok. There was an interesting side-story where libRGL got linked against /usr/X11R6/lib/libGL.so (presumably from an old install of XQuartz and libX11 stuff from homebrew -- it worked after we wiped both of those) instead of Apple's OpenGL framework. I still want to test this on Windows, then I'll rebase and force-push so there's a single commit. |
Ok, if You may add simple gtest-based code directly for |
I want to see it :) Especially after the tricky issue on mac. It seemed to run fine but the font texture was just noise. |
Yay, now it works on windows, too :) |
e3c27fb
to
938467c
Compare
Contains contributions from Waad, Alja and Matevz. Squashed to avoid adding of extra files in the repo (some committed by mistake) and to avoid numerous commits. * Waad: initial implementation & tuning. * Alja: integration with REve. * Matevz: final cleanup, loading of fonts & font metrics. Mac and Windows fixes. Full set of initial development commits is available from: https://github.com/alja/root/tree/waa-master-2024 Commits to get things working on Mac/Windows and libAfterImage/libpng: https://github.com/alja/root/tree/waad-revetext-overlay-master-6.33-rb1-final Related PR in RenderCore: UL-FRI-LGM/RenderCore#20 Demo: tutorials/eve7/texts.C Update RenderCore version to 1.5. Location of SDF font and metrics files: When REveText::AssertSdfFont() is called for the first time it chooses a writable location in eiter $ROOTSYS/ui5/eve7/sdf-fonts or a ./sdf-fonts in the current directory. Alternatively REveText::SetSdfFontDir() can be called beforehand to manually specify the desired location.
938467c
to
6dcb57a
Compare
OK, all done ... if everything passes, this ready to go. What a ride :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After many iterations code is working now as intended.
Grate job!
Thank you for your guidance Sergey! I'm glad this got done right :) |
This Pull request:
Add functionality to draw Scale Distance Field Fonts in the screen or world coordinates.
Example:
/tutorials/eve7/texts.C