tetris: enable compilation with -prod; cleanup of font loading errors

pull/4449/head
Delyan Angelov 2020-04-16 19:44:15 +03:00
parent 182108faca
commit aed8370d87
2 changed files with 5 additions and 9 deletions

View File

@ -403,7 +403,6 @@ fn key_down(wnd voidptr, key, code, action, mods int) {
// global keys // global keys
match key { match key {
k_escape { k_escape {
eprintln('should close')
glfw.set_should_close(wnd, true) glfw.set_should_close(wnd, true)
} }
k_space { k_space {

View File

@ -169,7 +169,7 @@ pub fn new_context(cfg gg.Cfg) &FreeType {
scale := cfg.scale scale := cfg.scale
// Can only have text in ortho mode // Can only have text in ortho mode
if !cfg.use_ortho { if !cfg.use_ortho {
return &FreeType{} return &FreeType{face:0}
} }
width := cfg.width * scale width := cfg.width * scale
height := cfg.height * scale height := cfg.height * scale
@ -205,19 +205,16 @@ pub fn new_context(cfg gg.Cfg) &FreeType {
font_path = 'RobotoMono-Regular.ttf' font_path = 'RobotoMono-Regular.ttf'
} }
if !os.exists(font_path) { if !os.exists(font_path) {
exe_path := os.executable() font_path = os.resource_abs_path(font_path)
exe_dir := os.base_dir(exe_path)
font_path = '$exe_dir/$font_path'
} }
if !os.exists(font_path) { if !os.exists(font_path) {
println('failed to load $font_path') eprintln('freetype: font "$font_path" does not exist')
return 0 return 0
} }
println('Trying to load font from $font_path') face := &C.FT_FaceRec{glyph:0}
face := &C.FT_FaceRec{}
ret = int(C.FT_New_Face(ft, font_path.str, 0, &face)) ret = int(C.FT_New_Face(ft, font_path.str, 0, &face))
if ret != 0 { if ret != 0 {
println('freetype: failed to load the font (error=$ret)') eprintln('freetype: failed to load font (error=$ret) from path: $font_path')
exit(1) exit(1)
} }
// Set size to load glyphs as // Set size to load glyphs as