gl01/internal/render/render_world_helper.go

47 lines
973 B
Go
Raw Normal View History

2022-01-22 23:06:41 +08:00
package render
import (
"unsafe"
"github.com/go-gl/gl/all-core/gl"
)
var (
screenQuadVerts = []float32{
-1, -1,
1, -1,
1, 1,
-1, -1,
1, 1,
-1, 1,
}
screenQuadVAO uint32
screenQuadVBO uint32
)
func initScreenQuad() {
gl.GenBuffers(1, &screenQuadVBO)
gl.BindBuffer(gl.ARRAY_BUFFER, screenQuadVBO)
gl.BufferData(gl.ARRAY_BUFFER, int(unsafe.Sizeof(float32(0)))*len(screenQuadVerts), gl.Ptr(screenQuadVerts), gl.STATIC_DRAW)
gl.GenVertexArrays(1, &screenQuadVAO)
gl.BindVertexArray(screenQuadVAO)
gl.VertexAttribPointer(0, 2, gl.FLOAT, false, int32(2*unsafe.Sizeof(float32(0))), gl.PtrOffset(0))
gl.EnableVertexAttribArray(0)
}
// drawScreenQuad draws a Quad covering the entire screen.
//
// Attribute: vert: [ -1.0 --> 1.0]
func (r *WorldRenderer) drawScreenQuad() {
if screenQuadVAO == 0 {
initScreenQuad()
}
gl.Disable(gl.DEPTH_TEST)
gl.Disable(gl.CULL_FACE)
gl.BindVertexArray(screenQuadVAO)
gl.DrawArrays(gl.TRIANGLES, 0, 6)
}