MCPcopy Create free account
hub / github.com/EngoEngine/engo / Setup

Method Setup

common/render_shaders_text.go:35–115  ·  view source on GitHub ↗
(w *ecs.World)

Source from the content-addressed store, hash-verified

33}
34
35func (l *textShader) Setup(w *ecs.World) error {
36 var err error
37 l.program, err = LoadShader(`
38attribute vec2 in_Position;
39attribute vec2 in_TexCoords;
40attribute vec4 in_Color;
41
42uniform mat3 matrixProjection;
43uniform mat3 matrixView;
44uniform mat3 matrixModel;
45
46varying vec4 var_Color;
47varying vec2 var_TexCoords;
48
49void main() {
50 var_Color = in_Color;
51 var_TexCoords = in_TexCoords;
52
53 vec3 matr = matrixProjection * matrixView * matrixModel * vec3(in_Position, 1.0);
54 gl_Position = vec4(matr.xy, 0, matr.z);
55}
56`, `
57#ifdef GL_ES
58#define LOWP lowp
59precision mediump float;
60#else
61#define LOWP
62#endif
63
64varying vec4 var_Color;
65varying vec2 var_TexCoords;
66
67uniform sampler2D uf_Texture;
68
69void main (void) {
70 gl_FragColor = var_Color * texture2D(uf_Texture, var_TexCoords);
71}`)
72
73 if err != nil {
74 return err
75 }
76
77 // Create and populate indices buffer
78 l.indicesRectangles = make([]uint16, 6*bufferSize)
79 for i, j := 0, 0; i < bufferSize*6; i, j = i+6, j+4 {
80 l.indicesRectangles[i+0] = uint16(j + 0)
81 l.indicesRectangles[i+1] = uint16(j + 1)
82 l.indicesRectangles[i+2] = uint16(j + 2)
83 l.indicesRectangles[i+3] = uint16(j + 0)
84 l.indicesRectangles[i+4] = uint16(j + 2)
85 l.indicesRectangles[i+5] = uint16(j + 3)
86 }
87 l.indicesRectanglesVBO = engo.Gl.CreateBuffer()
88 engo.Gl.BindBuffer(engo.Gl.ELEMENT_ARRAY_BUFFER, l.indicesRectanglesVBO)
89 engo.Gl.BufferData(engo.Gl.ELEMENT_ARRAY_BUFFER, l.indicesRectangles, engo.Gl.STATIC_DRAW)
90
91 // Define things that should be read from the texture buffer
92 l.inPosition = engo.Gl.GetAttribLocation(l.program, "in_Position")

Callers

nothing calls this directly

Calls 1

LoadShaderFunction · 0.85

Tested by

no test coverage detected