示例#1
0
文件: main.go 项目: xfong/gocl
	gl.Uniform4f(color, 0, 0, blue, 1)

	gl.Uniform2f(offset, float32(touchLoc.X/geom.Width), float32(touchLoc.Y/geom.Height))

	gl.BindBuffer(gl.ARRAY_BUFFER, buf)
	gl.EnableVertexAttribArray(position)
	gl.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, 0, 0)
	gl.DrawArrays(gl.TRIANGLES, 0, vertexCount)
	gl.DisableVertexAttribArray(position)

	debug.DrawFPS()
}

var triangleData = f32.Bytes(binary.LittleEndian,
	0.0, 0.4, 0.0, // top left
	0.0, 0.0, 0.0, // bottom left
	0.4, 0.0, 0.0, // bottom right
)

const (
	coordsPerVertex = 3
	vertexCount     = 3
)

const vertexShader = `#version 100
uniform vec2 offset;

attribute vec4 position;
void main() {
        // offset comes in with x/y values between 0 and 1.
        // position bounds are -1 to 1.
示例#2
0
文件: glimage.go 项目: Miaque/mojo
	gl.EnableVertexAttribArray(glimage.pos)
	gl.VertexAttribPointer(glimage.pos, 2, gl.FLOAT, false, 0, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, glimage.quadUV)
	gl.EnableVertexAttribArray(glimage.inUV)
	gl.VertexAttribPointer(glimage.inUV, 2, gl.FLOAT, false, 0, 0)

	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)

	gl.DisableVertexAttribArray(glimage.pos)
	gl.DisableVertexAttribArray(glimage.inUV)
}

var quadXYCoords = f32.Bytes(binary.LittleEndian,
	-1, +1, // top left
	+1, +1, // top right
	-1, -1, // bottom left
	+1, -1, // bottom right
)

var quadUVCoords = f32.Bytes(binary.LittleEndian,
	0, 0, // top left
	1, 0, // top right
	0, 1, // bottom left
	1, 1, // bottom right
)

const vertexShader = `#version 100
uniform mat3 mvp;
uniform mat3 uvp;
attribute vec3 pos;
attribute vec2 inUV;
示例#3
0
func drawKeys() {
	gl.UseProgram(program)
	projection.WriteMat4(&projmat)

	iPlaying := []int{}
	playing := []ratio{}
	amps := []float64{}
	for i, k := range keys {
		k := k.base()
		if k.voice != nil && !k.voice.Done() {
			iPlaying = append(iPlaying, i)
			playing = append(playing, k.ratio)
			amps = append(amps, k.voice.amp())
		}
	}
	complexities := make([]float64, len(keys))
	minComplexity := math.MaxFloat64
	for i, k := range keys {
		k := k.base()
		c := -1.0
		for j, iPlaying := range iPlaying {
			if i == iPlaying {
				a := amps[j]
				amps[j] = 1
				c = complexity(playing, amps)
				amps[j] = a
				break
			}
		}
		if c == -1 {
			c = complexity(append(playing, k.ratio), append(amps, 1))
		}
		complexities[i] = c
		if c < minComplexity {
			minComplexity = c
		}
	}
	data := []float32{}
	pointsizedata := []float32{}
	for i, k := range keys {
		k := k.base()
		k.y = 1 - math.Exp2(-float64(complexities[i]-minComplexity)/4)
		k.size = math.Exp2(-float64(complexities[i])/4) * float64(geom.Width) * float64(geom.PixelsPerPt) / 4
		data = append(data, float32(k.pitch), float32(k.y))
		pointsizedata = append(pointsizedata, float32(k.size))
	}
	gl.BindBuffer(gl.ARRAY_BUFFER, positionbuf)
	gl.BufferData(gl.ARRAY_BUFFER, f32.Bytes(binary.LittleEndian, data...), gl.DYNAMIC_DRAW)
	gl.BindBuffer(gl.ARRAY_BUFFER, pointsizebuf)
	gl.BufferData(gl.ARRAY_BUFFER, f32.Bytes(binary.LittleEndian, pointsizedata...), gl.DYNAMIC_DRAW)

	gl.EnableVertexAttribArray(position)
	gl.EnableVertexAttribArray(pointsize)
	gl.Uniform4f(color, 1, 1, 1, 1)
	gl.BindBuffer(gl.ARRAY_BUFFER, positionbuf)
	gl.VertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0)
	gl.BindBuffer(gl.ARRAY_BUFFER, pointsizebuf)
	gl.VertexAttribPointer(pointsize, 1, gl.FLOAT, false, 0, 0)
	gl.DrawArrays(gl.POINTS, 0, len(keys))
	gl.DisableVertexAttribArray(position)
	gl.DisableVertexAttribArray(pointsize)
}