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


Golang gl.Context类代码示例

本文整理汇总了Golang中golang.org/x/mobile/gl.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewButton

func NewButton(ctx gl.Context, x, y float32, w, h float32) *Button {
	btn := &Button{r: 1, g: 1, b: 1, a: 1}

	btn.x = (-(-1 - x)) / 2
	btn.y = (1 - y) / 2
	btn.w, btn.h = (w)/2, (-h)/2

	btn.verts = []float32{
		x, y, 0,
		x + w, y, 0,
		x, y + h, 0,
		x, y + h, 0,
		x + w, y, 0,
		x + w, y + h, 0,
	}

	btn.data = make([]byte, len(btn.verts)*4)

	var err error
	btn.program, err = glutil.CreateProgram(ctx, vertexShader, fragmentShader)
	if err != nil {
		panic(fmt.Errorf("error creating GL program: %v", err))
	}

	// create and alloc hw buf
	btn.buf = ctx.CreateBuffer()
	ctx.BindBuffer(gl.ARRAY_BUFFER, btn.buf)
	ctx.BufferData(gl.ARRAY_BUFFER, make([]byte, len(btn.verts)*4), gl.STATIC_DRAW)

	btn.position = ctx.GetAttribLocation(btn.program, "position")
	btn.color = ctx.GetUniformLocation(btn.program, "color")
	return btn
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:33,代码来源:waveform.go

示例2: NewWaveform

// TODO just how many samples do we want/need to display something useful?
func NewWaveform(ctx gl.Context, n int, in Sound) (*Waveform, error) {
	wf := &Waveform{Sound: in}

	wf.outs = make([][]float64, n)
	for i := range wf.outs {
		wf.outs[i] = make([]float64, in.BufferLen()*in.Channels())
	}
	wf.samples = make([]float64, in.BufferLen()*in.Channels()*n)
	// wf.aligned = make([]float64, in.BufferLen()*in.Channels()*n)

	wf.verts = make([]float32, len(wf.samples)*3)
	wf.data = make([]byte, len(wf.verts)*4)

	if ctx == nil {
		return wf, nil
	}

	var err error
	wf.program, err = glutil.CreateProgram(ctx, vertexShader, fragmentShader)
	if err != nil {
		return nil, fmt.Errorf("error creating GL program: %v", err)
	}

	// create and alloc hw buf
	wf.buf = ctx.CreateBuffer()
	ctx.BindBuffer(gl.ARRAY_BUFFER, wf.buf)
	ctx.BufferData(gl.ARRAY_BUFFER, make([]byte, len(wf.samples)*12), gl.STREAM_DRAW)

	wf.position = ctx.GetAttribLocation(wf.program, "position")
	wf.color = ctx.GetUniformLocation(wf.program, "color")
	return wf, nil
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:33,代码来源:waveform.go

示例3: onPaint

func onPaint(glctx gl.Context, sz size.Event) {
	glctx.ClearColor(1, 1, 1, 1)                                // クリアする色
	glctx.Clear(gl.COLOR_BUFFER_BIT)                            // 塗りつぶし?
	now := clock.Time(time.Since(startTime) * 60 / time.Second) // 60FramePerSecで計算し、現在のフレームを計算する
	game.Update(now)
	eng.Render(scene, now, sz)
}
开发者ID:toohsk,项目名称:gomobile-study,代码行数:7,代码来源:main.go

示例4: onPaint

func onPaint(glctx gl.Context, sz size.Event) {
	glctx.ClearColor(1, 1, 1, 1) // white background
	glctx.Clear(gl.COLOR_BUFFER_BIT)
	now := clock.Time(time.Since(startTime) * 60 / time.Second)
	eng.Render(scene, now, sz)
	fps.Draw(sz)
}
开发者ID:pankona,项目名称:gomobile_sprite_test,代码行数:7,代码来源:main.go

示例5: onPaint

func onPaint(glctx gl.Context, sz size.Event) {
	glctx.ClearColor(0, 0, 0, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT)
	now := clock.Time(time.Since(startTime) * 60 / time.Second)
	eng.Render(scene, now, sz)
	log.Draw(sz)
}
开发者ID:viru,项目名称:berrybot,代码行数:7,代码来源:main.go

示例6: onPaint

func onPaint(glctx gl.Context, sz size.Event) {
	glctx.ClearColor(1, 1, 1, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT)
	now := clock.Time(time.Since(startTime) * 60 / time.Second)
	game.Update(now)
	eng.Render(scene, now, sz)
}
开发者ID:Christeefym,项目名称:lantern,代码行数:7,代码来源:main.go

示例7: onPaint

func onPaint(glctx gl.Context, sz size.Event) {

	glctx.ClearColor(236, 240, 241, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT)

	columnOffset := (sz.WidthPt / 2) - ((geom.Pt(gridColumnsCount) * tileSize) / 2)
	rowOffset := (sz.HeightPt / 2) - ((geom.Pt(gridrowsCount) * tileSize) / 2)

	for c := 0; c < gridColumnsCount; c++ {

		for r := 0; r < gridrowsCount; r++ {

			t := &grid[((c+1)*(r+1))-1]

			t.columnOffset = columnOffset
			t.rowOffset = rowOffset
			t.x = geom.Pt(c) * tileSize
			t.y = geom.Pt(r) * tileSize
			t.Draw(sz)

		}

	}

}
开发者ID:plixul,项目名称:figura,代码行数:25,代码来源:main.go

示例8: Bind

func (tex Texture) Bind(ctx gl.Context, options ...func(gl.Context, Texture)) {
	ctx.ActiveTexture(gl.Enum(uint32(gl.TEXTURE0) + tex.Value - 1))
	ctx.BindTexture(gl.TEXTURE_2D, tex.Texture)
	for _, opt := range options {
		opt(ctx, tex)
	}
}
开发者ID:dskinner,项目名称:material,代码行数:7,代码来源:gl.go

示例9: onPaint

func onPaint(ctx gl.Context) {
	ctx.ClearColor(material.BlueGrey100.RGBA())
	ctx.Clear(gl.COLOR_BUFFER_BIT)
	env.Draw(ctx)
	now := time.Now()
	fps = int(time.Second / now.Sub(lastpaint))
	lastpaint = now
}
开发者ID:dskinner,项目名称:material,代码行数:8,代码来源:main.go

示例10: Mat4

func (prg Program) Mat4(ctx gl.Context, dst gl.Uniform, src f32.Mat4) {
	ctx.UniformMatrix4fv(dst, []float32{
		src[0][0], src[1][0], src[2][0], src[3][0],
		src[0][1], src[1][1], src[2][1], src[3][1],
		src[0][2], src[1][2], src[2][2], src[3][2],
		src[0][3], src[1][3], src[2][3], src[3][3],
	})
}
开发者ID:dskinner,项目名称:material,代码行数:8,代码来源:gl.go

示例11: Mat4

func (prg Program) Mat4(ctx gl.Context, dst gl.Uniform, src f32.Mat4) {
	m := make([]float32, 16)
	for i, v := range src {
		for j, x := range v {
			m[i*4+j] = x
		}
	}
	ctx.UniformMatrix4fv(dst, m)
}
开发者ID:lamproae,项目名称:material,代码行数:9,代码来源:gl.go

示例12: onStop

func onStop(glctx gl.Context) {
	glctx.DeleteProgram(program)
	glctx.DeleteBuffer(buf)
	fps.Release()
	if statusPainter != nil {
		statusPainter.Release()
	}
	images.Release()
}
开发者ID:bmatsuo,项目名称:rex,代码行数:9,代码来源:main.go

示例13: draw

func (vs *viewState) draw(glctx gl.Context, sz size.Event) {
	now := time.Now()
	diff := now.Sub(vs.lastDraw)
	vs.percentColor -= float32(diff.Seconds() * 0.5)
	if vs.percentColor < .25 {
		vs.percentColor = .25
	}
	vs.lastDraw = now

	select {
	case change := <-vs.tc:
		vs.touchChange = change
	default:
	}

	switch vs.touchChange.Type {
	case touch.TypeMove:
	case touch.TypeBegin:
		now := time.Now()
		if vs.lastTouch.Add(time.Millisecond * 1000).Before(now) {
			vs.lastTouch = now
			vs.percentColor = 0.5
			select {
			default:
			case vs.toggle <- now:
			}
		}
	case touch.TypeEnd:
	}

	var pingOk bool
	var connErr error
	vs.mu.RLock()
	pingOk = vs.pingOk
	connErr = vs.connErr
	vs.mu.RUnlock()

	var r, g, b = vs.percentColor, vs.percentColor, vs.percentColor
	if pingOk {
		r, b = 0, 0
	} else {
		g, b = 0, 0
	}

	glctx.ClearColor(r, g, b, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT)

	msg := "Tap to toggle garage door"
	if connErr != nil {
		msg = connErr.Error()
	}

	vs.sq.Draw(glctx, sz, "Garage door opener", msg)
}
开发者ID:kardianos,项目名称:garage,代码行数:54,代码来源:main.go

示例14: NewTextureBuffer

// TODO pass in an actual Texture ...
func NewTextureBuffer(ctx gl.Context, width, height int) *TextureFramebuffer {
	buf := &TextureFramebuffer{w: width, h: height}
	buf.fbo = Framebuffer{ctx.CreateFramebuffer()}
	buf.tex = Texture{ctx.CreateTexture()}

	buf.def = TextureDef(0, width, height, gl.RGBA, nil)
	buf.filter = TextureFilter(gl.LINEAR, gl.LINEAR)
	buf.wrap = TextureWrap(gl.REPEAT, gl.REPEAT)
	buf.withtex = FramebufferWithTex(buf.tex, 0, buf.def, buf.filter, buf.wrap)
	return buf
}
开发者ID:dskinner,项目名称:material,代码行数:12,代码来源:glutil.go

示例15: NewWhiteKey

// NewWhiteKey is a constructor that creates and returns a WhiteKey
func NewWhiteKey(glctx gl.Context, note util.KeyNote, sz size.Event, count int) *WhiteKey {
	newWhiteKey := new(WhiteKey)
	// Create the coloring and sound for the white key.
	newWhiteKey.PianoKey = newPianoKey(glctx, whiteKeyRGBColor, note)

	// Create coordinates for this specific white key
	newWhiteKey.openGLCoords, newWhiteKey.keyOutline, newWhiteKey.keyOuterBoundary = makeWhiteKeyVector(float32(sz.WidthPx), count)
	glctx.BufferData(gl.ARRAY_BUFFER, newWhiteKey.openGLCoords, gl.STATIC_DRAW)

	return newWhiteKey
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:12,代码来源:white_key.go


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