gen2brain / raylib-go

Go bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.
zlib License
1.55k stars 159 forks source link

How to show CJK chars or fonts in raylib-go #413

Open lnxyz opened 5 days ago

lnxyz commented 5 days ago

code example: how to show the cjk chars ?

package main

import (
    "fmt"

    gui "github.com/gen2brain/raylib-go/raygui"
    rl "github.com/gen2brain/raylib-go/raylib"
)

func main() {
    rl.InitWindow(600, 320, "raygui - button 世界你好!")

    rl.SetTargetFPS(60)

    var button bool

    var font = rl.LoadFontEx("fonts/SimSun.ttf", 96, nil)
    gui.SetFont(font)

    for !rl.WindowShouldClose() {
        rl.BeginDrawing()

        rl.ClearBackground(rl.Black)

        button = gui.Button(rl.NewRectangle(50, 150, 100, 40), "Click, 世界你好!")
        if button {
            fmt.Println("Clicked on button")
        }

        rl.EndDrawing()
    }

    rl.CloseWindow()
}

The CJK characters on this button are displayed as ???.

JupiterRider commented 4 days ago

Hey @lnxyz, you need to load the characters (runes) you want to display: rl.LoadFontEx("fonts/SimSun.ttf", 96, []rune("Click, 世界你好!"))

Not that you shouldn't load all tens of thousands CJK characters. Only use the ones you need.

(Reference: https://github.com/gen2brain/raylib-go/issues/233 and https://github.com/raysan5/raylib/discussions/2499)