Esempio n. 1
0
func draw() {
	gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.BindBuffer(gl.ARRAY_BUFFER, vertexArrayBuffer)
	gl.VertexAttribPointer(attrPos, 4, gl.FLOAT, false, 0, nil)
	gl.BindBuffer(gl.ARRAY_BUFFER, colorArrayBuffer)
	gl.VertexAttribPointer(attrCol, 3, gl.FLOAT, false, 0, nil)
	gl.DrawArrays(gl.TRIANGLES, 0, 3)
	gl.Flush()
	gl.Finish()
	egl.SwapBuffers(display, surface)
}
Esempio n. 2
0
func initShaders() {
	p = Program(FragmentShader(fsh), VertexShader(vsh))
	gl.UseProgram(p)

	attrPos = uint32(gl.GetAttribLocation(p, "pos"))
	attrCol = uint32(gl.GetAttribLocation(p, "color"))

	gl.GenBuffers(1, &vertexArrayBuffer)
	gl.BindBuffer(gl.ARRAY_BUFFER, vertexArrayBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, gl.SizeiPtr(len(vertices))*4, unsafe.Pointer(&vertices[0]), gl.STATIC_DRAW)
	gl.GenBuffers(1, &colorArrayBuffer)
	gl.BindBuffer(gl.ARRAY_BUFFER, colorArrayBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, gl.SizeiPtr(len(colors))*4, unsafe.Pointer(&colors[0]), gl.STATIC_DRAW)
	gl.EnableVertexAttribArray(attrPos)
	gl.EnableVertexAttribArray(attrCol)
}