示例#1
0
文件: testapp.go 项目: rockxcn/mobile
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
				}
			}
		}
	})
}
示例#2
0
文件: main.go 项目: xfong/gocl
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()
}
示例#3
0
文件: main.go 项目: rockxcn/mobile
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)
}
示例#4
0
文件: main.go 项目: guanhuihui/mobile
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)
}
示例#5
0
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()
			}
		}
	})
}
示例#6
0
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)
}
示例#7
0
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)
}
示例#8
0
文件: game.go 项目: porty/experiments
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)
}
示例#9
0
func onDraw(c config.Event) {
	gl.ClearColor(1, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	debug.DrawFPS(c)
	DrawResult(c, <-speed_rate)
}
示例#10
0
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)
}
示例#11
0
文件: darwin_arm.go 项目: Miaque/mojo
//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()
}
示例#12
0
//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()
}
示例#13
0
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)
		}
	}
}
示例#14
0
文件: main.go 项目: tenntenn/gomoxy
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)
}
示例#15
0
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) },
	})
}
示例#16
0
文件: main.go 项目: handong890/mobile
func draw(c event.Config) {
	if scene == nil {
		loadScene(c)
	}
	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, c)
	debug.DrawFPS(c)
}
示例#17
0
文件: main.go 项目: tendermint/mobile
func onPaint() {
	if scene == nil {
		loadScene()
	}
	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, cfg)
	debug.DrawFPS(cfg)
}
示例#18
0
func (e *Engine) Draw(c size.Event) {

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	gl.ClearColor(0.5, 0.8, 0.8, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(e.shader.program)

	gl.Uniform3fv(e.shader.lightdir, []float32{0.5, 0.6, 0.7})

	m := mgl32.Perspective(1.3, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projectionmatrix, m[:])

	eye := mgl32.Vec3{0, 0, 0.2}
	center := mgl32.Vec3{0, 0, 0}
	up := mgl32.Vec3{0, 1, 0}

	m = mgl32.LookAtV(eye, center, up)
	gl.UniformMatrix4fv(e.shader.viewmatrix, m[:])

	m = mgl32.HomogRotate3D((e.touchx/float32(c.WidthPt)-0.5)*6.28, mgl32.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.modelmatrix, m[:])

	m = mgl32.HomogRotate3D((e.touchx/float32(c.WidthPt)-0.5)*6.28, mgl32.Vec3{0, -1, 0})
	gl.UniformMatrix4fv(e.shader.lightmatrix, m[:])

	coordsPerVertex := 3
	for _, obj := range e.shape.Objs {
		gl.BindBuffer(gl.ARRAY_BUFFER, obj.coord)
		gl.EnableVertexAttribArray(e.shader.vertCoord)
		gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 12, 0)

		texCoordsPerVertex := 2
		gl.BindBuffer(gl.ARRAY_BUFFER, obj.uvcoord)
		gl.EnableVertexAttribArray(e.shader.texcoord)
		gl.VertexAttribPointer(e.shader.texcoord, texCoordsPerVertex, gl.FLOAT, false, 8, 0)

		gl.BindBuffer(gl.ARRAY_BUFFER, obj.normal)
		gl.EnableVertexAttribArray(e.shader.normal)
		gl.VertexAttribPointer(e.shader.normal, 3, gl.FLOAT, false, 12, 0)

		gl.BindTexture(gl.TEXTURE_2D, obj.tex)

		gl.DrawArrays(gl.TRIANGLES, 0, obj.vcount)

		gl.DisableVertexAttribArray(e.shader.texcoord)
		gl.DisableVertexAttribArray(e.shader.normal)
		gl.DisableVertexAttribArray(e.shader.vertCoord)
	}

	debug.DrawFPS(c)
}
示例#19
0
func (e *Engine) Draw(c size.Event) {

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	gl.ClearColor(0.2, 0.2, 0.2, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(e.shader.program)

	m := mgl32.Perspective(0.785, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projection, m[:])

	eye := mgl32.Vec3{0, 0, 8}
	center := mgl32.Vec3{0, 0, 0}
	up := mgl32.Vec3{0, 1, 0}

	m = mgl32.LookAtV(eye, center, up)
	gl.UniformMatrix4fv(e.shader.view, m[:])

	m = mgl32.HomogRotate3D(float32(e.touchLoc.X/c.WidthPt-0.5)*3.14*2, mgl32.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.modelx, m[:])

	m = mgl32.HomogRotate3D(float32(e.touchLoc.Y/c.HeightPt-0.5)*3.14, mgl32.Vec3{1, 0, 0})
	gl.UniformMatrix4fv(e.shader.modely, m[:])

	coordsPerVertex := 3
	for _, obj := range e.shape.Objs {
		gl.BindBuffer(gl.ARRAY_BUFFER, obj.coord)
		gl.EnableVertexAttribArray(e.shader.vertCoord)

		gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 12, 0)

		if obj.useuv == true {
			gl.Uniform1i(e.shader.useuv, 1)
			texCoordsPerVertex := 2
			gl.BindBuffer(gl.ARRAY_BUFFER, obj.uvcoord)
			gl.EnableVertexAttribArray(e.shader.vertTexCoord)
			gl.VertexAttribPointer(e.shader.vertTexCoord, texCoordsPerVertex, gl.FLOAT, false, 8, 0)

			gl.BindTexture(gl.TEXTURE_2D, obj.tex)
		} else {
			gl.Uniform1i(e.shader.useuv, 0)
			gl.Uniform4f(e.shader.color, obj.color[0], obj.color[1], obj.color[2], obj.color[3])
		}
		gl.DrawArrays(gl.TRIANGLES, 0, obj.vcount)
		if obj.useuv {
			gl.DisableVertexAttribArray(e.shader.vertTexCoord)
		}
		gl.DisableVertexAttribArray(e.shader.vertCoord)
	}

	debug.DrawFPS(c)
}
示例#20
0
文件: main.go 项目: shazow/linerage3d
func (e *Engine) Draw(c config.Event) {
	now := time.Now()
	interval := now.Sub(e.lastTick)
	e.lastTick = now

	// Handle key presses
	var camDelta mgl.Vec3
	if e.bindings.Pressed(KeyCamForward) {
		camDelta[2] -= moveSpeed
	}
	if e.bindings.Pressed(KeyCamReverse) {
		camDelta[2] += moveSpeed
	}
	if e.bindings.Pressed(KeyCamLeft) {
		camDelta[0] -= moveSpeed
	}
	if e.bindings.Pressed(KeyCamRight) {
		camDelta[0] += moveSpeed
	}
	if e.bindings.Pressed(KeyCamUp) {
		e.camera.MoveTo(e.camera.Position().Add(mgl.Vec3{0, moveSpeed, 0}))
	}
	if e.bindings.Pressed(KeyCamDown) {
		e.camera.MoveTo(e.camera.Position().Add(mgl.Vec3{0, -moveSpeed, 0}))
	}
	if camDelta[0]+camDelta[1]+camDelta[2] != 0 {
		e.following = false
		e.camera.Move(camDelta)
	} else if e.following {
		pos := e.world.Focus().Position()
		e.camera.Lerp(pos.Add(e.followOffset), pos, 0.1)
	}

	gl.ClearColor(0, 0, 0, 1)
	//gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.Enable(gl.DEPTH_TEST)

	//gl.Disable(gl.CULL_FACE)
	//gl.DepthFunc(gl.LESS)
	//gl.SampleCoverage(4.0, false)

	if !e.paused {
		err := e.world.Tick(interval)
		if err != nil {
			e.paused = true
			e.gameover = true
		}
	}
	e.scene.Draw(e.camera)

	gl.Disable(gl.DEPTH_TEST)
	debug.DrawFPS(c)
}
示例#21
0
func onPaint(sz size.Event) {
	gl.ClearColor(rgb(156), rgb(39), rgb(176), 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	var rotationMatrix = []float32{
		f32.Cos(-alpha), -f32.Sin(-alpha), 0.0,
		f32.Sin(-alpha), f32.Cos(-alpha), 0.0,
		0.0, 0.0, 1.0,
	}

	gl.UseProgram(program)
	// setting color
	gl.Uniform4f(color, rgb(255), rgb(255), rgb(255), 1)
	gl.UniformMatrix3fv(matrixId, rotationMatrix)
	gl.Uniform1f(resolutionId, resIndex)

	gl.BindBuffer(gl.ARRAY_BUFFER, swasBuffer)

	gl.EnableVertexAttribArray(position)
	gl.VertexAttribPointer(position, 3, gl.FLOAT, false, 0, 0)
	gl.DrawArrays(gl.LINES, 0, 16)
	gl.DisableVertexAttribArray(position)

	gl.UseProgram(texProgram)
	// setting color
	gl.Uniform4f(color2, rgb(130), rgb(50), rgb(80), 1)
	gl.Uniform1f(resolutionId2, resIndex)
	gl.UniformMatrix3fv(matrixId2, rotationMatrix)

	gl.BindBuffer(gl.ARRAY_BUFFER, quadBuffer)
	gl.EnableVertexAttribArray(position2)
	gl.VertexAttribPointer(position2, 3, gl.FLOAT, false, 0, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, quadTexBuffer)
	gl.EnableVertexAttribArray(textureCoords)
	gl.VertexAttribPointer(textureCoords, 2, gl.FLOAT, false, 0, 0)

	gl.Uniform1i(gl.GetUniformLocation(texProgram, "myTexture"), 0)
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, textureId)

	gl.DrawArrays(gl.TRIANGLES, 0, 6)
	gl.DisableVertexAttribArray(position2)
	gl.DisableVertexAttribArray(textureCoords)

	if spin == true {
		alpha += 0.1
	}

	if alpha >= 360 {
		alpha = 0.0
	}

}
示例#22
0
文件: main.go 项目: acsellers/ofs
func onPaint(e size.Event) {
	if scene == nil {
		loadScene()
	}
	gl.ClearColor(1, 1, 1, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	now := clock.Time(time.Since(start) * 60 / time.Second)
	eng.Render(scene, now, e)
	if *dbg {
		debug.DrawFPS(e)
	}
}
示例#23
0
func (video *Video) initGL() {
	log.Print("Initing")
	video.fpsmanager = gfx.NewFramerate()
	video.fpsmanager.SetFramerate(60)

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)

	log.Print("Creating program")
	video.prog = createProgram(vertShaderSrcDef, fragShaderSrcDef)
	log.Print("Attrib loc 1")
	posAttrib := attribLocation(video.prog, "vPosition")
	log.Print("Attrib loc 2")
	texCoordAttr := attribLocation(video.prog, "vTexCoord")
	log.Print("Uniform loc 1")
	paletteLoc := uniformLocation(video.prog, "palette")
	log.Print("Uniform loc 2")
	video.textureUni = uniformLocation(video.prog, "texture")

	log.Print("Gen Texture")
	video.texture = genTexture()
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, video.texture)

	log.Print("TexParam")
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

	gl.UseProgram(video.prog)
	gl.EnableVertexAttribArray(posAttrib)
	gl.EnableVertexAttribArray(texCoordAttr)

	gl.Uniform3iv(paletteLoc, nes.SPaletteRgb)

	log.Print("VertBO")
	vertVBO := genBuffer()
	checkGLError()
	gl.BindBuffer(gl.ARRAY_BUFFER, vertVBO)
	verts := f32.Bytes(binary.LittleEndian, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0)
	gl.BufferData(gl.ARRAY_BUFFER, verts, gl.STATIC_DRAW)

	textCoorBuf := genBuffer()
	checkGLError()
	gl.BindBuffer(gl.ARRAY_BUFFER, textCoorBuf)
	texVerts := f32.Bytes(binary.LittleEndian, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0)
	gl.BufferData(gl.ARRAY_BUFFER, texVerts, gl.STATIC_DRAW)

	gl.VertexAttribPointer(posAttrib, 2, gl.FLOAT, false, 0, 0)
	gl.VertexAttribPointer(texCoordAttr, 2, gl.FLOAT, false, 0, 0)
	log.Print("Started")
}
示例#24
0
func onPaint(sz size.Event) {
	if scene == nil {
		images = glutil.NewImages()
		fps = debug.NewFPS(images)
		eng = glsprite.Engine(images)
		loadScene()
	}
	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)
	fps.Draw(sz)
}
示例#25
0
func onPaint(c config.Event) {
	if !started {
		touchLoc = geom.Point{c.Width / 2, c.Height / 2}
		started = true
	}
	if scene == nil {
		loadScene()
	}
	gl.ClearColor(242/255.0, 240/255.0, 217/255.0, 1) // gophercon bg color
	gl.Clear(gl.COLOR_BUFFER_BIT)

	now := clock.Time(time.Since(startClock) * 60 / time.Second)
	eng.Render(scene, now, c)
	debug.DrawFPS(c)
}
示例#26
0
func draw(c event.Config) {
	if scene == nil {
		loadScene(c)
	}

	now := clock.Time(time.Since(startClock) * 60 / time.Second)
	if now == lastClock {
		return
	}
	lastClock = now

	gl.ClearColor(1, 1, 1, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	eng.Render(scene, now, c)
	//debug.DrawFPS()
}
示例#27
0
func (e *Engine) Draw(c size.Event) {
	since := time.Now().Sub(e.started)
	//gl.Enable()

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

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

	gl.UseProgram(e.shader.program)

	m := mgl32.Perspective(0.785, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projection, m[:])

	eye := mgl32.Vec3{3, 3, 3}
	center := mgl32.Vec3{0, 0, 0}
	up := mgl32.Vec3{0, 1, 0}

	m = mgl32.LookAtV(eye, center, up)
	gl.UniformMatrix4fv(e.shader.view, m[:])

	m = mgl32.HomogRotate3D(float32(since.Seconds()), mgl32.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.model, m[:])

	gl.BindBuffer(gl.ARRAY_BUFFER, e.shape.buf)

	coordsPerVertex := 3
	texCoordsPerVertex := 2
	vertexCount := len(cubeData) / (coordsPerVertex + texCoordsPerVertex)

	gl.EnableVertexAttribArray(e.shader.vertCoord)
	gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 20, 0) // 4 bytes in float, 5 values per vertex

	gl.EnableVertexAttribArray(e.shader.vertTexCoord)
	gl.VertexAttribPointer(e.shader.vertTexCoord, texCoordsPerVertex, gl.FLOAT, false, 20, 12)

	gl.BindTexture(gl.TEXTURE_2D, e.shape.texture)

	gl.DrawArrays(gl.TRIANGLES, 0, vertexCount)

	gl.DisableVertexAttribArray(e.shader.vertCoord)

	debug.DrawFPS(c)
}
示例#28
0
func (e *Engine) Draw(c event.Config) {
	since := time.Now().Sub(e.started)

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

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

	gl.UseProgram(e.shader.program)

	// Setup MVP
	var m mgl.Mat4
	m = mgl.Perspective(0.785, float32(c.Width/c.Height), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projection, m[:])

	m = mgl.LookAtV(
		mgl.Vec3{3, 3, 3}, // eye
		mgl.Vec3{0, 0, 0}, // center
		mgl.Vec3{0, 1, 0}, // up
	)
	gl.UniformMatrix4fv(e.shader.view, m[:])

	m = mgl.HomogRotate3D(float32(since.Seconds()), mgl.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.model, m[:])

	// Draw our shape
	gl.BindBuffer(gl.ARRAY_BUFFER, e.shape.buf)

	gl.EnableVertexAttribArray(e.shader.vertCoord)
	gl.VertexAttribPointer(e.shader.vertCoord, e.shape.coordsPerVertex, gl.FLOAT, false, 20, 0) // 4 bytes in float, 5 values per vertex

	gl.EnableVertexAttribArray(e.shader.vertTexCoord)
	gl.VertexAttribPointer(e.shader.vertTexCoord, e.shape.texCoordsPerVertex, gl.FLOAT, false, 20, 12)

	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, e.shape.texture)

	gl.DrawArrays(gl.TRIANGLES, 0, e.shape.vertexCount)

	gl.DisableVertexAttribArray(e.shader.vertCoord)

	//debug.DrawFPS(c)
}
示例#29
0
func onPaint(c config.Event) {
	gl.ClearColor(1, 1, 1, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.UseProgram(program)

	gl.Uniform4f(color, 0.3, 0.3, 0.3, 1) // color
	// position
	x := float32(touchLoc.X / c.Width)
	y := float32(touchLoc.Y / c.Height)
	gl.Uniform2f(offset, x, y)

	gl.BindBuffer(gl.ARRAY_BUFFER, buf)
	gl.EnableVertexAttribArray(position)
	gl.VertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0)
	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)
	gl.DisableVertexAttribArray(position)
}
示例#30
0
func draw() {
	if texs == nil {
		texs = loadTextures()
	}

	h := app.GetConfig().Height
	button = float32(h / 5)
	offset = button / 2

	now := clock.Time(time.Since(startClock) * 60 / time.Second)
	if now == lastClock {
		// TODO: figure out how to limit draw callbacks to 60Hz instead of
		// burning the CPU as fast as possible.
		// TODO: (relatedly??) sync to vblank?
		return
	}
	lastClock = now
	gl.ClearColor(1, 1, 1, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	cfg := app.GetConfig()
	board = &sprite.Node{}
	eng.Register(board)
	eng.SetTransform(board, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})

	n := newNode()
	eng.SetSubTex(n, texs[texBG])
	eng.SetTransform(n, f32.Affine{
		{float32(cfg.Width), 0, 0},
		{0, float32(cfg.Height), 0},
	})
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			drawButton(i, j)
		}
	}

	drawBrandModel()
	eng.Render(board, now)
}