From a548776d757c8d6acc164a6c1388e10ee145251b Mon Sep 17 00:00:00 2001 From: Momchil Atanasov Date: Thu, 27 Sep 2018 21:39:01 +0300 Subject: [PATCH] bump go, whiskey-gl, opengl --- entities/map.go | 4 +--- game/controller.go | 11 +++++----- go.mod | 11 ++++++++++ go.sum | 41 ++++++++++++++++++++++++++++++++++++++ main.go | 21 +++++++++++++------ render/material_skybox.go | 15 +++++++------- render/material_skycube.go | 15 +++++++------- render/material_texture.go | 19 +++++++++++------- render/renderer.go | 3 ++- 9 files changed, 103 insertions(+), 37 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/entities/map.go b/entities/map.go index e641569..0f6a928 100644 --- a/entities/map.go +++ b/entities/map.go @@ -3,7 +3,7 @@ package entities import ( "fmt" - "github.com/go-gl/gl/v2.1/gl" + "github.com/go-gl/gl/v4.1-core/gl" "github.com/mokiat/go-whiskey/math" "github.com/mokiat/rally-mka/collision" "github.com/mokiat/rally-mka/render" @@ -154,9 +154,7 @@ func (m *gameMap) Draw(renderer *render.Renderer) { for _, wall := range m.walls { renderer.Render(wall.RenderMesh, renderer.TextureMaterial()) } - gl.Enable(gl.ALPHA_TEST) for _, dummy := range m.dummies { renderer.Render(dummy.RenderMesh, renderer.TextureMaterial()) } - gl.Disable(gl.ALPHA_TEST) } diff --git a/game/controller.go b/game/controller.go index 8206f66..2342335 100644 --- a/game/controller.go +++ b/game/controller.go @@ -5,7 +5,7 @@ import ( "path/filepath" "time" - "github.com/go-gl/gl/v2.1/gl" + "github.com/go-gl/gl/v4.1-core/gl" "github.com/mokiat/go-whiskey/math" "github.com/mokiat/rally-mka/entities" "github.com/mokiat/rally-mka/render" @@ -58,12 +58,13 @@ type controller struct { } func (r *controller) InitScene() { + var vertexArrayID uint32 + gl.GenVertexArrays(1, &vertexArrayID) + gl.BindVertexArray(vertexArrayID) + gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.CULL_FACE) - gl.Enable(gl.ALPHA_TEST) - gl.AlphaFunc(gl.GEQUAL, 0.8) - gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) @@ -96,7 +97,7 @@ func (r *controller) InitScene() { } func (r *controller) ResizeScene(width, height int) { - // gl.Viewport(0, 0, int32(width), int32(height)) + gl.Viewport(0, 0, int32(width), int32(height)) screenHalfWidth := float32(width) / float32(height) screenHalfHeight := float32(1.0) r.renderer.SetProjectionMatrix(math.PerspectiveMat4x4(-screenHalfWidth, screenHalfWidth, -screenHalfHeight, screenHalfHeight, 1.0, 300.0)) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e8bb507 --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module github.com/mokiat/rally-mka + +require ( + github.com/go-gl/gl v0.0.0-20180407155706-68e253793080 + github.com/go-gl/glfw v0.0.0-20180813204114-2484f3e51bc4 + github.com/mokiat/go-whiskey v0.0.0-20180926180122-f4e1bf7ab2c3 + github.com/mokiat/go-whiskey-gl v0.0.0-20180927130448-6a0c17c77157 + golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3 // indirect + golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7 // indirect + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..50698ec --- /dev/null +++ b/go.sum @@ -0,0 +1,41 @@ +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-gl/gl v0.0.0-20180407155706-68e253793080 h1:pNxZva3052YM+z2p1aP08FgaTE2NzrRJZ5BHJCmKLzE= +github.com/go-gl/gl v0.0.0-20180407155706-68e253793080/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= +github.com/go-gl/glfw v0.0.0-20180813204114-2484f3e51bc4 h1:4gBr8toVw4vfazzm1MpqiTd7ODKRRevdMEDO2yNggOk= +github.com/go-gl/glfw v0.0.0-20180813204114-2484f3e51bc4/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/mokiat/go-whiskey v0.0.0-20171211181154-105cbf27a48d h1:O4Z4/l//BhM1bQFaBX+qphXbsfh4xjBE54+6CpJg6cM= +github.com/mokiat/go-whiskey v0.0.0-20171211181154-105cbf27a48d/go.mod h1:UynAdBm2YjXG4+BXGMs1f9JyCadtP62cJP0HbuXIcpw= +github.com/mokiat/go-whiskey v0.0.0-20180926180122-f4e1bf7ab2c3 h1:1gQI0r0lOa34Ps2ebjaiVd3l3sORtd7+aBOPGJNA1w4= +github.com/mokiat/go-whiskey v0.0.0-20180926180122-f4e1bf7ab2c3/go.mod h1:sKasKDB0Pv2UV3oDBj+/dxzBor7kIeiHZbrK5iozA9c= +github.com/mokiat/go-whiskey-gl v0.0.0-20171219192726-371f1cceb9dd h1:TtaI/zYcQjbYvpz4Oy2KznLwP7kgr5MLmU82uqfHC+0= +github.com/mokiat/go-whiskey-gl v0.0.0-20171219192726-371f1cceb9dd/go.mod h1:JTj4CFjwJSQSRNPAoLD8EiNDGd1+0EwO/pbYepLuEGA= +github.com/mokiat/go-whiskey-gl v0.0.0-20180927130448-6a0c17c77157 h1:N5t54K/NgfZEKVpEyPCvgTAzNIVHBRZHwvBBC4OyH5Y= +github.com/mokiat/go-whiskey-gl v0.0.0-20180927130448-6a0c17c77157/go.mod h1:Vu7GSrTR6AphNKoDmtPRZfDWwUFv7kiValL37N9Kqxg= +github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I= +github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go index 381ae1f..4c93a65 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "path/filepath" "runtime" - "github.com/go-gl/gl/v2.1/gl" + "github.com/go-gl/gl/v4.1-core/gl" "github.com/go-gl/glfw/v3.2/glfw" "github.com/mokiat/rally-mka/game" ) @@ -20,17 +20,21 @@ func main() { } defer glfw.Terminate() - const width = 800 - const height = 600 - glfw.WindowHint(glfw.Resizable, glfw.False) - glfw.WindowHint(glfw.ContextVersionMajor, 2) + const width = 1024 + const height = 576 + glfw.WindowHint(glfw.ContextVersionMajor, 4) glfw.WindowHint(glfw.ContextVersionMinor, 1) + glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) + glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) window, err := glfw.CreateWindow(width, height, "Rally MKA", nil, nil) if err != nil { panic(err) } + defer window.Destroy() window.MakeContextCurrent() + window.SetInputMode(glfw.CursorMode, glfw.CursorHidden) + glfw.SwapInterval(1) if err := gl.Init(); err != nil { panic(err) } @@ -42,7 +46,12 @@ func main() { controller := game.NewController(assetsDir) controller.InitScene() - controller.ResizeScene(width, height) + + window.SetFramebufferSizeCallback(func(w *glfw.Window, width int, height int) { + controller.ResizeScene(width, height) + }) + fbWidth, fbHeight := window.GetFramebufferSize() + controller.ResizeScene(fbWidth, fbHeight) for !window.ShouldClose() { isQuit := window.GetKey(glfw.KeyEscape) == glfw.Press diff --git a/render/material_skybox.go b/render/material_skybox.go index 1a7a857..36bbe65 100644 --- a/render/material_skybox.go +++ b/render/material_skybox.go @@ -4,15 +4,15 @@ func newSkyboxMaterial() *Material { return newMaterial(skyboxVertexShader, skyboxFragmentShader) } -const skyboxVertexShader string = `#version 120 +const skyboxVertexShader string = `#version 410 uniform mat4 projectionMatrixIn; uniform mat4 viewMatrixIn; -attribute vec3 coordIn; -attribute vec2 texCoordIn; +in vec3 coordIn; +in vec2 texCoordIn; -varying vec2 texCoordInOut; +smooth out vec2 texCoordInOut; void main() { @@ -24,14 +24,15 @@ void main() } ` -const skyboxFragmentShader string = `#version 120 +const skyboxFragmentShader string = `#version 410 uniform sampler2D diffuseTextureIn; -varying vec2 texCoordInOut; +smooth in vec2 texCoordInOut; +layout(location = 0) out vec4 fragmentColor; void main() { - gl_FragColor = texture2D(diffuseTextureIn, texCoordInOut); + fragmentColor = texture(diffuseTextureIn, texCoordInOut); } ` diff --git a/render/material_skycube.go b/render/material_skycube.go index b4a43b4..682048b 100644 --- a/render/material_skycube.go +++ b/render/material_skycube.go @@ -4,14 +4,14 @@ func newSkycubeMaterial() *Material { return newMaterial(skycubeVertexShader, skycubeFragmentShader) } -const skycubeVertexShader string = `#version 120 +const skycubeVertexShader string = `#version 410 uniform mat4 projectionMatrixIn; uniform mat4 viewMatrixIn; -attribute vec3 coordIn; +in vec3 coordIn; -varying vec3 texCoordInOut; +smooth out vec3 texCoordInOut; void main() { @@ -30,16 +30,15 @@ void main() } ` -const skycubeFragmentShader string = `#version 120 +const skycubeFragmentShader string = `#version 410 uniform samplerCube skycubeTextureIn; -varying vec3 texCoordInOut; +smooth in vec3 texCoordInOut; +layout(location = 0) out vec4 fragmentColor; void main() { - // gl_FragColor = textureCube(skycubeTextureIn, texCoordInOut); - gl_FragColor = vec4(textureCube(skycubeTextureIn, texCoordInOut).rgb, 1.0); - // gl_FragColor = vec4(texCoordInOut, 1.0); + fragmentColor = vec4(texture(skycubeTextureIn, texCoordInOut).rgb, 1.0); } ` diff --git a/render/material_texture.go b/render/material_texture.go index 86564cb..4171c8d 100644 --- a/render/material_texture.go +++ b/render/material_texture.go @@ -4,16 +4,16 @@ func newTextureMaterial() *Material { return newMaterial(textureVertexShader, textureFragmentShader) } -const textureVertexShader string = `#version 120 +const textureVertexShader string = `#version 410 uniform mat4 projectionMatrixIn; uniform mat4 modelMatrixIn; uniform mat4 viewMatrixIn; -attribute vec3 coordIn; -attribute vec2 texCoordIn; +in vec3 coordIn; +in vec2 texCoordIn; -varying vec2 texCoordInOut; +smooth out vec2 texCoordInOut; void main() { @@ -22,14 +22,19 @@ void main() } ` -const textureFragmentShader string = `#version 120 +const textureFragmentShader string = `#version 410 uniform sampler2D diffuseTextureIn; -varying vec2 texCoordInOut; +smooth in vec2 texCoordInOut; +layout(location = 0) out vec4 fragmentColor; void main() { - gl_FragColor = texture2D(diffuseTextureIn, texCoordInOut); + vec4 color = texture(diffuseTextureIn, texCoordInOut); + if (color.a < 0.9) { + discard; + } + fragmentColor = color; } ` diff --git a/render/renderer.go b/render/renderer.go index e251788..78aabe9 100644 --- a/render/renderer.go +++ b/render/renderer.go @@ -1,7 +1,7 @@ package render import ( - "github.com/go-gl/gl/v2.1/gl" + "github.com/go-gl/gl/v4.1-core/gl" "github.com/mokiat/go-whiskey/math" ) @@ -67,6 +67,7 @@ func (r *Renderer) ViewMatrix() math.Mat4x4 { func (r *Renderer) Render(mesh *Mesh, material *Material) { material.program.Use() + gl.BindFragDataLocation(material.program.ID, 0, gl.Str("fragmentColor\x00")) if material.diffuseTextureLocation != -1 { gl.ActiveTexture(gl.TEXTURE0)