Skip to content
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

Merged
merged 1 commit into from
Apr 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed data/font/andale_mono_regular_48.png
Binary file not shown.
Binary file removed data/font/andale_mono_regular_48.zfi
Binary file not shown.
Binary file removed data/font/arial_black_regular_65.png
Binary file not shown.
Binary file removed data/font/arial_black_regular_65.zfi
Binary file not shown.
Binary file added data/font/liberation_sans_bold_65.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/font/liberation_sans_bold_65.zfi
Binary file not shown.
5 changes: 3 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ 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/liberation_sans_bold_65");

std::string meshPath = "data/mesh/cube";
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
Expand Down Expand Up @@ -466,7 +466,8 @@ 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()));
char symbolMicro = '\xB5';
text->draw(std::string("boats: ") + std::to_string(boats.size()) + std::string("\nsparks: ") + std::to_string(sparks.size()) + "\n" + symbolMicro + "/F: " + std::to_string(uspf.count()));

glPopMatrix();
#endif
Expand Down
10 changes: 8 additions & 2 deletions text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Text {
};

struct __attribute__((packed)) Symbol {
int32_t id;
uint32_t id;
int32_t page;
uint8_t width;
uint8_t height;
Expand Down Expand Up @@ -91,7 +91,13 @@ class Text {
}

auto isMatchingSymbol = [&](const Symbol& symbol) -> bool {
return symbol.id == static_cast<uint32_t>(c);
/*
casting first to unsigned char is necessary, because if we
cast to uint32_t directly, the machine sign extends, meaning
that the match would fail because of the sign.
*/
unsigned char chUnsigned = static_cast<unsigned char>(c);
return symbol.id == static_cast<uint32_t>(chUnsigned);
};
const auto& it = std::find_if(symbols.begin(), symbols.end(), isMatchingSymbol);
assert(it != symbols.end());
Expand Down