func GameLoop() { t := 0.0 dt := 0.1 CreateUniverse() camera.PositionCamera(0, 0, 1000, 900) for glfw.WindowParam(glfw.Opened) == 1 { t += dt gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.Clear(gl.DEPTH_BUFFER_BIT | gl.LIGHTING_BIT) for i := range universe.Systems { for j := range universe.Systems[i].Planets { BufferPlanet(universe.Systems[i].Planets[j]) ai.PlanetOrbit(universe.Systems[i].Planets[j], t) } for j := range universe.Systems[i].Stars { BufferStar(universe.Systems[i].Stars[j]) ai.StarStationary(universe.Systems[i].Stars[j], t) } } glfw.SwapBuffers() } }
func (a *app) draw(t time.Time) { gl.Clear(gl.COLOR_BUFFER_BIT) img := a.img w := img.Rect.Dx() h := img.Rect.Dy() gl.ActiveTexture(gl.TEXTURE0) upload(1, img.Y, img.YStride, w, h) gl.ActiveTexture(gl.TEXTURE1) upload(2, img.Cb, img.CStride, w/2, h/2) gl.ActiveTexture(gl.TEXTURE2) upload(3, img.Cr, img.CStride, w/2, h/2) if *blend { pimg := a.pimg gl.Uniform1f(a.factorloc, factor(t, a.tbase.Add(pimg.Timecode), a.tbase.Add(img.Timecode))) gl.ActiveTexture(gl.TEXTURE3) upload(4, pimg.Y, pimg.YStride, w, h) gl.ActiveTexture(gl.TEXTURE4) upload(5, pimg.Cb, pimg.CStride, w/2, h/2) gl.ActiveTexture(gl.TEXTURE5) upload(6, pimg.Cr, pimg.CStride, w/2, h/2) } gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4) }
func (w *glfwBackend) Render(console *Console) { if w.Running() { w.mouse.Left.Released = false w.mouse.Right.Released = false w.mouse.Middle.Released = false w.key = NOKEY gl.Clear(gl.COLOR_BUFFER_BIT) gl.BindTexture(gl.TEXTURE_2D, textures[1]) for y := 0; y < console.Height(); y++ { for x := 0; x < console.Width(); x++ { _, bg, _ := console.Get(x, y) w.letter(x, y, 0, bg) } } gl.BindTexture(gl.TEXTURE_2D, textures[0]) for y := 0; y < console.Height(); y++ { for x := 0; x < console.Width(); x++ { fg, _, ch := console.Get(x, y) if position, ok := w.font.Map(ch); ok { w.letter(x, y, position, fg) } } } glfw.SwapBuffers() } }
func drawScene(draw func()) { // gl.ClearColor(1.0, 1.0, 1.0, 1.0) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) draw() gl.Finish() }
func (w *Window) run(init func(w *Window)) { runtime.LockOSThread() glfw.MakeContextCurrent(w.w) defer glfw.MakeContextCurrent(nil) init(w) // glfw should fire initial resize events to avoid this duplication (https://github.com/glfw/glfw/issues/62) w.resized(w.w.Size()) w.framebufferResized(w.w.FramebufferSize()) gl.Enable(gl.SCISSOR_TEST) gl.Enable(gl.BLEND) gl.Enable(gl.POINT_SMOOTH) gl.Enable(gl.LINE_SMOOTH) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) for !w.close { select { case f := <-w.do: f() case <-w.paint: gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Scissor(0, 0, w.bufWidth, w.bufHeight) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) w.base().paint() w.w.SwapBuffers() } } }
func (w *Window) run() { runtime.LockOSThread() glfw.MakeContextCurrent(w.w) defer glfw.MakeContextCurrent(nil) // glfw should fire initial resize events to avoid this duplication (https://github.com/glfw/glfw/issues/62) width, height := w.w.Size() gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, gl.Double(width), 0, gl.Double(height), -1, 1) Resize(w, Pt(float64(width), float64(height))) width, height = w.w.FramebufferSize() gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height)) gl.Enable(gl.BLEND) gl.Enable(gl.POINT_SMOOTH) gl.Enable(gl.LINE_SMOOTH) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) for !w.close { select { case f := <-w.do: f() case <-w.paint: gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) w.base().paint() w.w.SwapBuffers() } } }
func drawScene() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Rotated(-90, 1, 0, 0) //gl.Rotated(90, 0, 0, 1) gl.Rotated(gl.Double(-viewAngles[2]), 1, 0, 0) gl.Rotated(gl.Double(-viewAngles[0]), 0, 1, 0) gl.Rotated(gl.Double(-viewAngles[1]), 0, 0, 1) gl.Translated(gl.Double(viewOrg[0]), gl.Double(viewOrg[1]), gl.Double(viewOrg[2])) var r, g, b gl.Ubyte for i, face := range model.Faces { r = gl.Ubyte(i) + 100 g = gl.Ubyte(i>>1) + 100 b = gl.Ubyte(i>>2) + 100 if model.Triangle { gl.Begin(gl.TRIANGLES) } else { gl.Begin(gl.LINES) } gl.Color4ub(r, g, b, 0xff) for _, v := range face.Verts { gl.Vertex3d(gl.Double(v.Pos[0]), gl.Double(v.Pos[1]), gl.Double(v.Pos[2])) } gl.End() } }
func (l *Level) Render() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) SetUpCamera(800, 600, l.LevelBlueprint, 0) l.levelVertexBuffer.Render(Point3{0, 0, 0}) l.Paddle.Render() l.Ball.Render() }
func getPlayers(console *base.Console) []gin.DeviceId { var ct controllerTracker gin.In().RegisterEventListener(&ct) defer gin.In().UnregisterEventListener(&ct) ticker := time.Tick(time.Millisecond * 17) start := time.Time{} readyDuration := time.Second * 2 for start.IsZero() || time.Now().Sub(start) < readyDuration { <-ticker sys.Think() if ct.Ready() && start.IsZero() { start = time.Now() } if !ct.Ready() { start = time.Time{} } render.Queue(func() { defer console.Draw(0, 0, wdx, wdy) gl.Clear(gl.COLOR_BUFFER_BIT) gl.Disable(gl.DEPTH_TEST) gui.SetFontColor(1, 1, 1, 1) gl.Disable(gl.TEXTURE_2D) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() base.GetDictionary("crackin").RenderString(fmt.Sprintf("Num players: %d", len(ct.ids)), float64(wdx)/2, 300, 0, 100, gui.Center) base.GetDictionary("crackin").RenderString(fmt.Sprintf("Num ready: %d", ct.NumReady()), float64(wdx)/2, 400, 0, 100, gui.Center) if !start.IsZero() { base.GetDictionary("crackin").RenderString(fmt.Sprintf("Starting in %2.2f", (readyDuration-time.Now().Sub(start)).Seconds()), float64(wdx)/2, 500, 0, 100, gui.Center) } }) render.Queue(func() { sys.SwapBuffers() }) render.Purge() } var devices []gin.DeviceId for id := range ct.ids { devices = append(devices, id) } return devices }
func mainLoop(client sgf.ClientEngine, controllers []gin.DeviceId, console *base.Console) { client.MakeRequest(game.Join{Rebels: make([]*game.RebelPlayer, 2)}) ticker := time.Tick(time.Millisecond * 17) render.Queue(func() { gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) }) for { <-ticker if gin.In().GetKey(gin.AnyEscape).FramePressCount() != 0 { return } sys.Think() render.Queue(func() { gl.Clear(gl.COLOR_BUFFER_BIT) gl.Disable(gl.DEPTH_TEST) gui.SetFontColor(1, 1, 1, 1) gl.Disable(gl.TEXTURE_2D) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() base.GetDictionary("crackin").RenderString("Waiting on some nubs", float64(wdx)/2, 300, 0, 100, gui.Center) }) client.RLock() g := client.Game().(*game.Game) mode := g.Mode client.RUnlock() if mode == game.ModeWaiting { } else if mode == game.ModeProgram { programLoop(client, controllers, console) } else if mode == game.ModeRun { } render.Queue(func() { sys.SwapBuffers() }) render.Purge() } }
func (g *Gui) Draw() { gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(gl.Double(g.region.X), gl.Double(g.region.X+g.region.Dx), gl.Double(g.region.Y+g.region.Dy), gl.Double(g.region.Y), 1000, -1000) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() g.root.Draw(g.region, &styleStack{}) }
func ClearScene() { ambient := []gl.Float{0.7, 0.7, 0.7, 1} diffuse := []gl.Float{0.9, 0.9, 0.9, 1} lightpos := []gl.Float{0.2, 0.5, 1, 1} gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0]) gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0]) gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightpos[0]) gl.Enable(gl.LIGHT0) gl.ClearColor(1, 1, 1, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) }
func (g *Gui) Draw() { gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() region := g.root.Render_region gl.Ortho(gl.Double(region.X), gl.Double(region.X+region.Dx), gl.Double(region.Y), gl.Double(region.Y+region.Dy), 1000, -1000) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() g.root.Draw(region) if g.FocusWidget() != nil { g.FocusWidget().DrawFocused(region) } }
func drawScene() { fps() gl.Clear(gl.COLOR_BUFFER_BIT) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() if input.Zoom > 0 { gl.Ortho(0, gl.Double(float64(*flagSize)/input.Zoom), gl.Double(float64(*flagSize)/input.Zoom), 0, -1, 1.0) } gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Translatef(gl.Float(input.TransX*1), gl.Float(input.TransY*1), 0) drawGrid() drawCells() }
func (o *OpenGl) Init() { if err := glfw.Init(); err != nil { fmt.Fprintf(os.Stderr, "glfw: %s\n", err) return } defer glfw.Terminate() if err := glfw.OpenWindow(o.width, o.height, 0, 0, 0, 0, 16, 0, glfw.Windowed); err != nil { fmt.Fprintf(os.Stderr, "glfw: %s\n", err) return } defer glfw.CloseWindow() glfw.SetSwapInterval(1) glfw.SetWindowTitle(o.title) if err := gl.Init(); err != nil { fmt.Fprintf(os.Stderr, "gl: %s\n", err) } glfw.SetKeyCallback(glfw.KeyHandler(o.keyboard)) glfw.SetMouseButtonCallback(glfw.MouseButtonHandler(o.mouseClick)) glfw.SetMousePosCallback(glfw.MousePosHandler(o.mouseMove)) glfw.SetMouseWheelCallback(glfw.MouseWheelHandler(o.mouseWheel)) if err := o.initScene(); err != nil { fmt.Fprintf(os.Stderr, "init: %s\n", err) return } for glfw.WindowParam(glfw.Opened) == 1 { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) if o.display3d != nil { o.set3dView() o.display3d() } if o.display2d != nil { o.set2dView() o.display2d() } glfw.SwapBuffers() time.Sleep(20 * time.Millisecond) //<-o.redisplay } }
// draw draws the triangle. func draw() { gl.ClearColor(0.3, 0.3, 0.3, 0.0) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.ShadeModel(gl.SMOOTH) gl.LoadIdentity() gl.Translatef(-15.0, -15.0, 0.0) gl.Begin(gl.TRIANGLES) gl.Color3f(1.0, 0.0, 0.0) gl.Vertex2f(0.0, 0.0) gl.Color3f(0.0, 1.0, 0.0) gl.Vertex2f(30.0, 0.0) gl.Color3f(0.0, 0.0, 1.0) gl.Vertex2f(0.0, 30.0) gl.End() win.SwapBuffers() }
func DrawTestScene() { ambient := []gl.Float{0.7, 0.7, 0.7, 1} diffuse := []gl.Float{1, 1, 1, 1} lightpos := []gl.Float{0.2, 0.5, 1, 1} gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0]) gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0]) gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightpos[0]) gl.Enable(gl.LIGHT0) gl.ClearColor(1, 1, 1, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) const r = 0.5 const z = r red := color.NRGBA{R: 255, A: 255} blue := color.NRGBA{B: 255, A: 255} gl.Begin(gl.QUADS) (&Poly{[3]float32{0, 0, 0}, [4][3]float32{{-r, -r, z}, {r, -r, z}, {r, r, z}, {-r, r, z}}, red}).Render() (&Poly{[3]float32{0, 0, 0}, [4][3]float32{{-r, -r, -z}, {-r, r, -z}, {r, r, -z}, {r, -r, -z}}, blue}).Render() gl.End() }
func main() { f, err := os.Create("Go.pprof") // Create file for profiling if err != nil { panic(err) } glfw.SetErrorCallback(errorCallback) if !glfw.Init() { panic("Can't init glfw!") } defer glfw.Terminate() glfw.WindowHint(glfw.Samples, 2) glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) window, err := glfw.CreateWindow(Width, Height, Title, nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() glfw.SwapInterval(0) // No limit on FPS gl.Init() initScene() loadCubeToGPU() for !window.ShouldClose() { frameInitT = time.Now() movPts(frameDur) doWind() if spwnTmr >= SpawnInterval { spwnPts(SpawnInterval) spwnTmr -= SpawnInterval } if cleanupTmr >= float64(MaxLife)/1000 { cleanupPtPool() cleanupTmr = 0 } checkColls() gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gpuInitT = time.Now() renderPts() window.SwapBuffers() gpuEndT = time.Now() glfw.PollEvents() frameEndT = time.Now() frameDur = frameEndT.Sub(frameInitT).Seconds() // Calculate the length of the previous frame spwnTmr += frameDur cleanupTmr += frameDur runTmr += frameDur if runTmr > MaxLife/1000 { // Start collecting framerate data and profiling after a full MaxLife worth of particles have been spawned frames[curFrame] = frameDur gpuTimes[curFrame] = gpuEndT.Sub(gpuInitT).Seconds() curFrame += 1 pprof.StartCPUProfile(f) } if runTmr >= RunningTime { // Animation complete; calculate framerate mean and standard deviation pprof.StopCPUProfile() var sum float64 var i uint64 for i = 0; i < curFrame; i++ { sum += frames[i] } frameTimeMean := sum / float64(curFrame) fmt.Println("Average framerate was:", 1/frameTimeMean, "frames per second.") sum = 0 for i = 0; i < curFrame; i++ { sum += gpuTimes[i] } gpuTimeMean := sum / float64(curFrame) fmt.Println("Average cpu time was-", frameTimeMean-gpuTimeMean, "seconds per frame.") sumDiffs := 0.0 for i = 0; i < curFrame; i++ { sumDiffs += math.Pow(1/frames[i]-1/frameTimeMean, 2) } variance := sumDiffs / float64(curFrame) sd := math.Sqrt(variance) fmt.Println("The standard deviation was:", sd, "frames per second.") if PrintFrames == true { fmt.Print("--:") for i = 0; i < curFrame; i++ { fmt.Print(1 / frames[i]) fmt.Print(",") } fmt.Print(".--") } break } } gl.DisableClientState(gl.NORMAL_ARRAY) gl.DisableClientState(gl.VERTEX_ARRAY) }
func main() { sys = system.Make(gos.GetSystemInterface()) sys.Startup() wdx := 1000 wdy := 500 render.Init() var ui *gui.Gui render.Queue(func() { sys.CreateWindow(50, 150, wdx, wdy) sys.EnableVSync(true) err := gl.Init() if err != nil { f, err2 := os.Create(filepath.Join(datadir, "gl_log.txt")) if err2 != nil { fmt.Printf("Unable to write log to a file:%v\n%v\v", err, err2) } else { fmt.Fprintf(f, "%v\n", err) f.Close() } } ui, _ = gui.Make(gin.In(), gui.Dims{wdx, wdy}, filepath.Join(datadir, "fonts", "luxisr.ttf")) font, err := loadFont() if err != nil { panic(err.Error()) } dict = gui.MakeDictionary(font, 15) }) render.Purge() anchor := gui.MakeAnchorBox(gui.Dims{wdx, wdy}) ui.AddChild(anchor) var event_handler handler gin.In().RegisterEventListener(&event_handler) actions_list := gui.MakeVerticalTable() keyname_list := gui.MakeVerticalTable() both_lists := gui.MakeHorizontalTable() both_lists.AddChild(actions_list) both_lists.AddChild(keyname_list) anchor.AddChild(both_lists, gui.Anchor{1, 0.5, 1, 0.5}) var actions []string for action := range action_map { actions = append(actions, action) } sort.Strings(actions) for _, action := range actions { actions_list.AddChild(gui.MakeTextLine("standard", action, 150, 1, 1, 1, 1)) keyname_list.AddChild(gui.MakeTextLine("standard", commands[action].Cmd, 100, 1, 1, 1, 1)) } current_anim := gui.MakeTextLine("standard", "", 300, 1, 1, 1, 1) current_state := gui.MakeTextLine("standard", "", 300, 1, 1, 1, 1) frame_data := gui.MakeVerticalTable() frame_data.AddChild(current_anim) frame_data.AddChild(current_state) anchor.AddChild(frame_data, gui.Anchor{0, 1, 0, 1}) speed := 100 speed_text := gui.MakeTextLine("standard", "Speed: 100%", 150, 1, 1, 1, 1) anchor.AddChild(speed_text, gui.Anchor{0, 0, 0, 0}) var box1, box2 boxdata box1.name = "box1" box1.sb = makeSpriteBox(nil) anchor.AddChild(box1.sb, gui.Anchor{0.5, 0.5, 0.25, 0.5}) box1.load(GetStoreVal("box1")) box := box1 box2.name = "box2" box2.sb = makeSpriteBox(nil) anchor.AddChild(box2.sb, gui.Anchor{0.5, 0.5, 0.45, 0.5}) box2.load(GetStoreVal("box2")) box2.sb.top = true box_other := box2 box2.sb.r, box2.sb.g, box2.sb.b = 0.2, 0.1, 0.4 box1.sb.r, box1.sb.g, box1.sb.b = 0.4, 0.2, 0.8 error_msg = gui.MakeTextLine("standard", "", wdx, 1, 0.5, 0.5, 1) anchor.AddChild(error_msg, gui.Anchor{0, 0, 0, 0.1}) var chooser gui.Widget // curdir := GetStoreVal("curdir") // if curdir == "" { // curdir = "." // } else { // _,err := os.Stat(filepath.Join(datadir, curdir)) // if err == nil { // go func() { // anim, err := sprite.LoadSprite(filepath.Join(datadir, curdir)) // loaded <- loadResult{ anim, err } // } () // } else { // curdir = "." // } // } // var profile_output *os.File then := time.Now() sys.Think() for key_map["quit"].FramePressCount() == 0 { event_handler.box1 = &box event_handler.box2 = &box_other now := time.Now() dt := (now.Nanosecond() - then.Nanosecond()) / 1000000 then = now render.Queue(func() { sys.Think() if box1.sb.s != nil { box1.sb.s.Think(int64(float64(dt) * float64(speed) / 100)) } if box2.sb.s != nil { box2.sb.s.Think(int64(float64(dt) * float64(speed) / 100)) } gl.ClearColor(1, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT) ui.Draw() sys.SwapBuffers() }) render.Purge() select { case load := <-loaded: if load.err != nil { error_msg.SetText(load.err.Error()) current_anim.SetText("") } else { box.sb.s = load.anim error_msg.SetText("") } default: } // if box.sb.s != nil { // box.sb.s.Think() // current_anim.SetText(fmt.Sprintf("%d: %s", box.sb.s.Facing(), box.sb.s.Anim())) // current_state.SetText(box.sb.s.AnimState()) // } if box.sb.s != nil { if key_map["reset"].FramePressCount() > 0 { box.load(box.dir) box_other.load(box_other.dir) } } // if key_map["profile"].FramePressCount() > 0 { // if profile_output == nil { // var err error // profile_output, err = os.Create(filepath.Join(datadir, "cpu.prof")) // if err == nil { // err = pprof.StartCPUProfile(profile_output) // if err != nil { // fmt.Printf("Unable to start CPU profile: %v\n", err) // profile_output.Close() // profile_output = nil // } // fmt.Printf("profout: %v\n", profile_output) // } else { // fmt.Printf("Unable to open CPU profile: %v\n", err) // } // } else { // pprof.StopCPUProfile() // profile_output.Close() // profile_output = nil // } // } if key_map["load"].FramePressCount() > 0 && chooser == nil { anch := gui.MakeAnchorBox(gui.Dims{wdx, wdy}) file_chooser := gui.MakeFileChooser(filepath.Join(datadir, box.dir), func(path string, err error) { if err == nil && len(path) > 0 { curpath, _ := filepath.Split(path) box.load(curpath) } ui.RemoveChild(chooser) chooser = nil }, func(path string, is_dir bool) bool { return true }) anch.AddChild(file_chooser, gui.Anchor{0.5, 0.5, 0.5, 0.5}) chooser = anch ui.AddChild(chooser) } delta := key_map["speed up"].FramePressAmt() - key_map["slow down"].FramePressAmt() if delta != 0 { speed += int(delta) if speed < 1 { speed = 1 } if speed > 100 { speed = 100 } speed_text.SetText(fmt.Sprintf("Speed: %d%%", speed)) } if key_map["select1"].FramePressCount() > 0 { box2.sb.r, box2.sb.g, box2.sb.b = 0.2, 0.1, 0.4 box1.sb.r, box1.sb.g, box1.sb.b = 0.4, 0.2, 0.8 box = box1 box_other = box2 } if key_map["select2"].FramePressCount() > 0 { box2.sb.r, box2.sb.g, box2.sb.b = 0.4, 0.2, 0.8 box1.sb.r, box1.sb.g, box1.sb.b = 0.2, 0.1, 0.4 box = box2 box_other = box1 } } }
func standardHookup() { g := g2.Make(0, 0, wdx, wdy) var tm g2.ThunderMenu tm.Subs = make(map[string]*g2.ThunderSubMenu) triggers := map[gin.KeyId]struct{}{ gin.AnyReturn: struct{}{}, gin.In().GetKeyFlat(gin.ControllerButton0+2, gin.DeviceTypeController, gin.DeviceIndexAny).Id(): struct{}{}, } action := "" tm.Subs[""] = g2.MakeThunderSubMenu( []g2.Widget{ &g2.Button{Size: 50, Triggers: triggers, Name: "Debug", Callback: func() { tm.Push("debug") }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Host LAN game", Callback: func() { base.Log().Printf("HOST"); print("HOST\n") }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Join LAN game", Callback: func() { base.Log().Printf("JOIN"); print("JOIN\n") }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Quit", Callback: func() { action = "Quit" }}, }) tm.Subs["debug"] = g2.MakeThunderSubMenu( []g2.Widget{ &g2.Button{Size: 50, Triggers: triggers, Name: "Standard", Callback: func() { action = "standard" }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Moba", Callback: func() { action = "moba" }}, &g2.Button{Size: 50, Triggers: triggers, Name: "Back", Callback: func() { tm.Pop() }}, }) tm.Start(500) g.AddChild(&tm, g2.AnchorDeadCenter) g.AddChild(g2.MakeConsole(wdx, wdy), g2.AnchorDeadCenter) t := texture.LoadFromPath(filepath.Join(base.GetDataDir(), "background/buttons1.jpg")) for { sys.Think() if action == "Quit" { return } if action == "standard" || action == "moba" { g.StopEventListening() engine, local := debugHookup(action) mainLoop(engine, local, action) g.RestartEventListening() action = "" } render.Queue(func() { gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) if true { ratio := float64(wdx) / float64(wdy) t.RenderAdvanced(-1+(1-1/ratio), -1, 2/ratio, 2, 0, false) } gl.Disable(gl.TEXTURE_2D) base.GetDictionary("luxisr").RenderString("INvASioN!!!", 0, 0.5, 0, 0.03, gui.Center) }) render.Queue(func() { g.Draw() sys.SwapBuffers() }) render.Purge() } // 1 Start with a title screen // 2 Option to host or join // 3a If host then wait for a connection // 3b If join then ping and connect // 4 Once joined up the 'game' will handle choosing sides and whatnot }
// Need floor, right wall, and left wall matrices to draw the details func (room *Room) render(floor, left, right mathgl.Mat4, zoom float32, base_alpha byte, drawables []Drawable, los_tex *LosTexture, floor_drawers []FloorDrawer) { do_color := func(r, g, b, a byte) { R, G, B, A := room.Color() A = alphaMult(A, base_alpha) gl.Color4ub(alphaMult(R, r), alphaMult(G, g), alphaMult(B, b), alphaMult(A, a)) } gl.Enable(gl.TEXTURE_2D) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Enable(gl.STENCIL_TEST) gl.ClearStencil(0) gl.Clear(gl.STENCIL_BUFFER_BIT) gl.EnableClientState(gl.VERTEX_ARRAY) gl.EnableClientState(gl.TEXTURE_COORD_ARRAY) defer gl.DisableClientState(gl.VERTEX_ARRAY) defer gl.DisableClientState(gl.TEXTURE_COORD_ARRAY) var vert roomVertex planes := []plane{ {room.left_buffer, room.Wall, &left}, {room.right_buffer, room.Wall, &right}, {room.floor_buffer, room.Floor, &floor}, } gl.PushMatrix() defer gl.PopMatrix() if los_tex != nil { gl.LoadMatrixf(&floor[0]) gl.ClientActiveTexture(gl.TEXTURE1) gl.ActiveTexture(gl.TEXTURE1) gl.Enable(gl.TEXTURE_2D) gl.EnableClientState(gl.TEXTURE_COORD_ARRAY) los_tex.Bind() gl.BindBuffer(gl.ARRAY_BUFFER, room.vbuffer) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.ClientActiveTexture(gl.TEXTURE0) gl.ActiveTexture(gl.TEXTURE0) base.EnableShader("los") base.SetUniformI("los", "tex2", 1) } var mul, run mathgl.Mat4 for _, plane := range planes { gl.LoadMatrixf(&floor[0]) run.Assign(&floor) // Render the doors and cut out the stencil buffer so we leave them empty // if they're open switch plane.mat { case &left: gl.StencilFunc(gl.ALWAYS, 1, 1) gl.StencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE) for _, door := range room.Doors { if door.Facing != FarLeft { continue } door.TextureData().Bind() R, G, B, A := door.Color() do_color(R, G, B, alphaMult(A, room.far_left.wall_alpha)) gl.ClientActiveTexture(gl.TEXTURE0) door.TextureData().Bind() if door.door_glids.floor_buffer != 0 { gl.BindBuffer(gl.ARRAY_BUFFER, door.threshold_glids.vbuffer) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, door.door_glids.floor_buffer) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.DrawElements(gl.TRIANGLES, door.door_glids.floor_count, gl.UNSIGNED_SHORT, nil) } } gl.StencilFunc(gl.NOTEQUAL, 1, 1) gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP) do_color(255, 255, 255, room.far_left.wall_alpha) case &right: gl.StencilFunc(gl.ALWAYS, 1, 1) gl.StencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE) for _, door := range room.Doors { if door.Facing != FarRight { continue } door.TextureData().Bind() R, G, B, A := door.Color() do_color(R, G, B, alphaMult(A, room.far_right.wall_alpha)) gl.ClientActiveTexture(gl.TEXTURE0) door.TextureData().Bind() if door.door_glids.floor_buffer != 0 { gl.BindBuffer(gl.ARRAY_BUFFER, door.threshold_glids.vbuffer) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, door.door_glids.floor_buffer) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.DrawElements(gl.TRIANGLES, door.door_glids.floor_count, gl.UNSIGNED_SHORT, nil) } } gl.StencilFunc(gl.NOTEQUAL, 1, 1) gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP) do_color(255, 255, 255, room.far_right.wall_alpha) case &floor: gl.StencilFunc(gl.ALWAYS, 2, 2) gl.StencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE) do_color(255, 255, 255, 255) } gl.ClientActiveTexture(gl.TEXTURE0) gl.BindBuffer(gl.ARRAY_BUFFER, room.vbuffer) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) if los_tex != nil { los_tex.Bind() } gl.BindBuffer(gl.ARRAY_BUFFER, room.vbuffer) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) // Now draw the walls gl.LoadMatrixf(&floor[0]) plane.texture.Data().Bind() gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, plane.index_buffer) if (plane.mat == &left || plane.mat == &right) && strings.Contains(string(room.Wall.Path), "gradient.png") { base.EnableShader("gorey") base.SetUniformI("gorey", "tex", 0) base.SetUniformI("gorey", "foo", Foo) base.SetUniformF("gorey", "num_rows", Num_rows) base.SetUniformF("gorey", "noise_rate", Noise_rate) base.SetUniformF("gorey", "num_steps", Num_steps) } if plane.mat == &floor && strings.Contains(string(room.Floor.Path), "gradient.png") { base.EnableShader("gorey") base.SetUniformI("gorey", "tex", 0) base.SetUniformI("gorey", "foo", Foo) base.SetUniformF("gorey", "num_rows", Num_rows) base.SetUniformF("gorey", "noise_rate", Noise_rate) base.SetUniformF("gorey", "num_steps", Num_steps) zexp := math.Log(float64(zoom)) frac := 1 - 1/zexp frac = (frac - 0.6) * 5.0 switch { case frac > 0.7: base.SetUniformI("gorey", "range", 1) case frac > 0.3: base.SetUniformI("gorey", "range", 2) default: base.SetUniformI("gorey", "range", 3) } } if plane.mat == &floor { R, G, B, _ := room.Color() gl.Color4ub(R, G, B, 255) } gl.DrawElements(gl.TRIANGLES, gl.Sizei(room.floor_count), gl.UNSIGNED_SHORT, nil) if los_tex != nil { base.EnableShader("los") } else { base.EnableShader("") } } for _, wt := range room.WallTextures { if room.wall_texture_gl_map == nil { room.wall_texture_gl_map = make(map[*WallTexture]wallTextureGlIds) room.wall_texture_state_map = make(map[*WallTexture]wallTextureState) } ids := room.wall_texture_gl_map[wt] state := room.wall_texture_state_map[wt] var new_state wallTextureState new_state.flip = wt.Flip new_state.rot = wt.Rot new_state.x = wt.X new_state.y = wt.Y new_state.room.x = room.X new_state.room.y = room.Y new_state.room.dx = room.Size.Dx new_state.room.dy = room.Size.Dy if new_state != state { wt.setupGlStuff(room.X, room.Y, room.Size.Dx, room.Size.Dy, &ids) room.wall_texture_gl_map[wt] = ids room.wall_texture_state_map[wt] = new_state } gl.LoadMatrixf(&floor[0]) if ids.vbuffer != 0 { wt.Texture.Data().Bind() R, G, B, A := wt.Color() gl.ClientActiveTexture(gl.TEXTURE0) gl.BindBuffer(gl.ARRAY_BUFFER, ids.vbuffer) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.ClientActiveTexture(gl.TEXTURE0) if ids.floor_buffer != 0 { gl.StencilFunc(gl.ALWAYS, 2, 2) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, ids.floor_buffer) gl.Color4ub(R, G, B, A) gl.DrawElements(gl.TRIANGLES, ids.floor_count, gl.UNSIGNED_SHORT, nil) } if ids.left_buffer != 0 { gl.StencilFunc(gl.ALWAYS, 1, 1) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, ids.left_buffer) do_color(R, G, B, alphaMult(A, room.far_left.wall_alpha)) gl.DrawElements(gl.TRIANGLES, ids.left_count, gl.UNSIGNED_SHORT, nil) } if ids.right_buffer != 0 { gl.StencilFunc(gl.ALWAYS, 1, 1) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, ids.right_buffer) do_color(R, G, B, alphaMult(A, room.far_right.wall_alpha)) gl.DrawElements(gl.TRIANGLES, ids.right_count, gl.UNSIGNED_SHORT, nil) } } } base.EnableShader("marble") base.SetUniformI("marble", "tex2", 1) base.SetUniformF("marble", "room_x", float32(room.X)) base.SetUniformF("marble", "room_y", float32(room.Y)) for _, door := range room.Doors { door.setupGlStuff(room) if door.threshold_glids.vbuffer == 0 { continue } if door.AlwaysOpen() { continue } if door.highlight_threshold { gl.Color4ub(255, 255, 255, 255) } else { gl.Color4ub(128, 128, 128, 255) } gl.BindBuffer(gl.ARRAY_BUFFER, door.threshold_glids.vbuffer) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.ClientActiveTexture(gl.TEXTURE0) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, door.threshold_glids.floor_buffer) gl.DrawElements(gl.TRIANGLES, door.threshold_glids.floor_count, gl.UNSIGNED_SHORT, nil) } base.EnableShader("") if los_tex != nil { base.EnableShader("") gl.ActiveTexture(gl.TEXTURE1) gl.Disable(gl.TEXTURE_2D) gl.ActiveTexture(gl.TEXTURE0) gl.ClientActiveTexture(gl.TEXTURE1) gl.DisableClientState(gl.TEXTURE_COORD_ARRAY) gl.ClientActiveTexture(gl.TEXTURE0) } run.Assign(&floor) mul.Translation(float32(-room.X), float32(-room.Y), 0) run.Multiply(&mul) gl.LoadMatrixf(&run[0]) gl.StencilFunc(gl.EQUAL, 2, 3) gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP) room_rect := image.Rect(room.X, room.Y, room.X+room.Size.Dx, room.Y+room.Size.Dy) for _, fd := range floor_drawers { x, y := fd.Pos() dx, dy := fd.Dims() if room_rect.Overlaps(image.Rect(x, y, x+dx, y+dy)) { fd.RenderOnFloor() } } do_color(255, 255, 255, 255) gl.LoadIdentity() gl.Disable(gl.STENCIL_TEST) room.renderFurniture(floor, 255, drawables, los_tex) gl.ClientActiveTexture(gl.TEXTURE1) gl.Disable(gl.TEXTURE_2D) gl.ClientActiveTexture(gl.TEXTURE0) base.EnableShader("") }
// Clear clears the pixels on screen. This should probably be called before // every new frame. func Clear() error { gl.Clear(gl.COLOR_BUFFER_BIT) return checkForErrors() }
func (s *Scene) Draw() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) for _, o := range s.Objects { o.draw() } }
func programLoop(client sgf.ClientEngine, controllers []gin.DeviceId, console *base.Console) { ticker := time.Tick(time.Millisecond * 17) var selections cardSelections selections.cols = 7 selections.players = make([]cardSelection, len(controllers)) client.RLock() g := client.Game().(*game.Game) for _, card := range g.Cards { selections.cards = append(selections.cards, card) selections.used = append(selections.used, -1) } client.RUnlock() for { <-ticker if gin.In().GetKey(gin.AnyEscape).FramePressCount() != 0 { return } for i, device := range controllers { up := gin.In().GetKeyFlat(gin.ControllerHatSwitchUp, device.Type, device.Index).FramePressCount() down := gin.In().GetKeyFlat(gin.ControllerHatSwitchDown, device.Type, device.Index).FramePressCount() left := gin.In().GetKeyFlat(gin.ControllerHatSwitchLeft, device.Type, device.Index).FramePressCount() right := gin.In().GetKeyFlat(gin.ControllerHatSwitchRight, device.Type, device.Index).FramePressCount() selections.HandleMove(i, right-left, down-up) drop := gin.In().GetKeyFlat(gin.ControllerButton0+1, device.Type, device.Index).FramePressCount() > 0 choose := gin.In().GetKeyFlat(gin.ControllerButton0+2, device.Type, device.Index).FramePressCount() > 0 if choose { selections.HandleChoose(i) } if drop { selections.HandleDrop(i) } } sys.Think() render.Queue(func() { defer console.Draw(0, 0, wdx, wdy) gl.Clear(gl.COLOR_BUFFER_BIT) gl.Disable(gl.DEPTH_TEST) gui.SetFontColor(1, 1, 1, 1) gl.Disable(gl.TEXTURE_2D) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() client.RLock() g := client.Game().(*game.Game) renderBoard(g, 10, 10, 400, 400) client.RUnlock() renderCards(selections.cards, 64, 400, 400, selections.cols, &selections) for i, player := range selections.players { setColorForIndex(i) renderCardReticle(false, 64, player.sx, player.sy, 400, 400) renderCards(player.cards, 64, 400, 300-100*i, selections.cols, nil) } }) render.Queue(func() { sys.SwapBuffers() }) render.Purge() } }
func drawScene() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Translatef(0, 0, -3.0) gl.Rotatef(rotx, 1, 0, 0) gl.Rotatef(roty, 0, 1, 0) rotx += 0.5 roty += 0.5 gl.BindTexture(gl.TEXTURE_2D, texture) gl.Color4f(1, 1, 1, 1) gl.Begin(gl.QUADS) gl.Normal3f(0, 0, 1) gl.TexCoord2f(0, 0) gl.Vertex3f(-1, -1, 1) gl.TexCoord2f(1, 0) gl.Vertex3f(1, -1, 1) gl.TexCoord2f(1, 1) gl.Vertex3f(1, 1, 1) gl.TexCoord2f(0, 1) gl.Vertex3f(-1, 1, 1) gl.Normal3f(0, 0, -1) gl.TexCoord2f(1, 0) gl.Vertex3f(-1, -1, -1) gl.TexCoord2f(1, 1) gl.Vertex3f(-1, 1, -1) gl.TexCoord2f(0, 1) gl.Vertex3f(1, 1, -1) gl.TexCoord2f(0, 0) gl.Vertex3f(1, -1, -1) gl.Normal3f(0, 1, 0) gl.TexCoord2f(0, 1) gl.Vertex3f(-1, 1, -1) gl.TexCoord2f(0, 0) gl.Vertex3f(-1, 1, 1) gl.TexCoord2f(1, 0) gl.Vertex3f(1, 1, 1) gl.TexCoord2f(1, 1) gl.Vertex3f(1, 1, -1) gl.Normal3f(0, -1, 0) gl.TexCoord2f(1, 1) gl.Vertex3f(-1, -1, -1) gl.TexCoord2f(0, 1) gl.Vertex3f(1, -1, -1) gl.TexCoord2f(0, 0) gl.Vertex3f(1, -1, 1) gl.TexCoord2f(1, 0) gl.Vertex3f(-1, -1, 1) gl.Normal3f(1, 0, 0) gl.TexCoord2f(1, 0) gl.Vertex3f(1, -1, -1) gl.TexCoord2f(1, 1) gl.Vertex3f(1, 1, -1) gl.TexCoord2f(0, 1) gl.Vertex3f(1, 1, 1) gl.TexCoord2f(0, 0) gl.Vertex3f(1, -1, 1) gl.Normal3f(-1, 0, 0) gl.TexCoord2f(0, 0) gl.Vertex3f(-1, -1, -1) gl.TexCoord2f(1, 0) gl.Vertex3f(-1, -1, 1) gl.TexCoord2f(1, 1) gl.Vertex3f(-1, 1, 1) gl.TexCoord2f(0, 1) gl.Vertex3f(-1, 1, -1) gl.End() }
func main() { runtime.LockOSThread() flag.Parse() if *workers <= 0 { *workers = 1 } runtime.GOMAXPROCS(*workers + 1) buildPalette() sdl.Init(sdl.INIT_VIDEO) defer sdl.Quit() if !*noVSync { sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1) } if sdl.SetVideoMode(512, 512, 32, sdl.OPENGL) == nil { panic("sdl error") } sdl.WM_SetCaption("Gomandel", "Gomandel") if err := gl.Init(); err != nil { panic(err) } gl.Enable(gl.TEXTURE_2D) gl.Viewport(0, 0, 512, 512) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, 512, 512, 0, -1, 1) gl.ClearColor(0, 0, 0, 0) //----------------------------------------------------------------------------- var dndDragging bool = false var dnd3 bool = false var dndStart Point var dndEnd Point initialRect := Rect{-1.5, -1.5, 3, 3} rect := initialRect tm := NewTileManager(512, 512) tm.ZoomRequest(&rect) running := true for running { for { var event interface{} select { case event = <-sdl.Events: default: } if event == nil { break } switch e := event.(type) { case sdl.QuitEvent: running = false case sdl.MouseButtonEvent: if e.Type == sdl.MOUSEBUTTONDOWN { dndDragging = true dndStart.X = gl.Int(e.X) dndStart.Y = gl.Int(e.Y) dndEnd = dndStart if e.Button == 3 { dnd3 = true } else { dndDragging = true } } else { dndDragging = false dndEnd.X = gl.Int(e.X) dndEnd.Y = gl.Int(e.Y) switch e.Button { case 1: rect = rectFromSelection(dndStart, dndEnd, 512, 512, rect) tm.ZoomRequest(&rect) case 2: rect = initialRect tm.ZoomRequest(&rect) case 3: dnd3 = false } } case sdl.MouseMotionEvent: if dnd3 { dndEnd.X = gl.Int(e.X) dndEnd.Y = gl.Int(e.Y) rect = moveRectBy(rect, dndStart, dndEnd, 512, 512) tm.MoveRequest(rect) dndStart = dndEnd } else if dndDragging { dndEnd.X = gl.Int(e.X) dndEnd.Y = gl.Int(e.Y) } } } tm.Update() gl.Clear(gl.COLOR_BUFFER_BIT) tm.Draw() gl.BindTexture(gl.TEXTURE_2D, 0) if dndDragging { drawSelection(dndStart, dndEnd) } sdl.GL_SwapBuffers() } }