glfont
1.0.0
Name : glfont Library
Author : Noah Shibley, http://socialhardware.net
Date : June 16th 2016
Notes : A modern opengl text rendering library for golang
Dependencies: freetype, go-gl, glfw
func LoadFont ( file string , scale int32 , windowWidth int , windowHeight int ) ( * Font , error )로드 폰트는 주어진 척도로 지정된 글꼴을로드합니다. 기본 문자 세트는 ASCII (CodePoints 32 ~ 127)입니다.
func LoadTrueTypeFont ( program uint32 , r io. Reader , scale int32 , low , high rune , dir Direction ) ( * Font , error )LoadTruetyPefont는 TTF 파일 Gylph를 기반으로 버퍼와 텍스처를 빌드합니다.
func LoadFontBytes ( buf [] byte , scale int32 , windowWidth int , windowHeight int ) ( * Font , error ) { loadfontbytes는 주어진 척도에서 바이트 ( goregulat.TTF , https://pkg.go.dev/golang.org/x/image/font/gofont/goregular)에서 직접 글꼴을로드합니다. 기본 문자 세트는 ASCII (CodePoints 32 ~ 127)입니다.
func ( f * Font ) GenerateGlyphs ( low , high rune ) errorGenerateLyphs는 비 ASCII 유니 코드 코드 포인트에 대한 추가 글리프를 구축합니다.
func ( f * Font ) Printf ( x , y float32 , scale float32 , fs string , argv ... interface {}) errorprintf는 문자열을 화면에 그려, printf와 같은 인수 목록을 가져옵니다.
func ( f * Font ) SetColor ( red float32 , green float32 , blue float32 , alpha float32 )setColor는 텍스트를 그릴 때 사용할 텍스트 색상을 설정할 수 있습니다.
func ( f * Font ) UpdateResolution ( windowWidth int , windowHeight int )뷰포트가 조정 될 때는 업데이트 레스 분해물이 필요합니다
func ( f * Font ) Width ( scale float32 , fs string , argv ... interface {}) float32너비는 텍스트 조각의 너비를 픽셀로 반환합니다.
package main
import (
"fmt"
"log"
"runtime"
"github.com/go-gl/gl/all-core/gl"
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/nullboundary/glfont"
)
const windowWidth = 1920
const windowHeight = 1080
func init () {
runtime . LockOSThread ()
}
func main () {
if err := glfw . Init (); err != nil {
log . Fatalln ( "failed to initialize glfw:" , err )
}
defer glfw . Terminate ()
glfw . WindowHint ( glfw . Resizable , glfw . True )
glfw . WindowHint ( glfw . ContextVersionMajor , 3 )
glfw . WindowHint ( glfw . ContextVersionMinor , 2 )
glfw . WindowHint ( glfw . OpenGLProfile , glfw . OpenGLCoreProfile )
glfw . WindowHint ( glfw . OpenGLForwardCompatible , glfw . True )
window , _ := glfw . CreateWindow ( int ( windowWidth ), int ( windowHeight ), "glfontExample" , glfw . GetPrimaryMonitor (), nil )
window . MakeContextCurrent ()
glfw . SwapInterval ( 1 )
if err := gl . Init (); err != nil {
panic ( err )
}
//load font (fontfile, font scale, window width, window height
font , err := glfont . LoadFont ( "Roboto-Light.ttf" , int32 ( 52 ), windowWidth , windowHeight )
if err != nil {
log . Panicf ( "LoadFont: %v" , err )
}
gl . Enable ( gl . DEPTH_TEST )
gl . DepthFunc ( gl . LESS )
gl . ClearColor ( 0.0 , 0.0 , 0.0 , 0.0 )
for ! window . ShouldClose () {
gl . Clear ( gl . COLOR_BUFFER_BIT | gl . DEPTH_BUFFER_BIT )
//set color and draw text
font . SetColor ( 1.0 , 1.0 , 1.0 , 1.0 ) //r,g,b,a font color
font . Printf ( 100 , 100 , 1.0 , "Lorem ipsum dolor sit amet, consectetur adipiscing elit." ) //x,y,scale,string,printf args
window . SwapBuffers ()
glfw . PollEvents ()
}
}