예제 #1
0
func onPaint(sz size.Event) {
	gl.ClearColor(rgb(156), rgb(39), rgb(176), 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	var rotationMatrix = []float32{
		f32.Cos(-alpha), -f32.Sin(-alpha), 0.0,
		f32.Sin(-alpha), f32.Cos(-alpha), 0.0,
		0.0, 0.0, 1.0,
	}

	gl.UseProgram(program)
	// setting color
	gl.Uniform4f(color, rgb(255), rgb(255), rgb(255), 1)
	gl.UniformMatrix3fv(matrixId, rotationMatrix)
	gl.Uniform1f(resolutionId, resIndex)

	gl.BindBuffer(gl.ARRAY_BUFFER, swasBuffer)

	gl.EnableVertexAttribArray(position)
	gl.VertexAttribPointer(position, 3, gl.FLOAT, false, 0, 0)
	gl.DrawArrays(gl.LINES, 0, 16)
	gl.DisableVertexAttribArray(position)

	gl.UseProgram(texProgram)
	// setting color
	gl.Uniform4f(color2, rgb(130), rgb(50), rgb(80), 1)
	gl.Uniform1f(resolutionId2, resIndex)
	gl.UniformMatrix3fv(matrixId2, rotationMatrix)

	gl.BindBuffer(gl.ARRAY_BUFFER, quadBuffer)
	gl.EnableVertexAttribArray(position2)
	gl.VertexAttribPointer(position2, 3, gl.FLOAT, false, 0, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, quadTexBuffer)
	gl.EnableVertexAttribArray(textureCoords)
	gl.VertexAttribPointer(textureCoords, 2, gl.FLOAT, false, 0, 0)

	gl.Uniform1i(gl.GetUniformLocation(texProgram, "myTexture"), 0)
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, textureId)

	gl.DrawArrays(gl.TRIANGLES, 0, 6)
	gl.DisableVertexAttribArray(position2)
	gl.DisableVertexAttribArray(textureCoords)

	if spin == true {
		alpha += 0.1
	}

	if alpha >= 360 {
		alpha = 0.0
	}

}
예제 #2
0
파일: glutil.go 프로젝트: handong890/mobile
// writeAffine writes the contents of an Affine to a 3x3 matrix GL uniform.
func writeAffine(u gl.Uniform, a *f32.Affine) {
	var m [9]float32
	m[0*3+0] = a[0][0]
	m[0*3+1] = a[1][0]
	m[0*3+2] = 0
	m[1*3+0] = a[0][1]
	m[1*3+1] = a[1][1]
	m[1*3+2] = 0
	m[2*3+0] = a[0][2]
	m[2*3+1] = a[1][2]
	m[2*3+2] = 1
	gl.UniformMatrix3fv(u, m[:])
}
예제 #3
0
func writeAff3(u gl.Uniform, a f64.Aff3) {
	var m [9]float32
	m[0*3+0] = float32(a[0*3+0])
	m[0*3+1] = float32(a[1*3+0])
	m[0*3+2] = 0
	m[1*3+0] = float32(a[0*3+1])
	m[1*3+1] = float32(a[1*3+1])
	m[1*3+2] = 0
	m[2*3+0] = float32(a[0*3+2])
	m[2*3+1] = float32(a[1*3+2])
	m[2*3+2] = 1
	gl.UniformMatrix3fv(u, m[:])
}