MCPcopy Create free account
hub / github.com/SolarLune/masterplan / Texture

Method Texture

textrenderer.go:15–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13}
14
15func (glyph *Glyph) Texture() *sdl.Texture {
16
17 if glyph.Image.Texture != nil {
18 return glyph.Image.Texture
19 }
20
21 surf, err := globals.Font.RenderGlyphLCD(glyph.Rune, sdl.Color{255, 255, 255, 255}, sdl.Color{0, 0, 0, 255})
22
23 if err != nil {
24 // If there's an error rendering a glyph, we just assume it doesn't exist in the fontset
25 return nil
26 }
27
28 defer surf.Destroy()
29
30 newSurf, _ := surf.Convert(sdl.PIXELFORMAT_RGBA8888)
31
32 defer newSurf.Destroy()
33
34 // Here we manually draw the glyph to set the color to white, but modulate the alpha
35 // based on the color values
36
37 // Format seems to be AGBR, not RGBA?
38 formatDetails, err := newSurf.Format.Details()
39 if err != nil {
40 panic(err)
41 }
42
43 pixels := newSurf.Pixels()
44
45 for y := 0; y < int(surf.H); y++ {
46 for x := 0; x < int(surf.W); x++ {
47
48 i := int32(y)*newSurf.Pitch + int32(x)*int32(formatDetails.BytesPerPixel)
49
50 // This would be to get the color unmodified.
51 // return color.RGBA{pixels[i+3], pixels[i+2], pixels[i+1], pixels[i]}
52 newSurf.WritePixel(int32(x), int32(y), 0xff, 0xff, 0xff, pixels[i+3])
53 }
54 }
55
56 texture, err := globals.Renderer.CreateTextureFromSurface(newSurf)
57
58 if err != nil {
59 panic(err)
60 }
61 // texture.SetScaleMode(sdl.SCALEMODE_NEAREST)
62
63 glyph.Image.Texture = texture
64 glyph.Image.Size.X = float32(surf.W)
65 glyph.Image.Size.Y = float32(surf.H)
66
67 return texture
68
69}
70
71func (glyph *Glyph) Width() int32 {
72 if glyph.Texture() == nil {

Callers 6

WidthMethod · 0.95
HeightMethod · 0.95
GlyphMethod · 0.45
RenderTextMethod · 0.45
QuickRenderTextMethod · 0.45
DrawMethod · 0.45

Calls 1

DestroyMethod · 0.65

Tested by

no test coverage detected