diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-05-21 14:37:02 +0200 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-05-21 14:37:02 +0200 |
commit | 10679867f1742121f5e953247406cfb83f3b3e65 (patch) | |
tree | 4b0021e5c04b147830ba3367b4f351ccf18cb332 /graphics.go | |
parent | feff22144689df9da5ddb8e9693326b77feb7949 (diff) | |
download | stlscope-10679867f1742121f5e953247406cfb83f3b3e65.tar stlscope-10679867f1742121f5e953247406cfb83f3b3e65.tar.zst stlscope-10679867f1742121f5e953247406cfb83f3b3e65.zip |
First successful homogenous Transformation on GPU
Diffstat (limited to 'graphics.go')
-rw-r--r-- | graphics.go | 16 |
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)) } |