summaryrefslogtreecommitdiff
path: root/graphics.go
diff options
context:
space:
mode:
Diffstat (limited to 'graphics.go')
-rw-r--r--graphics.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/graphics.go b/graphics.go
index 91edcce..a5c7373 100644
--- a/graphics.go
+++ b/graphics.go
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/go-gl/gl/v4.6-core/gl"
+ "github.com/go-gl/mathgl/mgl32"
)
var (
@@ -23,9 +24,13 @@ const (
// vertex shader to draw points
VERTEX_SHADER = `
#version 410
+
+ uniform mat4 trafo;
+
in vec3 vp;
+
void main() {
- gl_Position = vec4(vp, 1.0);
+ gl_Position = trafo * vec4(vp, 1.0);
}
` + "\x00"
@@ -45,6 +50,8 @@ type Graphics struct {
vertexShader uint32
fragmentShader uint32
program uint32
+ trafo mgl32.Mat4
+ trafoUniform int32
}
func newGraphics() Graphics {
@@ -79,6 +86,11 @@ func newGraphics() Graphics {
// create VAO
graphics.vao = makeVao(triangle)
+ // create transformation matrix
+ graphics.trafo = mgl32.HomogRotate3D(float32(1.57), mgl32.Vec3{0, 1, 1}) // mgl32.Ident4()
+ graphics.trafoUniform = gl.GetUniformLocation(graphics.program, gl.Str("trafo\x00"))
+ gl.UniformMatrix4fv(graphics.trafoUniform, 1, false, &graphics.trafo[0])
+
return graphics
}
@@ -86,6 +98,8 @@ func (graphics Graphics) draw() {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.UseProgram(graphics.program)
+ gl.UniformMatrix4fv(graphics.trafoUniform, 1, false, &graphics.trafo[0])
+
gl.BindVertexArray(graphics.vao)
gl.DrawArrays(gl.TRIANGLES, 0, int32(len(triangle)/3))
}