Beispiel #1
0
func main() {
	data, err := ioutil.ReadFile(filepath.Join("..", "ClearSans-Regular.ttf"))
	if err != nil {
		panic(err)
	}

	tmpBitmap := make([]byte, 512*512)
	cdata, err, _, tmpBitmap := truetype.BakeFontBitmap(data, 0, 32, tmpBitmap, 512, 512, 32, 96)
	var x, y float64
	b := 'b'
	x, q := truetype.GetBakedQuad(cdata, 512, 512, int(b)-32, x, y, true)

	fmt.Println(q)
}
Beispiel #2
0
func my_print(x, y float64, text string, ftex uint32, cdata []*truetype.BakedChar) {
	gl.Enable(gl.TEXTURE_2D)
	gl.BindTexture(gl.TEXTURE_2D, ftex)
	gl.Begin(gl.QUADS)
	for _, b := range text {
		if int(b) >= 32 && int(b) < 128 {
			var q *truetype.AlignedQuad
			x, q = truetype.GetBakedQuad(cdata, 512, 512, int(b)-32, x, y, true)
			gl.TexCoord2f(q.S0, q.T0)
			gl.Vertex2f(q.X0, q.Y0)
			gl.TexCoord2f(q.S1, q.T0)
			gl.Vertex2f(q.X1, q.Y0)
			gl.TexCoord2f(q.S1, q.T1)
			gl.Vertex2f(q.X1, q.Y1)
			gl.TexCoord2f(q.S0, q.T1)
			gl.Vertex2f(q.X0, q.Y1)
		}
	}
	gl.End()
}