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 (scene *Floor) Draw(camera Camera) { shader, _ := scene.UseShader(nil) gl.Enable(gl.STENCIL_TEST) gl.StencilFunc(gl.ALWAYS, 1, 0xFF) gl.StencilOp(gl.KEEP, gl.KEEP, gl.REPLACE) gl.StencilMask(0xFF) gl.DepthMask(false) gl.Clear(gl.STENCIL_BUFFER_BIT) // Draw floor gl.Uniform3fv(shader.Uniform("material.ambient"), []float32{0.1, 0.1, 0.1}) scene.Shape.Draw(shader, camera) // Draw reflections gl.StencilFunc(gl.EQUAL, 1, 0xFF) gl.StencilMask(0x00) gl.DepthMask(true) view := camera.View() gl.Uniform3fv(shader.Uniform("material.ambient"), []float32{0.3, 0.3, 0.3}) for _, node := range scene.reflected { model := node.Transform(scene.transform) gl.UniformMatrix4fv(shader.Uniform("model"), model[:]) normal := model.Mul4(view).Inv().Transpose() gl.UniformMatrix4fv(shader.Uniform("normalMatrix"), normal[:]) node.Draw(camera) } gl.Disable(gl.STENCIL_TEST) }
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) }