https://github.com/vbsw/shaders
simple vertex and fragement shader, version 1.30 (OpenGL 3.0)
https://github.com/vbsw/shaders
example glsl go golang shader simple
Last synced: 11 days ago
JSON representation
simple vertex and fragement shader, version 1.30 (OpenGL 3.0)
- Host: GitHub
- URL: https://github.com/vbsw/shaders
- Owner: vbsw
- License: bsl-1.0
- Created: 2020-05-18T09:17:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-05T17:24:58.000Z (over 4 years ago)
- Last Synced: 2023-07-27T22:45:08.017Z (over 2 years ago)
- Topics: example, glsl, go, golang, shader, simple
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Shaders
[](https://godoc.org/github.com/vbsw/shaders) [](https://goreportcard.com/report/github.com/vbsw/shaders) [](https://masterminds.github.io/stability/experimental.html)
## About
This package contains plain vertex and fragment shaders, version 1.30 (OpenGL 3.0), for Go. It is published on and .
## Copyright
Copyright 2020, Vitali Baumtrok (vbsw@mailbox.org).
Shaders is distributed under the Boost Software License, version 1.0. (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
Shaders is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Boost Software License for more details.
## Examples
With this package:
import (
"github.com/go-gl/gl/v3.3-core/gl"
"github.com/vbsw/shaders"
)
func main() {
....
shader := shaders.NewPrimitiveShader()
shader.VertexShaderID = gl.CreateShader(gl.VERTEX_SHADER)
gl.ShaderSource(shader.VertexShaderID, 1, shader.VertexShader, nil)
....
}
Standard way:
import (
"github.com/go-gl/gl/v3.3-core/gl"
)
func main() {
....
vertexShaderStr := "#version 130\nin vec3 vp;\nvoid main () {\n\tgl_Position = vec4(vp, 1.0);\n}"
shaderID := gl.CreateShader(gl.VERTEX_SHADER)
vertexShaderC, free := gl.Strs(vertexShaderStr + "\x00")
gl.ShaderSource(shaderID, 1, vertexShaderC, nil)
free()
....
}
Initialize the projection matrix:
import (
"github.com/go-gl/gl/v3.3-core/gl"
"github.com/vbsw/shaders"
)
func main() {
....
shader.ProjectionLocation = gl.GetUniformLocation(shader.ProgramID, shader.ProjectionUniform)
gl.UseProgram(shader.ProgramID)
setProjection(shader.ProjectionLocation, 400, 400)
....
}
func setProjection(projectionLocation int32, width, height int) {
projectionMatrix := make([]float32, 4*4)
projectionMatrix[0] = 2.0 / float32(width)
projectionMatrix[5] = 2.0 / float32(height)
projectionMatrix[12] = -1.0
projectionMatrix[13] = -1.0
projectionMatrix[15] = 1.0
gl.UniformMatrix4fv(projectionLocation, 1, false, &projectionMatrix[0]);
}
## References
- https://golang.org/doc/install
- https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
- https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.1.30.pdf
- https://github.com/go-gl/gl/blob/master/v3.3-core/gl/conversions.go
- https://git.sr.ht/~eliasnaur/gio/tree/master/example/glfw/main.go