Exemple #1
0
func onStart(glctx gl.Context, u *uistate.UIState) {
	flag.Set("v23.credentials", "/sdcard/credentials")
	vlog.Log.Configure(vlog.OverridePriorConfiguration(true), vlog.LogToStderr(true))
	vlog.Log.Configure(vlog.OverridePriorConfiguration(true), vlog.Level(0))
	ctx, shutdown := v23.Init()
	u.Shutdown = shutdown
	u.Ctx = ctx
	u.Service = syncbase.NewService(util.MountPoint + "/croupier/" + util.SBName)
	namespace := v23.GetNamespace(u.Ctx)
	allAccess := access.AccessList{In: []security.BlessingPattern{"..."}}
	permissions := access.Permissions{
		"Admin":   allAccess,
		"Write":   allAccess,
		"Read":    allAccess,
		"Resolve": allAccess,
		"Debug":   allAccess,
	}
	namespace.SetPermissions(u.Ctx, util.MountPoint, permissions, "")
	namespace.SetPermissions(u.Ctx, util.MountPoint+"/croupier", permissions, "")
	u.Service.SetPermissions(u.Ctx, permissions, "")
	u.Images = glutil.NewImages(glctx)
	fps = debug.NewFPS(u.Images)
	u.Eng = glsprite.Engine(u.Images)
	u.Texs = texture.LoadTextures(u.Eng)
	u.CurTable = table.InitializeGame(u.NumPlayers, u.Texs)
	sound.InitPlayers(u)
	sync.CreateTables(u)
	// Create watch stream to update game state based on Syncbase updates
	go sync.UpdateSettings(u)
}
Exemple #2
0
func onStart(glctx gl.Context) {
	var err error
	program, err = glutil.CreateProgram(glctx, vertexShader, fragmentShader)
	if err != nil {
		log.Printf("[ERR] Failed creating GL program: %v", err)
		return
	}

	buf = glctx.CreateBuffer()
	glctx.BindBuffer(gl.ARRAY_BUFFER, buf)
	glctx.BufferData(gl.ARRAY_BUFFER, triangleData, gl.STATIC_DRAW)

	position = glctx.GetAttribLocation(program, "position")
	color = glctx.GetUniformLocation(program, "color")
	offset = glctx.GetUniformLocation(program, "offset")

	images = glutil.NewImages(glctx)
	fps = debug.NewFPS(images)

	statusFont, statusFace, err = exfont.LoadAsset("Tuffy.ttf", statusFaceOpt)
	if err != nil {
		log.Printf("[ERR] Failed to load status font: %v", err)
	}
	statusPainter = rexdemo.NewStatusPainter(demo, statusFont, _color.White, images)
}
Exemple #3
0
func onStart(glctx gl.Context) {
	var err error
	program, err = glutil.CreateProgram(glctx, vertexShader, fragmentShader)
	if err != nil {
		log.Printf("[ERR] Failed creating GL program: %v", err)
		return
	}

	buf = glctx.CreateBuffer()
	glctx.BindBuffer(gl.ARRAY_BUFFER, buf)
	glctx.BufferData(gl.ARRAY_BUFFER, triangleData, gl.STATIC_DRAW)

	position = glctx.GetAttribLocation(program, "position")
	color = glctx.GetUniformLocation(program, "color")
	offset = glctx.GetUniformLocation(program, "offset")

	images = glutil.NewImages(glctx)
	fps = debug.NewFPS(images)

	statusFont, statusFace, err = exfont.LoadAsset("Tuffy.ttf", statusFaceOpt)
	if err != nil {
		log.Printf("[ERR] Failed to load status font: %v", err)
	}
	statusPainter = rexdemo.NewStatusPainter(demo, statusFont, statusBG, images)

	ifaces, err := net.Interfaces()
	if err != nil {
		log.Printf("[ERR] Failed to retreived interfaces")
	} else {
		log.Printf("[DEBUG] %d network interfaces", len(ifaces))
		for _, iface := range ifaces {
			log.Printf("[DEBUG] IFACE %d %s", iface.Index, iface.Name)
		}
	}
}
Exemple #4
0
func NewGLDebug(ctx gl.Context) *GLDebug {
	if ctx == nil {
		return nil
	}
	images := glutil.NewImages(ctx)
	return &GLDebug{
		ctx:    ctx,
		images: images,
		fps:    debug.NewFPS(images),
	}
}
Exemple #5
0
func (self *GLPeer) Initialize(in_glctx gl.Context) {
	LogDebug("IN")
	self.glctx = in_glctx

	// transparency of png
	self.glctx.Enable(gl.BLEND)
	self.glctx.BlendEquation(gl.FUNC_ADD)
	self.glctx.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	self.images = glutil.NewImages(in_glctx)
	self.fps = debug.NewFPS(self.images)
	self.initEng()
	LogDebug("OUT")
}
Exemple #6
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)
}
Exemple #7
0
func onStart(glctx gl.Context) {
	var err error
	program, err = glutil.CreateProgram(glctx, vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}
	buf = glctx.CreateBuffer()
	glctx.BindBuffer(gl.ARRAY_BUFFER, buf)
	glctx.BufferData(gl.ARRAY_BUFFER, triangleData, gl.STATIC_DRAW)
	position = glctx.GetAttribLocation(program, "position")
	color = glctx.GetUniformLocation(program, "color")
	offset = glctx.GetUniformLocation(program, "offset")
	images = glutil.NewImages(glctx)
	fps = debug.NewFPS(images)
}
Exemple #8
0
func onStart(glctx gl.Context) {
	var err error
	program, err = glutil.CreateProgram(glctx, vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	glctx.Enable(gl.DEPTH_TEST)

	triBuf = glctx.CreateBuffer()
	glctx.BindBuffer(gl.ARRAY_BUFFER, triBuf)
	glctx.BufferData(gl.ARRAY_BUFFER, triangleData, gl.STATIC_DRAW)

	position = glctx.GetAttribLocation(program, "vPos")
	color = glctx.GetAttribLocation(program, "vCol")
	normals = glctx.GetAttribLocation(program, "vNorm")

	projection = glctx.GetUniformLocation(program, "proj")
	view = glctx.GetUniformLocation(program, "view")
	model = glctx.GetUniformLocation(program, "model")
	tint = glctx.GetUniformLocation(program, "tint")
	normalMatrix = glctx.GetUniformLocation(program, "normalMatrix")
	lightIntensity = glctx.GetUniformLocation(program, "light.intensities")
	lightPos = glctx.GetUniformLocation(program, "light.position")

	arcball = NewArcBall(mgl32.Vec3{0, 0, 0}, mgl32.Vec3{0, 10, 10}, mgl32.Vec3{0, 1, 0})

	white = mgl32.Vec4{1.0, 1.0, 1.0, 1.0}
	red = mgl32.Vec4{1.0, 0.0, 0.0, 1.0}

	lastUpdate = time.Now()

	images = glutil.NewImages(glctx)
	fps = debug.NewFPS(images)

	err = al.OpenDevice()
	if err != nil {
		log.Printf("Err: %+v", err)
	}
	al.SetListenerPosition(al.Vector{0, 0, 0})
	al.SetListenerGain(1.0)
	piano = NewPiano()
}
Exemple #9
0
func onStart(glctx gl.Context) {
	var err error
	program, err = glutil.CreateProgram(glctx, vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	triangleData = genCircleTriangles(0.0, 0.0, 0.5)

	buf = glctx.CreateBuffer()

	position = glctx.GetAttribLocation(program, "position")
	color = glctx.GetUniformLocation(program, "color")
	offset = glctx.GetUniformLocation(program, "offset")

	images = glutil.NewImages(glctx)
	fps = debug.NewFPS(images)
}
Exemple #10
0
func appStart(glctx gl.Context) {
	println("Starting")
	program, err = glutil.CreateProgram(glctx, vertexShader, fragmentShader)
	if err != nil {
		panic("error creating GL program: " + err.Error())
		return
	}

	buf = glctx.CreateBuffer()
	glctx.BindBuffer(gl.ARRAY_BUFFER, buf)
	glctx.BufferData(gl.ARRAY_BUFFER, triangleData, gl.STATIC_DRAW)

	position = glctx.GetAttribLocation(program, "position")
	color = glctx.GetUniformLocation(program, "color")
	offset = glctx.GetUniformLocation(program, "offset")
	images = glutil.NewImages(glctx)
	fps = debug.NewFPS(images)

	SetScene(currentScene.Name)
}
Exemple #11
0
func (e *engine) Start(glctx gl.Context) error {
	e.glctx = glctx
	e.shaders = loader.ShaderLoader(glctx)
	e.textures = loader.TextureLoader(glctx)

	err := e.world.Start(WorldContext{
		Bindings: e.bindings,
		Shaders:  e.shaders,
		Textures: e.textures,
	})
	if err != nil {
		return err
	}

	e.camera.MoveTo(e.followOffset)
	e.camera.RotateTo(e.world.Focus().Position())

	// Toggle keys
	e.bindings.On(control.KeyPause, func(_ control.KeyBinding) {
		e.paused = !e.paused
		log.Println("Paused:", e.paused)

		if e.gameover {
			e.gameover = false
			e.world.Reset()
		}
	})
	e.bindings.On(control.KeyCameraFollow, func(_ control.KeyBinding) {
		e.following = !e.following
		log.Println("Following:", e.following)
	})

	e.started = time.Now()
	e.lastTick = e.started

	e.images = glutil.NewImages(glctx)
	e.fps = debug.NewFPS(e.images)

	log.Println("Starting: ", e.world.String())
	return nil
}
Exemple #12
0
func startDebugLayer(glctx gl.Context) debugLayer {
	layer := debugLayer{}
	layer.images = glutil.NewImages(glctx)
	layer.fps = debug.NewFPS(layer.images)
	return layer
}
Exemple #13
0
func onStart(glctx gl.Context) {
	images = glutil.NewImages(glctx)
	fps = debug.NewFPS(images)
	loadScene(sceneId)
}
Exemple #14
0
func onStart(glctx gl.Context) {
	images = glutil.NewImages(glctx)
	fps = debug.NewFPS(images)
	eng = glsprite.Engine(images)
	loadScene()
}
Exemple #15
0
func runLoop(defaultScene Scene, headless bool) {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)
	go func() {
		<-c
		closeEvent()
	}()

	app.Main(func(a app.App) {
		var (
			images *glutil.Images
			fps    *debug.FPS
		)

		for e := range a.Events() {
			switch e := a.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					Gl = gl.NewContext(e.DrawContext)
					RunPreparation(defaultScene)

					images = glutil.NewImages(e.DrawContext.(mobilegl.Context))
					fps = debug.NewFPS(images)

					// Let the device know we want to start painting :-)
					a.Send(paint.Event{})
				case lifecycle.CrossOff:
					closeEvent()
				}

			case size.Event:
				sz = e
				windowWidth = float32(sz.WidthPx)
				windowHeight = float32(sz.HeightPx)
				Gl.Viewport(0, 0, sz.WidthPx, sz.HeightPx)
			case paint.Event:
				if e.External {
					// As we are actively painting as fast as
					// we can (usually 60 FPS), skip any paint
					// events sent by the system.
					continue
				}

				RunIteration()
				if closeGame {
					break
				}

				fps.Draw(sz)

				// Reset mouse if needed
				if Mouse.Action == RELEASE {
					Mouse.Action = NEUTRAL
				}

				a.Publish() // same as SwapBuffers

				// Drive the animation by preparing to paint the next frame
				// after this one is shown. - FPS is ignored here!
				a.Send(paint.Event{})
			case touch.Event:
				Mouse.X = e.X
				Mouse.Y = e.Y
				switch e.Type {
				case touch.TypeBegin:
					Mouse.Action = PRESS
				case touch.TypeMove:
					Mouse.Action = MOVE
				case touch.TypeEnd:
					Mouse.Action = RELEASE
				}
			}
		}
	})
}
Exemple #16
0
func onStart(glctx gl.Context) {
	var err error
	program, err = glutil.CreateProgram(glctx, vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	/*opengl中三种变量
	uniform变量是外部application程序传递给(vertex和fragment)shader的变量。因此它是application通过函数glUniform**()函数赋值的。
	在(vertex和fragment)shader程序内部,uniform变量就像是C语言里面的常量(const ),它不能被shader程序修改。(shader只能用,不能改)

	attribute变量是只能在vertex shader中使用的变量。(它不能在fragment shader中声明attribute变量,也不能被fragment shader中使用)
	一般用attribute变量来表示一些顶点的数据,如:顶点坐标,法线,纹理坐标,顶点颜色等。
	在application中,一般用函数glBindAttribLocation()来绑定每个attribute变量的位置,然后用函数glVertexAttribPointer()为每个attribute变量赋值。

	varying变量是vertex和fragment shader之间做数据传递用的。一般vertex shader修改varying变量的值,然后fragment shader使用该varying变量的值。
	因此varying变量在vertex和fragment shader二者之间的声明必须是一致的。application不能使用此变量。
	*/

	position = glctx.GetAttribLocation(program, "position") //获取位置对象(索引)
	color = glctx.GetAttribLocation(program, "color")       // 获取颜色对象(索引)
	scan = glctx.GetUniformLocation(program, "scan")        // 获取缩放对象(索引)

	/*
	VBO允许usage标示符取以下9种值:

		gl.STATIC_DRAW
		gl.STATIC_READ
		gl.STATIC_COPY

		gl.DYNAMIC_DRAW
		gl.DYNAMIC_READ
		gl.DYNAMIC_COPY

		gl.STREAM_DRAW
		gl.STREAM_READ
		gl.STREAM_COPY

	"Static”意味着VBO中的数据不会被改变(一次修改,多次使用),
	"dynamic”意味着数据可以被频繁修改(多次修改,多次使用),
	"stream”意味着数据每帧都不同(一次修改,一次使用)。

	"Draw”意味着数据将会被送往GPU进行绘制,
	"read”意味着数据会被用户的应用读取,
	"copy”意味着数据会被用于绘制和读取。

	注意在使用VBO时,只有draw是有效的,而copy和read主要将会在像素缓冲区(PBO)和帧缓冲区(FBO)中发挥作用。
	系统会根据usage标示符为缓冲区对象分配最佳的存储位置,比如系统会为gl.STATIC_DRAW和gl.STREAM_DRAW分配显存,
	gl.DYNAMIC_DRAW分配AGP,以及任何_READ_相关的缓冲区对象都会被存储到系统或者AGP中因为这样数据更容易读写
	 */
	positionbuf = glctx.CreateBuffer()
	glctx.BindBuffer(gl.ARRAY_BUFFER, positionbuf)
	glctx.BufferData(gl.ARRAY_BUFFER, triangleData, gl.STATIC_DRAW)

	colorbuf = glctx.CreateBuffer()
	glctx.BindBuffer(gl.ARRAY_BUFFER, colorbuf)
	glctx.BufferData(gl.ARRAY_BUFFER, colorData, gl.STATIC_DRAW)

	images = glutil.NewImages(glctx)
	fps = debug.NewFPS(images)

	// fmt.Println(position.String(),color.String(),offset.String())//Attrib(0) Uniform(1) Uniform(0)
	// TODO(crawshaw): the debug package needs to put GL state init here
	// Can this be an event.Register call now??
}