Exemple #1
0
func initScene() {
	halfW, halfH := float32(Width)*0.5, float32(Height)*0.5

	Projection = mgl.Ortho2D(-halfW, halfW, -halfH, halfH).Mul4(
		mgl.Translate3D(-halfW, -halfH, 0))

	ModelView = mgl.Ident4f().Mul4(mgl.Scale3D(100, 100, 0))
	MVP <- Projection.Mul4(ModelView)

	gl.Disable(gl.DEPTH_TEST)
	gl.DepthMask(false)

	program := Program(FragmentShader(fsh), VertexShader(vsh))
	gl.UseProgram(uint(program))
	uMVP = gl.GetUniformLocation(program, "uMVP")
	attrPos = gl.GetAttribLocation(program, "pos")
	attrColor = gl.GetAttribLocation(program, "color")

	gl.EnableVertexAttribArray(uint(attrPos))
	gl.EnableVertexAttribArray(uint(attrColor))
	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.VertexAttribPointer(uint(attrPos), 2, gl.FLOAT, false, 0, uintptr(gl.Void(&POSITION[0])))
	gl.VertexAttribPointer(uint(attrColor), 4, gl.FLOAT, false, 0, uintptr(gl.Void(&COLOR[0])))

}
Exemple #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)
}