Skip to content

Commit

Permalink
bump go, whiskey-gl, opengl
Browse files Browse the repository at this point in the history
  • Loading branch information
mokiat committed Sep 27, 2018
1 parent adce80c commit a548776
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 37 deletions.
4 changes: 1 addition & 3 deletions entities/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
11 changes: 6 additions & 5 deletions game/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
41 changes: 41 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
}
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions render/material_skybox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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);
}
`
15 changes: 7 additions & 8 deletions render/material_skycube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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);
}
`
19 changes: 12 additions & 7 deletions render/material_texture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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;
}
`
3 changes: 2 additions & 1 deletion render/renderer.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a548776

Please sign in to comment.