예제 #1
0
파일: main.go 프로젝트: xfong/gocl
func initGL() {
	var err error
	program, err = glutil.CreateProgram(vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	buf = gl.GenBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, buf)
	gl.BufferData(gl.ARRAY_BUFFER, gl.STATIC_DRAW, triangleData)

	position = gl.GetAttribLocation(program, "position")
	color = gl.GetUniformLocation(program, "color")
	offset = gl.GetUniformLocation(program, "offset")
	touchLoc = geom.Point{geom.Width / 2, geom.Height / 2}
}
예제 #2
0
파일: key.go 프로젝트: gordonklaus/justkeys
func initKeys() {
	var err error
	program, err = glutil.CreateProgram(
		`#version 100
		uniform mat4 projection;
		attribute vec3 position;
		attribute float pointsize;
		void main() {
			gl_Position = projection * vec4(position, 1);
			gl_PointSize = pointsize;
		}`,
		`#version 100
		precision mediump float;
		uniform vec4 color;
		void main(void)
		{
		    vec2 v = 2.0*gl_PointCoord.xy - vec2(1.0);
			float r2 = dot(v, v);
			gl_FragColor = mix(color, vec4(0), r2);
		}`,
	)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	gl.Enable(34370) // GL_PROGRAM_POINT_SIZE; apparently not necessary on Android
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR)

	projection = gl.GetUniformLocation(program, "projection")
	updateProjectionMatrix()

	position = gl.GetAttribLocation(program, "position")
	pointsize = gl.GetAttribLocation(program, "pointsize")
	color = gl.GetUniformLocation(program, "color")
	positionbuf = gl.CreateBuffer()
	pointsizebuf = gl.CreateBuffer()
	updateKeys(ratio{1, 1})
}