@@ -347,11 +347,23 @@ func LoadTrueTypeFont(program uint32, r io.Reader, scale int32, dir Direction) (
347347 f .nextX = x
348348 f .nextY = y
349349
350+ // Generate texture
351+ gl .GenTextures (1 , & f .textureID )
352+ gl .ActiveTexture (gl .TEXTURE0 )
353+ gl .BindTexture (gl .TEXTURE_2D , f .textureID )
354+ gl .PixelStorei (gl .UNPACK_ALIGNMENT , 1 )
355+ gl .TexParameteri (gl .TEXTURE_2D , gl .TEXTURE_MIN_FILTER , gl .LINEAR )
356+ gl .TexParameteri (gl .TEXTURE_2D , gl .TEXTURE_MAG_FILTER , gl .LINEAR )
357+ gl .TexParameteri (gl .TEXTURE_2D , gl .TEXTURE_WRAP_S , gl .CLAMP_TO_EDGE )
358+ gl .TexParameteri (gl .TEXTURE_2D , gl .TEXTURE_WRAP_T , gl .CLAMP_TO_EDGE )
359+
360+ gl .TexImage2D (gl .TEXTURE_2D , 0 , gl .RGBA , int32 (atlas .Rect .Dx ()), int32 (atlas .Rect .Dy ()), 0 , gl .RGBA , gl .UNSIGNED_BYTE , gl .Ptr (atlas .Pix ))
361+ gl .BindTexture (gl .TEXTURE_2D , 0 )
362+
350363 // Configure VAO/VBO for texture quads
351364 genVertexArrays (1 , & f .vao )
352- bindVertexArray (f .vao )
353-
354365 gl .GenBuffers (1 , & f .vbo )
366+ bindVertexArray (f .vao )
355367 gl .BindBuffer (gl .ARRAY_BUFFER , f .vbo )
356368
357369 vertAttrib := uint32 (gl .GetAttribLocation (f .program , gl .Str ("vert\x00 " )))
@@ -362,18 +374,6 @@ func LoadTrueTypeFont(program uint32, r io.Reader, scale int32, dir Direction) (
362374 gl .EnableVertexAttribArray (texCoordAttrib )
363375 gl .VertexAttribPointerWithOffset (texCoordAttrib , 2 , gl .FLOAT , false , 4 * 4 , 2 * 4 )
364376
365- // Generate texture
366- gl .GenTextures (1 , & f .textureID )
367- gl .ActiveTexture (gl .TEXTURE0 )
368- gl .BindTexture (gl .TEXTURE_2D , f .textureID )
369- gl .PixelStorei (gl .UNPACK_ALIGNMENT , 1 )
370- gl .TexParameteri (gl .TEXTURE_2D , gl .TEXTURE_MIN_FILTER , gl .LINEAR )
371- gl .TexParameteri (gl .TEXTURE_2D , gl .TEXTURE_MAG_FILTER , gl .LINEAR )
372- gl .TexParameteri (gl .TEXTURE_2D , gl .TEXTURE_WRAP_S , gl .CLAMP_TO_EDGE )
373- gl .TexParameteri (gl .TEXTURE_2D , gl .TEXTURE_WRAP_T , gl .CLAMP_TO_EDGE )
374- gl .TexImage2D (gl .TEXTURE_2D , 0 , gl .RGBA , int32 (atlas .Rect .Dx ()), int32 (atlas .Rect .Dy ()), 0 , gl .RGBA , gl .UNSIGNED_BYTE , gl .Ptr (atlas .Pix ))
375- gl .BindTexture (gl .TEXTURE_2D , 0 )
376-
377377 gl .BindBuffer (gl .ARRAY_BUFFER , 0 )
378378 bindVertexArray (0 )
379379
@@ -417,7 +417,8 @@ func LoadFont(file string, scale int32, windowWidth int, windowHeight int) (*Fon
417417 gl .UseProgram (program )
418418
419419 // Set screen resolution
420- gl .Uniform2f (gl .GetUniformLocation (program , gl .Str ("resolution\x00 " )), float32 (windowWidth ), float32 (windowHeight ))
420+ resUniform := gl .GetUniformLocation (program , gl .Str ("resolution\x00 " ))
421+ gl .Uniform2f (resUniform , float32 (windowWidth ), float32 (windowHeight ))
421422
422423 atlasScale := int32 (float32 (scale ) / fontRenderScale )
423424 if atlasScale < 1 {
@@ -455,6 +456,15 @@ func (f *Font) Print(x, y float32, scale float32, text string) error {
455456 return nil
456457 }
457458
459+ // Setup blending mode
460+ gl .Enable (gl .BLEND )
461+ gl .BlendFunc (gl .SRC_ALPHA , gl .ONE_MINUS_SRC_ALPHA )
462+
463+ // Activate corresponding render state
464+ gl .UseProgram (f .program )
465+ // Set text color
466+ gl .Uniform4f (gl .GetUniformLocation (f .program , gl .Str ("textColor\x00 " )), f .color .R , f .color .G , f .color .B , f .color .A )
467+
458468 var coords []point
459469
460470 // Iterate through all glyphs in string
@@ -492,10 +502,6 @@ func (f *Font) Print(x, y float32, scale float32, text string) error {
492502 x += float32 ((ch .advance >> 6 )) * scale // Bitshift by 6 to get value in pixels (2^6 = 64 (divide amount of 1/64th pixels by 64 to get amount of pixels))
493503 }
494504
495- gl .UseProgram (f .program )
496- gl .Uniform4f (gl .GetUniformLocation (f .program , gl .Str ("textColor\x00 " )), f .color .R , f .color .G , f .color .B , f .color .A )
497- gl .Enable (gl .BLEND )
498- gl .BlendFunc (gl .SRC_ALPHA , gl .ONE_MINUS_SRC_ALPHA )
499505 bindVertexArray (f .vao )
500506 gl .ActiveTexture (gl .TEXTURE0 )
501507 gl .BindTexture (gl .TEXTURE_2D , f .textureID )
0 commit comments