示例#1
0
文件: main.go 项目: viru/berrybot
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)
}
示例#2
0
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)
}
示例#3
0
文件: main.go 项目: plixul/figura
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)

		}

	}

}
示例#4
0
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)
}
示例#5
0
func onPaint(glctx gl.Context, sz size.Event) {

	glctx.Viewport(0, 0, sz.WidthPx, sz.HeightPx)
	glctx.ClearColor(0.5, 0.5, 0.5, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	glctx.UseProgram(program)

	projectionMtx = mgl32.Perspective(45, float32(width)/float32(height), 0.1, 100)

	arcBallMtx := arcball.getMtx()

	glctx.UniformMatrix4fv(projection, projectionMtx[:])

	glctx.UniformMatrix4fv(view, arcBallMtx[:])

	glctx.BindBuffer(gl.ARRAY_BUFFER, triBuf)
	glctx.EnableVertexAttribArray(position)
	glctx.EnableVertexAttribArray(color)
	glctx.EnableVertexAttribArray(normals)

	vertSize := 4 * (coordsPerVertex + colorPerVertex + normalsPerVertex)

	glctx.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, vertSize, 0)
	glctx.VertexAttribPointer(color, colorPerVertex, gl.FLOAT, false, vertSize, 4*coordsPerVertex)
	glctx.VertexAttribPointer(normals, normalsPerVertex, gl.FLOAT, false, vertSize, 4*(coordsPerVertex+colorPerVertex))

	glctx.DepthMask(true)

	glctx.Uniform3fv(lightPos, light.Pos[:])
	glctx.Uniform3fv(lightIntensity, light.Intensities[:])

	for _, k := range piano.Keys {
		glctx.Uniform4fv(tint, k.Color[:])

		mtx := k.GetMtx()
		normMat := mtx.Mat3().Inv().Transpose()
		glctx.UniformMatrix3fv(normalMatrix, normMat[:])
		glctx.UniformMatrix4fv(model, mtx[:])
		glctx.DrawArrays(gl.TRIANGLES, 0, len(triangleData)/vertSize)
	}

	modelMtx := mgl32.Ident4()
	modelMtx = modelMtx.Mul4(mgl32.Translate3D(worldPos.X(), worldPos.Y(), worldPos.Z()))
	modelMtx = modelMtx.Mul4(mgl32.Scale3D(0.5, 0.5, 0.5))

	/*
		glctx.Uniform4fv(tint, red[:])
		// Disable depthmask so we dont get the pixel depth of the cursor cube
		glctx.DepthMask(false)
		glctx.UniformMatrix4fv(model, modelMtx[:])
		glctx.DepthMask(true)
	*/

	glctx.DisableVertexAttribArray(position)
	glctx.DisableVertexAttribArray(color)
	glctx.DisableVertexAttribArray(normals)

	fps.Draw(sz)
}
示例#6
0
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)
}
示例#7
0
func (buf *TextureFramebuffer) StartSample(ctx gl.Context) {
	buf.fbo.Bind(ctx, buf.withtex)
	ctx.GetIntegerv(int32v4, gl.VIEWPORT)
	ctx.Viewport(0, 0, buf.w, buf.h)
	ctx.ClearColor(0, 0, 0, 0)
	ctx.Clear(gl.COLOR_BUFFER_BIT)
}
示例#8
0
文件: main.go 项目: dskinner/material
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
}
示例#9
0
func onPaint(glctx gl.Context, sz size.Event) {
	glctx.ClearColor(0.2, 0.2, 0.2, 0.5)
	glctx.Clear(gl.DEPTH_BUFFER_BIT)
	glctx.Clear(gl.COLOR_BUFFER_BIT)

	glctx.UseProgram(program)

	board.Draw()
}
示例#10
0
文件: main.go 项目: kardianos/garage
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)
}
示例#11
0
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
		}
	}
}
示例#12
0
func onDraw(glctx gl.Context, sz size.Event) {
	select {
	case <-determined:
		if ok {
			glctx.ClearColor(0, 1, 0, 1)
		} else {
			glctx.ClearColor(1, 0, 0, 1)
		}
	default:
		glctx.ClearColor(0, 0, 0, 1)
	}
	glctx.Clear(gl.COLOR_BUFFER_BIT)
}
示例#13
0
文件: main.go 项目: vanadium/croupier
func onPaint(glctx gl.Context, sz size.Event, u *uistate.UIState) {
	if u.CurView == uistate.None {
		u.ScanChan = make(chan bool)
		go sync.ScanForSG(u.Ctx, u.ScanChan, u)
		view.LoadDiscoveryView(u)
	}
	glctx.ClearColor(1, 1, 1, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT)
	now := clock.Time(time.Since(u.StartTime) * 60 / time.Second)
	u.Eng.Render(u.Scene, now, sz)
	if u.Debug {
		fps.Draw(sz)
	}
}
示例#14
0
func onPaint(glctx gl.Context, sz size.Event) {
	//gl.Enable(gl.DEPTH_TEST)
	//gl.DepthFunc(gl.LESS)
	//清场
	glctx.ClearColor(1, 1, 1, 1) //设置背景颜色
	glctx.Clear(gl.COLOR_BUFFER_BIT)
	glctx.Clear(gl.DEPTH_BUFFER_BIT)

	//使用program
	glctx.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)
	glctx.UniformMatrix4fv(scan, []float32{
		touchLocX/float32(sz.WidthPt)*4 - 2, 0, 0, 0,
		0, touchLocY/float32(sz.HeightPt)*4 - 2, 0, 0,
		0, 0, 0, 0,
		0, 0, 0, 1,
	})
	/*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;
	*/

	glctx.BindBuffer(gl.ARRAY_BUFFER, positionbuf)
	glctx.EnableVertexAttribArray(position)
	defer glctx.DisableVertexAttribArray(position)//必须全部缓存导入完成后再关闭
	glctx.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, 0, 0) //导入position缓存
	glctx.DrawArrays(gl.TRIANGLES, 0, vertexCount)

	glctx.BindBuffer(gl.ARRAY_BUFFER, colorbuf)
	glctx.EnableVertexAttribArray(color)
	defer glctx.DisableVertexAttribArray(color)//必须全部缓存导入完成后再关闭
	glctx.VertexAttribPointer(color, colorsPerVertex, gl.FLOAT, false, 0, 0) //导入color缓存
	glctx.DrawArrays(gl.TRIANGLES, 0, vertexCount)



	fps.Draw(sz)
}
示例#15
0
func onPaint(glctx gl.Context, sz size.Event) {
	glctx.ClearColor(1, 0, 0, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT)
	glctx.UseProgram(program)
	green += 0.01
	if green > 1 {
		green = 0
	}
	glctx.Uniform4f(color, 0, green, 0, 1)
	glctx.Uniform2f(offset, touchX/float32(sz.WidthPx), touchY/float32(sz.HeightPx))
	glctx.BindBuffer(gl.ARRAY_BUFFER, buf)
	glctx.EnableVertexAttribArray(position)
	glctx.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, 0, 0)
	glctx.DrawArrays(gl.TRIANGLES, 0, vertexCount)
	glctx.DisableVertexAttribArray(position)
	fps.Draw(sz)
}
示例#16
0
func onPaint(glctx gl.Context, sz size.Event) {
	glctx.ClearColor(0.5, 0.5, 0.5, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT)

	glctx.UseProgram(frameData.Program)

	glctx.Uniform4f(frameData.Color, 0.5, 0.5, 0.5, 1)

	// Put ourselves in the +x/+y quadrant (upper right quadrant)
	glctx.Uniform2f(frameData.Offset, 0.0, 1.0)

	glctx.EnableVertexAttribArray(frameData.Position)
	manager.PaintLayers(sz, frameData)
	// End drawing
	glctx.DisableVertexAttribArray(frameData.Position)

}
示例#17
0
func (m *Module) draw(glctx gl.Context, sz size.Event, images *glutil.Images) {
	serverResponse := m.Network.Response()

	glctx.ClearColor(1, 1, 1, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT)

	var display render.Display
	display.Loaded = m.loaded
	if len(serverResponse.Predictions) > 0 {
		display.NextOK = true
		display.NextTrainMinutes = serverResponse.Predictions[0].Minutes
		display.TransitRouteName = fmt.Sprintf("%s (%s)", serverResponse.Stop.Route, serverResponse.Stop.Direction)
		if len(serverResponse.Predictions) > 1 {
			display.NextNextOK = true
			display.NextNextTrainMinutes = serverResponse.Predictions[1].Minutes
		}
		display.UpdatedSecondsAgo = int(time.Now().Sub(serverResponse.LastRefresh).Seconds())
		display.PredictionSource = serverResponse.Predictions[0].Source
	}
	m.Render.Display(display, sz, glctx, images)
}
示例#18
0
func onPaint(ctx gl.Context) {
	ctx.ClearColor(0, 0, 0, 1)
	ctx.Clear(gl.COLOR_BUFFER_BIT)

	pianowf.Prepare(1)
	switch sz.Orientation {
	case size.OrientationPortrait:
		pianowf.Paint(ctx, -1, -1, 2, 0.5)
		mixwf.Paint(ctx, -1, 0.25, 2, 0.5)
	default:
		pianowf.Paint(ctx, -1, -1, 2, 1)
		mixwf.Paint(ctx, -1, 0.25, 2, 0.5)
	}

	btnreverb.Paint(ctx)
	btnlowpass.Paint(ctx)
	btnmetronome.Paint(ctx)
	btnloop.Paint(ctx)
	btnsndbank.Paint(ctx)

	now := time.Now()
	fps = int(time.Second / now.Sub(lastpaint))
	lastpaint = now
}
示例#19
0
文件: spike.go 项目: pyros2097/spike
// This is the main rendering call that updates the current scene and all children in the scene
func appPaint(glctx gl.Context, sz size.Event, delta float32) {
	glctx.ClearColor(currentScene.BGColor.R, currentScene.BGColor.G, currentScene.BGColor.B, currentScene.BGColor.A)
	glctx.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	for _, child := range currentScene.Children {
		child.act(delta)
		child.draw(tempBatch, 1.0)
		if len(InputChannel) > 0 {
			for e := range InputChannel {
				if child.Input != nil {
					child.Input(child, e)
				}
				if len(InputChannel) == 0 {
					break
				}
			}
		}
	}

	glctx.UseProgram(program)

	green += 0.01
	if green > 1 {
		green = 0
	}
	glctx.Uniform4f(color, 0, green, 0, 1)

	glctx.Uniform2f(offset, touchX/float32(sz.WidthPx), touchY/float32(sz.HeightPx))

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

	fps.Draw(sz)
}
示例#20
0
文件: testapp.go 项目: 2722/lantern
func main() {
	app.Main(func(a app.App) {
		var (
			glctx   gl.Context
			visible bool
		)

		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 := a.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					comm.Send("lifecycle_visible")
					sendPainting = true
					visible = true
					glctx, _ = e.DrawContext.(gl.Context)
				case lifecycle.CrossOff:
					comm.Send("lifecycle_not_visible")
					visible = false
				}
			case size.Event:
				comm.Send("size", e.PixelsPerPt, e.Orientation)
			case paint.Event:
				if visible {
					if color == "red" {
						glctx.ClearColor(1, 0, 0, 1)
					} else {
						glctx.ClearColor(0, 1, 0, 1)
					}
					glctx.Clear(gl.COLOR_BUFFER_BIT)
					a.Publish()
				}
				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
					// Send a paint event so the screen gets redrawn.
					a.Send(paint.Event{})
				}
			}
		}
	})
}
示例#21
0
func (self *window) run() {
	var glctx gl.Context
	var frame geom.Size
	var scale float64

	defer close(self.events)

	for v := range self.app.Events() {
		switch e := v.(type) {
		default:
			// This is none of the events that we know the mobile package should send,
			// probably a custom event from the application so we simply forward it.
			self.events <- v

		case paint.Event:
			if glctx != nil {
				// Always clear the content before redrawing so we don't leak left overs
				// of the video buffer.
				glctx.ClearColor(0, 0, 0, 1)
				glctx.Clear(gl.COLOR_BUFFER_BIT)
				gc := newGraphicContext(self.app, glctx)

				self.events <- event.Redraw{
					GC:       gc,
					Clip:     geom.Rect{W: frame.W, H: frame.H},
					External: e.External,
				}

				gc.join.Wait()
			}

		case size.Event:
			w := float64(e.WidthPt)
			h := float64(e.HeightPt)
			d := float64(e.PixelsPerPt)

			if w != frame.W || h != frame.H || d != scale {
				frame.W = w
				frame.H = h
				scale = d

				self.events <- event.ChangeScreen{
					Bounds: geom.Rect{W: frame.W, H: frame.H},
					Scale:  scale,
				}

				self.events <- event.Move{}

				self.events <- event.Resize{
					Size: frame,
				}
			}

		case lifecycle.Event:
			if e.To == lifecycle.StageDead {
				self.events <- event.Close{}
				return
			}

			switch e.Crosses(lifecycle.StageVisible) {
			case lifecycle.CrossOn:
				// The app doesn't send a paint event when it starts so we force
				// it here to trigger the first drawing of the newly created
				// window.
				glctx = e.DrawContext.(gl.Context)
				self.app.Send(paint.Event{External: true})
				self.events <- event.Focus{Focused: true}

			case lifecycle.CrossOff:
				glctx = nil
				self.events <- event.Focus{Focused: false}
			}
		}
	}

	// Unsure under which condition the events channel could get closed before a
	// lifecycle event indicating the app is going away but just in case we send
	// a close event before returning.
	self.events <- event.Close{}
}