-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add a font supporting more characters #9
Conversation
Please have all information in the first post (= merge your second post into the first post and delete the second post). Why isn't there a screenshot of the text in action? One font is probably fine for now. It's more important that the exact details used for the fonts creation are documented (e.g. have the fontmap, list of fonts [possibly with download link, so preferably fonts which are easy to license], font size, texture size etc. in the wiki) Also see andryblack/fontbuilder#19 and I haven't reviewed the code yet. I'll probably do so during the next couple of days. Please remind me if it doesn't happen :) |
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.
Why is Arial Black still in the codebase, if Liberation Mono does its job and more?
main.cpp
Outdated
@@ -66,7 +66,8 @@ int main(int argc, char* argv[]) { | |||
|
|||
std::shared_ptr<Texture> texture = std::make_shared<Texture>("data/font/main"); | |||
|
|||
std::shared_ptr<Text> text = std::make_shared<Text>("data/font/arial_black_regular_65"); | |||
//std::shared_ptr<Text> text = std::make_shared<Text>("data/font/arial_black_regular_65"); |
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.
Why was this commented out instead of edited directly?
text.cpp
Outdated
@@ -91,7 +91,7 @@ class Text { | |||
} | |||
|
|||
auto isMatchingSymbol = [&](const Symbol& symbol) -> bool { | |||
return symbol.id == static_cast<uint32_t>(c); | |||
return symbol.id == static_cast<unsigned char>(c); |
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 purpose does changing the type have?
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.
Yes. Also if the type is unsigned here it should probably also be like that in the zengl struct (which is currently int32_t
).
However, I don't know how unicode works in C++ and if zengl files even use unicode (which I kind of hope).
main.cpp
Outdated
@@ -466,7 +467,17 @@ int main(int argc, char* argv[]) { | |||
|
|||
// Test text | |||
glColor3f(0.1f, 0.2f, 0.5f); | |||
text->draw(std::string("boats: ") + std::to_string(boats.size()) + std::string("\nsparks: ") + std::to_string(sparks.size()) + std::string("\nus/F: ") + std::to_string(uspf.count())); | |||
|
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 see ninja refactoring. 👀
If you're going to ninja @JayFoxRox, at least clean up your whitespace. 😉
text.cpp
Outdated
@@ -91,7 +91,7 @@ class Text { | |||
} | |||
|
|||
auto isMatchingSymbol = [&](const Symbol& symbol) -> bool { | |||
return symbol.id == static_cast<uint32_t>(c); | |||
return symbol.id == static_cast<unsigned char>(c); |
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.
Whitespace change not necessary
main.cpp
Outdated
std::string("\n\xB5/F: ") + //'\xB5' being the micro symbol | ||
std::to_string(uspf.count()); | ||
text->draw(debuggingText); | ||
//'\xB5' = µ = micro sign (in case your editor's font can't handle it) |
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.
nit: Ideally this should have been in a variable: char symbolMicro = '\xB5'; or something.
text.cpp
Outdated
return symbol.id == static_cast<unsigned char>(c); | ||
/* c is probably char_t here, so ... | ||
casting first to unsigned char is necessary, because if we | ||
cast to int32_t directly, the machine bit extends, meaning |
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.
*sign extends
text.cpp
Outdated
@@ -91,7 +91,16 @@ class Text { | |||
} | |||
|
|||
auto isMatchingSymbol = [&](const Symbol& symbol) -> bool { | |||
return symbol.id == static_cast<unsigned char>(c); | |||
/* c is probably char_t here, so ... |
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.
-probably
text.cpp
Outdated
that the match would fail because of the type's sign. | ||
we could also do uint32_t, since I think zengl supports utf-32 | ||
but I don't think that's necessary because we are not support | ||
unicode anyway (i.e. we never go beyond 0xFF) |
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.
depending on what zengl uses we should fix the zengl struct and also this cast. I stole my zengl struct from the font tool source and changed some datatypes to stdint iirc.
Only some smaller issues left, I will test this later and hopefully we can integrate it in a couple of hours |
text.cpp
Outdated
@@ -91,7 +91,16 @@ class Text { | |||
} | |||
|
|||
auto isMatchingSymbol = [&](const Symbol& symbol) -> bool { | |||
return symbol.id == static_cast<uint32_t>(c); | |||
/* c is char_t here, so ... |
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.
isn't it just a char
?
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.
forgot about this one? @doTulio
It's a nit, so if you don't change it I'll just merge anyway in about 10 minutes or so.
text.cpp
Outdated
/* c is char_t here, so ... | ||
casting first to unsigned char is necessary, because if we | ||
cast to int32_t directly, the machine sign extends, meaning | ||
that the match would fail because of the type's sign. |
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.
-type's
text.cpp
Outdated
unicode anyway (i.e. we never go beyond 0xFF) | ||
*/ | ||
unsigned char chUnsigned = static_cast<unsigned char>(c); | ||
return symbol.id == static_cast<int32_t>(chUnsigned); |
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.
symbol_id is uint32_t, so this should be uint32_t too
text.cpp
Outdated
casting first to unsigned char is necessary, because if we | ||
cast to int32_t directly, the machine sign extends, meaning | ||
that the match would fail because of the type's sign. | ||
we could also do uint32_t, since I think zengl supports utf-32 |
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.
We already do a 32 bit conversion here, so I'm not sure why you say "we could" - we already do. (also we can't - c is a char and we won't change that. So information has already been lost)
Okay, please fix what's mentioned in the remaining comments, squash up and make sure to add the character map to the wiki. Reviewed and tested: LGTM aside from what's mentioned |
- Deleted extra font files. We need only one. Later it can be decided whether we use a more appropriate, prettier, gamelier looking font. - Generated Sans Bold. Bold just looks better the way font rendering currently is done. - Improved casting and explanation in text.cpp.
Thanks! (Please add the charmap and other settings you used + a link to the font (as ttf or w/e) to the wiki) |
Changed the font from Arial to Liberation Sans, which is licensed under the SIL Open Font License.
The tool fontbuilder was used to generate the following character map from the aforementioned font.
This is the whole of printable Extended ASCII.
Also, when matching for the character's id, the type has been changed to unsigned so that charcodes larger than
0x0F
could be used.