本文整理汇总了Golang中golang.org/x/mobile/gl.Context.ReadPixels方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.ReadPixels方法的具体用法?Golang Context.ReadPixels怎么用?Golang Context.ReadPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/mobile/gl.Context
的用法示例。
在下文中一共展示了Context.ReadPixels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: onTouch
func onTouch(glctx gl.Context, e touch.Event) {
touchX = e.X
touchY = e.Y
// When touch occurs we need to figure out which key is pressed.
// Using color picking for this.
// That is, scene is redrawn with each key given a unique color.
// And then the color is read on the touched pixel to figure out which key
// is pressed or if a key is pressed at all.
glctx.ClearColor(0.73, 0.5, 0.75, 0.5)
glctx.Clear(gl.DEPTH_BUFFER_BIT)
glctx.Clear(gl.COLOR_BUFFER_BIT)
glctx.UseProgram(program)
board.DrawI() // Draw the board with each key in a unique color
c := make([]byte, 12, 12)
glctx.ReadPixels(c, int(e.X), int(e.Y), 1, 1, gl.RGB, gl.UNSIGNED_BYTE)
// gl.RGB, gl.UNSIGNED_BYTE is the combination that is preffered by my Android
// phone. And is said to be the one preffered by many.
r := (float32(c[0]) / 255) * 100 // Convert byte to float
out := float32(math.Floor(float64(r)+0.5)) / 100 // and round up
key, ok := board.idColorKey[out]
if !ok {
curKey, ok := keystate[e.Sequence] //stop already playing sound
if ok {
StopSound(curKey)
}
return
}
if e.Type == touch.TypeBegin {
keystate[e.Sequence] = key
PlaySound(key)
} else if e.Type == touch.TypeEnd {
delete(keystate, e.Sequence)
StopSound(key)
} else if e.Type == touch.TypeMove {
if keystate[e.Sequence] != key {
// Drag has moved out of initial key
curKey, ok := keystate[e.Sequence] //stop already playing sound
if ok {
StopSound(curKey)
}
PlaySound(key) // play new key's sound
keystate[e.Sequence] = key
}
}
}