Пример #1
0
func initShaders() {
	program := Program(FragmentShader(fsh), VertexShader(vsh))
	gl.UseProgram(program)
	attrPos = uint(gl.GetAttribLocation(program, "pos"))
	attrColor = uint(gl.GetAttribLocation(program, "color"))
	gl.GenBuffers(1, gl.Void(&verticesArrayBuffer))
	gl.BindBuffer(gl.ARRAY_BUFFER, verticesArrayBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, len(vertices)*4, gl.Void(&vertices[0]), gl.STATIC_DRAW)
	gl.GenBuffers(1, gl.Void(&colorsArrayBuffer))
	gl.BindBuffer(gl.ARRAY_BUFFER, colorsArrayBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, len(colors)*4, gl.Void(&colors[0]), gl.STATIC_DRAW)
	gl.EnableVertexAttribArray(attrPos)
	gl.EnableVertexAttribArray(attrColor)
	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
}
Пример #2
0
func initShaders() {
	program := Program(FragmentShader(fsh), VertexShader(vsh))
	gl.UseProgram(program)

	attrPos = uint(gl.GetAttribLocation(program, "pos"))
	attrTexIn = uint(gl.GetAttribLocation(program, "texIn"))
	unifTexture = gl.GetUniformLocation(program, "texture")
	gl.EnableVertexAttribArray(attrPos)
	gl.EnableVertexAttribArray(attrTexIn)

	// Upload vertices data
	gl.GenBuffers(1, gl.Void(&verticesArrayBuffer))
	gl.BindBuffer(gl.ARRAY_BUFFER, verticesArrayBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, len(vertices)*4, gl.Void(&vertices[0]), gl.STATIC_DRAW)

	// Upload texture data
	imageBuffer, width, height := loadImage()
	gl.GenTextures(1, gl.Void(&textureBuffer))
	gl.BindTexture(gl.TEXTURE_2D, textureBuffer)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Void(&imageBuffer[0]))

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
}