func main() { flag.Parse() v = game.NewVault() v.PlaceRoom(9, 0, 1) v.PlaceRoom(9, 1, 1) v.PlaceRoom(10, 1, 2) // setup transparency for sprites gl.Disable(gl.DEPTH_TEST) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) app.Main(func(a app.App) { var sz size.Event for e := range a.Events() { switch e := app.Filter(e).(type) { case size.Event: sz = e case paint.Event: onPaint(sz) a.EndPaint(e) } } }) }
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() } } }) }
func onStart() { gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) rc, err := asset.Open("hello.wav") if err != nil { log.Fatal(err) } player, err = audio.NewPlayer(rc, 0, 0) if err != nil { log.Fatal(err) } }
func onStart() { gl.Enable(gl.BLEND) gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA) texture := loadImages("495.png") textureId = gl.CreateTexture() gl.BindTexture(gl.TEXTURE_2D, textureId) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT) gl.TexImage2D(gl.TEXTURE_2D, 0, texture.Rect.Size().X, texture.Rect.Size().Y, gl.RGBA, gl.UNSIGNED_BYTE, texture.Pix) // loading Shaders & linking programs program = createProgram("vShader.vs", "fShader.vs") texProgram = createProgram("vTexShader.vs", "fTexShader.vs") quadBuffer = gl.CreateBuffer() gl.BindBuffer(gl.ARRAY_BUFFER, quadBuffer) gl.BufferData(gl.ARRAY_BUFFER, quadData, gl.STATIC_DRAW) quadTexBuffer = gl.CreateBuffer() gl.BindBuffer(gl.ARRAY_BUFFER, quadTexBuffer) gl.BufferData(gl.ARRAY_BUFFER, quadTexData, gl.STATIC_DRAW) swasBuffer = gl.CreateBuffer() gl.BindBuffer(gl.ARRAY_BUFFER, swasBuffer) gl.BufferData(gl.ARRAY_BUFFER, swastikaData, gl.STATIC_DRAW) position = gl.GetAttribLocation(program, "position") color = gl.GetUniformLocation(program, "color") matrixId = gl.GetUniformLocation(program, "rotationMatrix") resolutionId = gl.GetUniformLocation(program, "resIndex") position2 = gl.GetAttribLocation(texProgram, "position") textureCoords = gl.GetAttribLocation(texProgram, "texCoords") matrixId2 = gl.GetUniformLocation(texProgram, "rotationMatrix") resolutionId2 = gl.GetUniformLocation(texProgram, "resIndex") color2 = gl.GetUniformLocation(texProgram, "color") }
func initKeys() { var err error program, err = glutil.CreateProgram( `#version 100 uniform mat4 projection; attribute vec3 position; attribute float pointsize; void main() { gl_Position = projection * vec4(position, 1); gl_PointSize = pointsize; }`, `#version 100 precision mediump float; uniform vec4 color; void main(void) { vec2 v = 2.0*gl_PointCoord.xy - vec2(1.0); float r2 = dot(v, v); gl_FragColor = mix(color, vec4(0), r2); }`, ) if err != nil { log.Printf("error creating GL program: %v", err) return } gl.Enable(34370) // GL_PROGRAM_POINT_SIZE; apparently not necessary on Android gl.Enable(gl.BLEND) gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR) projection = gl.GetUniformLocation(program, "projection") updateProjectionMatrix() position = gl.GetAttribLocation(program, "position") pointsize = gl.GetAttribLocation(program, "pointsize") color = gl.GetUniformLocation(program, "color") positionbuf = gl.CreateBuffer() pointsizebuf = gl.CreateBuffer() updateKeys(ratio{1, 1}) }
func loadScene(c event.Config) { gl.Enable(gl.BLEND) gl.BlendEquation(gl.FUNC_ADD) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) w, h := float32(c.Width), float32(c.Height) texs = loadTextures() scene = &sprite.Node{} eng.Register(scene) a := f32.Affine{ {1, 0, 0}, {0, 1, 0}, } if h > w { w, h = h, w angle := float32(-math.Pi / 2) a = f32.Affine{ {f32.Cos(angle), -f32.Sin(angle), 0}, {f32.Sin(angle), f32.Cos(angle), w}, } } scale = w / 1100 eng.SetTransform(scene, a) x0 = w/2 - 500*scale y0 = h/2 - 100*scale //log.Printf("width:%f height:%f scale:%f x0:%f y0:%f", w, h, scale, x0, y0) timeNode := newTimeNode() scene.AppendChild(timeNode) startNode := newStartNode() scene.AppendChild(startNode) endNode := newEndNode() scene.AppendChild(endNode) startVisilbe, endVisible := false, false scene.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { switch state { case stateStart: if !startVisilbe { startVisilbe = true eng.SetSubTex(startNode, texs["GO"]) } if endVisible { eng.SetSubTex(endNode, sprite.SubTex{}) endVisible = false } case stateRunning: if startVisilbe { eng.SetSubTex(startNode, sprite.SubTex{}) startVisilbe = false } case stateEnd: if !endVisible { endVisible = true eng.SetSubTex(endNode, texs["gooon"]) } } }) }