forked from 4ydx/glmenu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu_texture.go
83 lines (61 loc) · 1.92 KB
/
menu_texture.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2012 The go-gl Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package glmenu
import (
"github.com/go-gl/gl/v4.1-core/gl"
"github.com/go-gl/mathgl/mgl32"
"image"
)
var menuTextureVertexShaderSource string = `
#version 330
uniform mat4 orthographic_matrix;
uniform vec2 final_position;
in vec4 centered_position;
in vec2 uv;
out vec2 fragment_uv;
void main() {
fragment_uv = uv;
vec4 placed = orthographic_matrix * centered_position;
gl_Position = vec4(placed.x + final_position.x, placed.y + final_position.y, placed.z, placed.w);
}
` + "\x00"
var menuTextureFragmentShaderSource string = `
#version 330
uniform sampler2D fragment_texture;
uniform float text_lowerbound;
in vec2 fragment_uv;
out vec4 fragment_color;
void main() {
vec4 color = texture(fragment_texture, fragment_uv);
fragment_color = color;
}
` + "\x00"
type MenuTexture struct {
Menu *Menu
textureID uint32 // Holds the glyph texture id.
program uint32 // program compiled from shaders
// attributes
centeredPositionAttribute uint32 // vertex centered_position required for scaling around the orthographic projections center
uvAttribute uint32 // texture position
// The final screen position post-scaling
finalPositionUniform int32
// Position of the shaders fragment texture variable
fragmentTextureUniform int32
Dimensions mgl32.Vec2
orthographicMatrixUniform int32
OrthographicMatrix mgl32.Mat4
textureWidth float32
textureHeight float32
WindowWidth float32
WindowHeight float32
Image *image.NRGBA
}
func (mt *MenuTexture) ResizeWindow(width float32, height float32) {
mt.WindowWidth = width
mt.WindowHeight = height
mt.OrthographicMatrix = mgl32.Ortho2D(-mt.WindowWidth/2, mt.WindowWidth/2, -mt.WindowHeight/2, mt.WindowHeight/2)
}
func (mt *MenuTexture) Release() {
gl.DeleteTextures(1, &mt.textureID)
}