summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.go8
-rw-r--r--graphics.go21
-rw-r--r--main.go1
3 files changed, 18 insertions, 12 deletions
diff --git a/app.go b/app.go
index 603f47d..119e17d 100644
--- a/app.go
+++ b/app.go
@@ -6,6 +6,7 @@ import (
"log"
"github.com/go-gl/glfw/v3.3/glfw"
+ "github.com/go-gl/mathgl/mgl32"
)
const (
@@ -16,6 +17,7 @@ const (
type App struct {
window *glfw.Window
+ graphics *Graphics
}
func newApp() App {
@@ -45,9 +47,13 @@ func newApp() App {
return app
}
-func (application App) handle() {
+func (application *App) handle() {
glfw.PollEvents()
application.window.SwapBuffers()
+ trafo := mgl32.HomogRotate3D(float32(glfw.GetTime()) * 3, mgl32.Vec3{0, 1, 1})
+ var scale float32 = 0.01
+ trafo = trafo.Mul4(mgl32.Scale3D(scale, scale, scale))
+ application.graphics.setTrafo(trafo)
}
func (application App) terminate() {
diff --git a/graphics.go b/graphics.go
index 87c21ed..66b8274 100644
--- a/graphics.go
+++ b/graphics.go
@@ -9,7 +9,6 @@ import (
"github.com/go-gl/gl/v4.6-core/gl"
"github.com/go-gl/mathgl/mgl32"
- "github.com/go-gl/glfw/v3.3/glfw"
)
var (
@@ -22,12 +21,6 @@ var (
const (
- // rotational speed and vector
- OMEGA = 3
- ROT_X = 0
- ROT_Y = 1
- ROT_Z = 1
-
// vertex shader to draw points
VERTEX_SHADER = `
#version 410
@@ -65,6 +58,8 @@ func newGraphics() Graphics {
var graphics Graphics = Graphics{}
+ graphics.trafo = mgl32.Ident4()
+
// init OpenGL and save/log version
log.Println("OpenGL init")
err := gl.Init()
@@ -94,8 +89,8 @@ func newGraphics() Graphics {
graphics.vao = makeVao(vertices)
// create transformation matrix
- graphics.trafo = mgl32.HomogRotate3D(float32(glfw.GetTime()) * OMEGA, mgl32.Vec3{ROT_X, ROT_Y, ROT_Z})
- graphics.trafoUniform = gl.GetUniformLocation(graphics.program, gl.Str("trafo\x00"))
+ //graphics.trafo = mgl32.HomogRotate3D(float32(glfw.GetTime()) * OMEGA, mgl32.Vec3{ROT_X, ROT_Y, ROT_Z})
+ //graphics.trafoUniform = gl.GetUniformLocation(graphics.program, gl.Str("trafo\x00"))
gl.UniformMatrix4fv(graphics.trafoUniform, 1, false, &graphics.trafo[0])
return graphics
@@ -105,11 +100,11 @@ func (graphics Graphics) draw() {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.UseProgram(graphics.program)
- graphics.trafo = mgl32.HomogRotate3D(float32(glfw.GetTime()) * OMEGA, mgl32.Vec3{ROT_X, ROT_Y, ROT_Z})
+ //graphics.trafo = mgl32.HomogRotate3D(float32(glfw.GetTime()) * OMEGA, mgl32.Vec3{ROT_X, ROT_Y, ROT_Z})
gl.UniformMatrix4fv(graphics.trafoUniform, 1, false, &graphics.trafo[0])
gl.BindVertexArray(graphics.vao)
- gl.DrawArrays(gl.TRIANGLES, 0, int32(len(vertices)/3))
+ gl.DrawArrays(gl.LINE_STRIP, 0, int32(len(vertices)/3)) // POINTS, LINES, LINE_STRIP, LINE_LOOP, TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN
}
// makeVao initializes and returns a vertex array from the points provided.
@@ -157,3 +152,7 @@ func compileShader(source string, shaderType uint32) (uint32, error) {
return shader, nil
}
+
+func (graphics *Graphics) setTrafo(trafo mgl32.Mat4) {
+ graphics.trafo = trafo
+}
diff --git a/main.go b/main.go
index 6444871..1bf0b9d 100644
--- a/main.go
+++ b/main.go
@@ -33,6 +33,7 @@ func main() {
// initialize graphics
var graphics Graphics = newGraphics()
+ app.graphics = &graphics // connect graphics to the app
// main loop
for !app.window.ShouldClose() {