当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.ReadPixels方法代码示例

本文整理汇总了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
		}
	}
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:53,代码来源:main.go


注:本文中的golang.org/x/mobile/gl.Context.ReadPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。