Anut-py / h-raylib

Haskell bindings for raylib
https://hackage.haskell.org/package/h-raylib
Apache License 2.0
84 stars 14 forks source link

loadFontEx does not appear to work #56

Closed k355l3r-5yndr0m3 closed 4 months ago

k355l3r-5yndr0m3 commented 4 months ago

font loaded by loadFontEx is not visible on screen.

module Main where
import Raylib.Core
import Raylib.Core.Text

import Raylib.Util
import Raylib.Util.Colors

import Raylib.Types

main :: IO ()
main = do
  window <- initWindow 100 100 ""

  font <- loadFontEx "font.ttf" 28 [] 0 window

  whileWindowOpen0 $ do
    beginDrawing
    clearBackground white
    drawTextEx font "Testing" (Vector2 0 0) 28 0 black
    endDrawing

  unloadFont font window

  closeWindow window
Anut-py commented 4 months ago

I think this is happening because the font is not loaded properly. ./font.ttf is taken relative to where you call the executable from (e.g. if you are in project-directory and use cabal run, then it will look for project-directory/font.ttf). If you do changeDirectory =<< getApplicationDirectory after initWindow, it will search for files relative to the executable path.

In a real project you should use the data-files field in the cabal file to list any assets you will use, then access them using the instructions here. This is probably the most convenient solution.

k355l3r-5yndr0m3 commented 4 months ago

No, I tried this first using data-files then when I did not get anything on screen I tried absolute path, still nothing.

Anut-py commented 4 months ago

Take a look at the custom-font-text example and compare it to your code. Can you share your cabal file and project structure?

k355l3r-5yndr0m3 commented 4 months ago

This issue is specific to loadFontEx. If I change to use loadFont then it render just fine, although I do not have fine control over the font. My cabal file and project structure is irrelevant as using an absolute path still have the same result. If I change the path to something that does not exist, raylib will print an error and loadFontEx will return the default font which is visible.

Anut-py commented 4 months ago

Fixed in 5.5.0.0, use font <- managed window $ loadFontEx "font.ttf" 28 Nothing. Reopen if there are any problems.