Exemple #1
0
func setupGL() int32 {
	gl.Disable(gl.DEPTH_TEST)
	gl.ClearColor(0.7, 0.7, 0.7, 1)

	program, _ := loadResources()

	gl.BindFragDataLocation(program, 0, gl.Str("outputColor\x00"))
	cameraMatrixUniform := gl.GetUniformLocation(program, gl.Str("cameraMatrix\x00"))
	octUniform := gl.GetUniformLocation(program, gl.Str("oct\x00"))
	gl.Uniform1i(octUniform, 0)

	gl.Viewport(0, 0, winWidth, winHeight)

	var vao uint32
	gl.GenVertexArrays(1, &vao)
	gl.BindVertexArray(vao)

	quadVertexBufferData := []float32{
		-1, -1, 0,
		1, -1, 0,
		-1, 1, 0,
		-1, 1, 0,
		1, -1, 0,
		1, 1, 0,
	}

	var vbo uint32
	gl.GenBuffers(1, &vbo)
	gl.BindBuffer(gl.ARRAY_BUFFER, vbo)
	gl.BufferData(gl.ARRAY_BUFFER, len(quadVertexBufferData)*4, gl.Ptr(quadVertexBufferData), gl.STATIC_DRAW)

	vertAttrib := uint32(gl.GetAttribLocation(program, gl.Str("inputPosition\x00")))
	gl.EnableVertexAttribArray(vertAttrib)
	gl.VertexAttribPointer(vertAttrib, 3, gl.FLOAT, false, 0, gl.PtrOffset(0))

	return cameraMatrixUniform
}
// GetAttribLocation implements the opengl.OpenGl interface.
func (native *OpenGl) GetAttribLocation(program uint32, name string) int32 {
	return gl.GetAttribLocation(program, gl.Str(name+"\x00"))
}