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


Golang gl.ClearColor函数代码示例

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


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

示例1: main

func main() {
	app.Main(func(a app.App) {
		addr := "127.0.0.1:" + apptest.Port
		log.Printf("addr: %s", addr)

		conn, err := net.Dial("tcp", addr)
		if err != nil {
			log.Fatal(err)
		}
		defer conn.Close()
		log.Printf("dialled")
		comm := &apptest.Comm{
			Conn:   conn,
			Fatalf: log.Panicf,
			Printf: log.Printf,
		}

		comm.Send("hello_from_testapp")
		comm.Recv("hello_from_host")

		color := "red"
		sendPainting := false
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					comm.Send("lifecycle_visible")
					sendPainting = true
				case lifecycle.CrossOff:
					comm.Send("lifecycle_not_visible")
				}
			case size.Event:
				comm.Send("size", e.PixelsPerPt, e.Orientation)
			case paint.Event:
				if color == "red" {
					gl.ClearColor(1, 0, 0, 1)
				} else {
					gl.ClearColor(0, 1, 0, 1)
				}
				gl.Clear(gl.COLOR_BUFFER_BIT)
				a.EndPaint(e)
				if sendPainting {
					comm.Send("paint", color)
					sendPainting = false
				}
			case touch.Event:
				comm.Send("touch", e.Type, e.X, e.Y)
				if e.Type == touch.TypeEnd {
					if color == "red" {
						color = "green"
					} else {
						color = "red"
					}
					sendPainting = true
				}
			}
		}
	})
}
开发者ID:rockxcn,项目名称:mobile,代码行数:60,代码来源:testapp.go

示例2: draw

func draw() {
	if program.Value == 0 {
		initGL()
		initCL()
	}
	if numPlatforms == 0 {
		gl.ClearColor(1, 0, 0, 1)
	} else {
		gl.ClearColor(0, 1, 0, 1)
	}
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.UseProgram(program)

	blue += 0.01
	if blue > 1 {
		blue = 0
	}
	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()
}
开发者ID:xfong,项目名称:gocl,代码行数:30,代码来源:main.go

示例3: onDraw

func onDraw(sz size.Event) {
	select {
	case <-determined:
		if ok {
			gl.ClearColor(0, 1, 0, 1)
		} else {
			gl.ClearColor(1, 0, 0, 1)
		}
	default:
		gl.ClearColor(0, 0, 0, 1)
	}
	gl.Clear(gl.COLOR_BUFFER_BIT)

	debug.DrawFPS(sz)
}
开发者ID:rockxcn,项目名称:mobile,代码行数:15,代码来源:main.go

示例4: draw

func draw(c event.Config) {
	select {
	case <-determined:
		if ok {
			gl.ClearColor(0, 1, 0, 1)
		} else {
			gl.ClearColor(1, 0, 0, 1)
		}
	default:
		gl.ClearColor(0, 0, 0, 1)
	}
	gl.Clear(gl.COLOR_BUFFER_BIT)

	debug.DrawFPS(c)
}
开发者ID:guanhuihui,项目名称:mobile,代码行数:15,代码来源:main.go

示例5: main

func main() {
	app.Main(func(a app.App) {
		var c event.Config
		var eng *WritableEngine
		var root *sprite.Node
		startClock := time.Now()
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case event.Config:
				c = e
			case event.Draw:
				if eng == nil || root == nil {
					eng = NewWritableEngine(
						glsprite.Engine(),
						image.Rect(0, 0, int(c.Width.Px(c.PixelsPerPt)), int(c.Height.Px(c.PixelsPerPt))),
						color.White,
					)
					root = loadScene(eng, loadTextures(eng))
					go listen(eng, ":8080")
				}
				now := clock.Time(time.Since(startClock) * 60 / time.Second)
				gl.ClearColor(1, 1, 1, 1)
				gl.Clear(gl.COLOR_BUFFER_BIT)
				gl.Enable(gl.BLEND)
				gl.BlendEquation(gl.FUNC_ADD)
				gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
				if eng != nil && root != nil {
					eng.Render(root, now, c)
				}
				a.EndDraw()
			}
		}
	})
}
开发者ID:golang-samples,项目名称:gomobile,代码行数:34,代码来源:main.go

示例6: Render

func (e *Engine) Render(sz size.Event) {
	gl.ClearColor(1, 1, 1, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	now := clock.Time(time.Since(e.startTime) * 60 / time.Second)
	e.arranger.sz = &sz
	e.eng.Render(e.scene, now, sz)
}
开发者ID:mccordnate,项目名称:gogam,代码行数:7,代码来源:engine.go

示例7: onPaint

func onPaint(c size.Event) {
	//清场
	gl.ClearColor(1, 1, 1, 1) //设置背景颜色
	gl.Clear(gl.COLOR_BUFFER_BIT)

	//使用program
	gl.UseProgram(program)

	gl.Uniform4f(color, 0, 0.5, 0.8, 1) //设置color对象值,设置4个浮点数.
	//offset有两个值X,Y,窗口左上角为(0,0),右下角为(1,1)
	//gl.Uniform4f(offset,5.0,1.0,1.0,1.0 )
	//gl.Uniform2f(offset,offsetx,offsety )//为2参数的uniform变量赋值
	//log.Println("offset:",offsetx,offsety, 0, 0)
	gl.UniformMatrix4fv(scan, []float32{
		float32(touchLoc.X/c.WidthPt*4 - 2), 0, 0, 0,
		0, float32(touchLoc.Y/c.HeightPt*4 - 2), 0, 0,
		0, 0, 0, 0,
		0, 0, 0, 1,
	})
	gl.BindBuffer(gl.ARRAY_BUFFER, buf)
	gl.EnableVertexAttribArray(position)
	/*glVertexAttribPointer 指定了渲染时索引值为 index 的顶点属性数组的数据格式和位置。调用gl.vertexAttribPointer()方法,把顶点着色器中某个属性相对应的通用属性索引连接到绑定的webGLBUffer对象上。
	  index 指定要修改的顶点属性的索引值
	  size    指定每个顶点属性的组件数量。必须为1、2、3或者4。初始值为4。(如position是由3个(x,y,z)组成,而颜色是4个(r,g,b,a))
	  type    指定数组中每个组件的数据类型。可用的符号常量有GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT,GL_UNSIGNED_SHORT, GL_FIXED, 和 GL_FLOAT,初始值为GL_FLOAT。
	  normalized  指定当被访问时,固定点数据值是否应该被归一化(GL_TRUE)或者直接转换为固定点值(GL_FALSE)。
	  stride  指定连续顶点属性之间的偏移量。如果为0,那么顶点属性会被理解为:它们是紧密排列在一起的。初始值为0。
	  pointer 指定第一个组件在数组的第一个顶点属性中的偏移量。该数组与GL_ARRAY_BUFFER绑定,储存于缓冲区中。初始值为0;
	*/
	gl.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, 0, 0) //更新position值
	gl.DrawArrays(gl.TRIANGLES, 0, vertexCount)
	gl.DisableVertexAttribArray(position)

	debug.DrawFPS(c)
}
开发者ID:lovexiaov,项目名称:gomobileapp,代码行数:35,代码来源:main.go

示例8: draw

func draw(c event.Config) {
	secondsFromStart := time.Since(startTime) * 60 / time.Second
	now := clock.Time(secondsFromStart)

	currentBottomRight := geom.Point{c.Width, c.Height}
	if bottomRight == nil || currentBottomRight != *bottomRight {
		bottomRight = &currentBottomRight

		log.Printf("Device Sizing: %vx%v PixelsPerPt:%v",
			c.Width,
			c.Height,
			c.PixelsPerPt,
		)
	}

	if fullScene == nil {
		fullScene = setupScene(c.Width, c.Height, secondsFromStart)
	}

	gl.ClearColor(0, 0, 0, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	eng.Render(fullScene, now, c)
	debug.DrawFPS(c)
}
开发者ID:porty,项目名称:experiments,代码行数:25,代码来源:game.go

示例9: onDraw

func onDraw(c config.Event) {
	gl.ClearColor(1, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	debug.DrawFPS(c)
	DrawResult(c, <-speed_rate)
}
开发者ID:dr4ke616,项目名称:gospeedtest,代码行数:7,代码来源:main.go

示例10: onPaint

func onPaint(c size.Event) {
	gl.ClearColor(0, 0.3, 0.3, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.UseProgram(program)

	green += direction
	if green > 1 {
		green = 1
		direction = -direction
	}
	if green < 0.4 {
		green = 0.4
		direction = -direction
	}
	gl.Uniform4f(color, 0, green, 0, 1)

	gl.Uniform2f(offset, touchX/float32(c.WidthPx), touchY/float32(c.HeightPx))

	gl.BindBuffer(gl.ARRAY_BUFFER, buf)

	gl.BufferData(gl.ARRAY_BUFFER, triangleData, gl.STATIC_DRAW) // ?

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

	debug.DrawFPS(c)
}
开发者ID:plumbum,项目名称:go-samples,代码行数:30,代码来源:main.go

示例11: drawgl

//export drawgl
func drawgl(ctx uintptr) {
	// The call to lockContext loads the OpenGL context into
	// thread-local storage for use by the underlying GL calls
	// done in the user's Draw function. We need to stay on
	// the same thread throughout Draw, so we LockOSThread.
	runtime.LockOSThread()
	C.setContext(unsafe.Pointer(ctx))

	initGLOnce.Do(initGL)

	// TODO not here?
	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	if cb.Draw != nil {
		cb.Draw()
	}

	// TODO
	//C.unlockContext(ctx)

	// This may unlock the original main thread, but that's OK,
	// because by the time it does the thread has already entered
	// C.runApp, which won't give the thread up.
	runtime.UnlockOSThread()
}
开发者ID:Miaque,项目名称:mojo,代码行数:26,代码来源:darwin_arm.go

示例12: drawgl

//export drawgl
func drawgl(ctx C.GLintptr) {
	// The call to lockContext loads the OpenGL context into
	// thread-local storage for use by the underlying GL calls
	// done in the user's Draw function. We need to stay on
	// the same thread throughout Draw, so we LockOSThread.
	runtime.LockOSThread()
	C.lockContext(ctx)

	initGLOnce.Do(initGL)

	events.Lock()
	pending := events.pending
	events.pending = nil
	events.Unlock()
	for _, e := range pending {
		if cb.Touch != nil {
			cb.Touch(e)
		}
	}

	// TODO: is the library or the app responsible for clearing the buffers?
	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	if cb.Draw != nil {
		cb.Draw()
	}

	C.unlockContext(ctx)

	// This may unlock the original main thread, but that's OK,
	// because by the time it does the thread has already entered
	// C.runApp, which won't give the thread up.
	runtime.UnlockOSThread()
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:35,代码来源:darwin.go

示例13: windowDrawLoop

func windowDrawLoop(cb Callbacks, w *C.ANativeWindow, queue *C.AInputQueue) {
	C.createEGLWindow(w)

	// TODO: is the library or the app responsible for clearing the buffers?
	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	C.eglSwapBuffers(C.display, C.surface)

	if errv := gl.GetError(); errv != gl.NO_ERROR {
		log.Printf("GL initialization error: %s", errv)
	}

	geom.Width = geom.Pt(float32(C.windowWidth) / geom.PixelsPerPt)
	geom.Height = geom.Pt(float32(C.windowHeight) / geom.PixelsPerPt)

	for {
		processEvents(cb, queue)
		select {
		case <-windowDestroyed:
			return
		default:
			if cb.Draw != nil {
				cb.Draw()
			}
			C.eglSwapBuffers(C.display, C.surface)
		}
	}
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:28,代码来源:loop_android.go

示例14: onPaint

func onPaint(sz size.Event) {
	if scene == nil {
		loadScene(sz)
	}
	gl.ClearColor(1, 1, 1, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	now := clock.Time(time.Since(startTime) * 60 / time.Second)
	eng.Render(scene, now, sz)
}
开发者ID:tenntenn,项目名称:gomoxy,代码行数:9,代码来源:main.go

示例15: main

func main() {
	app.Run(app.Callbacks{
		Draw: func() {
			gl.ClearColor(0, 0, 1, 1) // blue
			gl.Clear(gl.COLOR_BUFFER_BIT)
		},
		Touch: func(e event.Touch) { fmt.Println(e) },
	})
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:9,代码来源:touch.go


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