// resize resizes the window to the specified dimensions. func resize(width, height int) { gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height)) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0) gl.MatrixMode(gl.MODELVIEW) }
func InitViewport() { gl.Viewport(0, 0, gl.Sizei(Width), gl.Sizei(Height)) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() x := gl.Double(float64(Height) / float64(Width)) gl.Frustum(-1./2., 1./2., -x/2, x/2, 10, 100) }
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 initScene() { input.Init() life = automata.NewLife(*flagRule, *flagSize, *flagDelay, *flagSeed) input.Sim = life go life.Run() gl.ClearColor(0.0, 0.0, 0.0, 0.0) gl.Viewport(0, 0, Width, Height) }
func windowResizeCallback(window *glfw.Window, width, height int) { paunchWindow.width = width paunchWindow.height = height for _, eventManager := range paunchWindow.eventManagers { eventManager.RunWindowResizeEvent(width, height) } gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height)) }
func (g *Game) RenderLocalEditor(region g2.Region) { g.editor.Lock() defer g.editor.Unlock() g.editor.region = region g.editor.camera.regionDims = linear.Vec2{float64(region.Dims.Dx), float64(region.Dims.Dy)} levelDims := linear.Vec2{float64(g.Level.Room.Dx), float64(g.Level.Room.Dy)} g.editor.camera.StandardRegion(levelDims.Scale(0.5), levelDims) g.editor.camera.approachTarget() gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() defer gl.PopMatrix() gl.PushAttrib(gl.VIEWPORT_BIT) gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy)) defer gl.PopAttrib() current := &g.editor.camera.current gl.Ortho( gl.Double(current.mid.X-current.dims.X/2), gl.Double(current.mid.X+current.dims.X/2), gl.Double(current.mid.Y+current.dims.Y/2), gl.Double(current.mid.Y-current.dims.Y/2), gl.Double(1000), gl.Double(-1000), ) defer func() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) }() gl.MatrixMode(gl.MODELVIEW) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) g.renderWalls() g.renderEdges() g.renderBases() g.renderEntsAndAbilities() g.renderProcesses() g.editor.renderPathing(&g.Level.Room, g.local.pathingData) switch g.editor.action { case editorActionNone: case editorActionPlaceBlock: g.editor.renderPlaceBlock(g) default: base.Error().Printf("Unexpected editorAction: %v", g.editor.action) } }
func initScene(width, height int, init func()) (err error) { gl.Disable(gl.DEPTH_TEST) gl.ClearColor(0.5, 0.5, 0.5, 0.0) gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height)) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, gl.Double(width), gl.Double(height), 0, 0, 1) gl.MatrixMode(gl.MODELVIEW) init() return }
func (s *Scene) Init() (err error) { runtime.LockOSThread() gl.Enable(gl.TEXTURE_2D) gl.Enable(gl.DEPTH_TEST) gl.ClearColor(0.0, 0.0, 0.0, 0.0) gl.ClearDepth(1) //gl.DepthFunc(gl.LEQUAL) gl.Viewport(0, 0, Width, Height) mm.init() return }
func (a *app) OnResize(w, h int) { oaspect := float64(a.imgW()) / float64(a.imgH()) haspect := float64(w) / float64(h) vaspect := float64(h) / float64(w) var scx, scy float64 if oaspect > haspect { scx = 1 scy = haspect / oaspect } else { scx = vaspect * oaspect scy = 1 } gl.Viewport(0, 0, gl.Sizei(w), gl.Sizei(h)) gl.LoadIdentity() gl.Scaled(gl.Double(scx), gl.Double(scy), 1) }
func SetUpCamera( screenWidth int32, screenHeight int32, lb *LevelBlueprint, playerIndex int32) { pb := &lb.Players[playerIndex] // Calculate the distance between the near plane and the camera. We want // (PaddleAreaWidth / 2) / cameraDist = tan(CameraHorzFovDegrees / 2) t := math.Tan(math.Pi * Config.CameraHorzFovDegrees / 360) cameraDist := pb.PaddleAreaWidth / (2 * t) cameraPos := pb.PaddleAreaCenter.Minus( pb.Orientation.Forward.Times(cameraDist)) // Set up the projection matrix. gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Viewport(0, 0, gl.Sizei(screenWidth), gl.Sizei(screenHeight)) gl.Frustum( gl.Double(-pb.PaddleAreaWidth/2), gl.Double(pb.PaddleAreaWidth/2), gl.Double(-pb.PaddleAreaHeight/2), gl.Double(pb.PaddleAreaHeight/2), gl.Double(cameraDist), gl.Double(cameraDist+Config.ViewDepth)) // Set up the modelview matrix. gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() transformation := [16]gl.Double{ gl.Double(pb.Orientation.Right.X), gl.Double(pb.Orientation.Up.X), gl.Double(-pb.Orientation.Forward.X), gl.Double(0.0), gl.Double(pb.Orientation.Right.Y), gl.Double(pb.Orientation.Up.Y), gl.Double(-pb.Orientation.Forward.Y), gl.Double(0.0), gl.Double(pb.Orientation.Right.Z), gl.Double(pb.Orientation.Up.Z), gl.Double(-pb.Orientation.Forward.Z), gl.Double(0.0), gl.Double(0.0), gl.Double(0.0), gl.Double(0.0), gl.Double(1.0)} gl.MultMatrixd(&transformation[0]) gl.Translated( gl.Double(-cameraPos.X), gl.Double(-cameraPos.Y), gl.Double(-cameraPos.Z)) }
func (g *Game) RenderLocalGame(region g2.Region) { g.local.Camera.regionDims = linear.Vec2{float64(region.Dims.Dx), float64(region.Dims.Dy)} // func (g *Game) renderLocalHelper(region g2.Region, local *LocalData, camera *cameraInfo, side int) { g.local.Camera.FocusRegion(g, 0) gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() // Set the viewport so that we only render into the region that we're supposed // to render to. // TODO: Check if this works on all graphics cards - I've heard that the opengl // spec doesn't actually require that viewport does any clipping. gl.PushAttrib(gl.VIEWPORT_BIT) gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy)) defer gl.PopAttrib() current := &g.local.Camera.current gl.Ortho( gl.Double(current.mid.X-current.dims.X/2), gl.Double(current.mid.X+current.dims.X/2), gl.Double(current.mid.Y+current.dims.Y/2), gl.Double(current.mid.Y-current.dims.Y/2), gl.Double(1000), gl.Double(-1000), ) defer func() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) }() gl.MatrixMode(gl.MODELVIEW) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) level := g.Level zoom := current.dims.X / float64(region.Dims.Dx) level.ManaSource.Draw(zoom, float64(level.Room.Dx), float64(level.Room.Dy)) g.renderWalls() g.renderEdges() g.renderBases() g.renderEntsAndAbilities() g.renderProcesses() g.RenderLosMask() }
func PositionCamera(x, y gl.Double, width, height gl.Sizei) { texs.Disable2d() texs.Enable2d(x, y, 1000, 900) gl.Viewport(0, 0, 1000, 900) gl.LoadIdentity() title := strconv.FormatInt(int64(x), 10) + " , " + strconv.FormatInt(int64(y), 10) glfw.SetWindowTitle(title) X = x y = Y Width = width Height = height //UpdateActiveSystems() }
func initScene() { gl.Disable(gl.TEXTURE_2D) gl.Disable(gl.DEPTH_TEST) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Disable(gl.ALPHA_TEST) gl.Enable(gl.LINE_SMOOTH) gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST) gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE) gl.LineWidth(1.0) gl.ClearColor(0.0, 0.0, 0.0, 0.0) gl.ClearDepth(1) //gl.DepthFunc(gl.LEQUAL) gl.Viewport(0, 0, Width, Height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() perspective(110.0, 1.0, 4, 8192) }
func glInit(width, height int) { gl.Init() gl.Enable(gl.TEXTURE_2D) gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1) gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height)) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, gl.Double(width), gl.Double(height), 0, -1, 1) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.EnableClientState(gl.VERTEX_ARRAY) gl.EnableClientState(gl.COLOR_ARRAY) gl.EnableClientState(gl.TEXTURE_COORD_ARRAY) gl.VertexPointer(2, gl.FLOAT, 0, gl.Pointer(&vs[0])) gl.ColorPointer(3, gl.UNSIGNED_BYTE, 0, gl.Pointer(&cs[0])) gl.TexCoordPointer(2, gl.FLOAT, 0, gl.Pointer(&ts[0])) }
func (o *OpenGl) initScene() (err error) { gl.ClearColor(0.0, 0.0, 0.0, 0.0) gl.ClearDepth(1) gl.DepthFunc(gl.LEQUAL) ambient := []gl.Float{0.5, 0.5, 0.5, 1} diffuse := []gl.Float{1, 1, 1, 1} position := []gl.Float{-5, 5, 10, 0} gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0]) gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0]) gl.Lightfv(gl.LIGHT0, gl.POSITION, &position[0]) gl.Viewport(0, 0, gl.Sizei(o.width), gl.Sizei(o.height)) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1, 1, -1, 1, 1.0, 10.0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() return nil }
func initScene() (err error) { gl.Enable(gl.TEXTURE_2D) gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.LIGHTING) gl.ClearColor(0.5, 0.5, 0.5, 0.0) gl.ClearDepth(1) gl.DepthFunc(gl.LEQUAL) 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.Viewport(0, 0, Width, Height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1, 1, -1, 1, 1.0, 10.0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() texture, err = createTextureFromBytes(gopher_png[:]) return }
func initScene() { gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.LIGHTING) gl.ClearColor(0.1, 0.1, 0.6, 1.0) gl.ClearDepth(1) gl.DepthFunc(gl.LEQUAL) 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.Viewport(0, 0, Width, Height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1, 1, -1, 1, 1.0, 1000.0) gl.Rotatef(20, 1, 0, 0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.PushMatrix() return }
func (w *Window) registerCallbacks() { w.w.OnFocus(func(focused bool) { if focused { go doMain(func() { for i, w2 := range windows { if w2 == w { windows = append(append([]*Window{w}, windows[:i]...), windows[i+1:]...) break } } }) } }) w.w.OnClose(w.Close) w.w.OnResize(func(width, height int) { w.Do(func() { s := Pt(float64(width), float64(height)) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, gl.Double(s.X), 0, gl.Double(s.Y), -1, 1) Resize(w.Self, s) if w.centralView != nil { Resize(w.centralView, s) } }) }) w.w.OnFramebufferResize(func(width, height int) { w.Do(func() { gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height)) }) }) k := KeyEvent{} w.w.OnKey(func(key, scancode, action, mods int) { w.Do(func() { k.Key = key k.action = action k.Repeat = action == glfw.Repeat k.Shift = mods&glfw.ModShift != 0 k.Ctrl = mods&glfw.ModControl != 0 k.Alt = mods&glfw.ModAlt != 0 k.Super = mods&glfw.ModSuper != 0 k.Command = commandKey(k) if key >= KeyEscape || action == glfw.Release { k.Text = "" if w.keyFocus != nil { if k.action != glfw.Release { w.keyFocus.KeyPress(k) } else { w.keyFocus.KeyRelease(k) } } } }) }) w.w.OnChar(func(char rune) { w.Do(func() { if char < KeyEscape { k.Text = string(char) if w.keyFocus != nil { if k.action != glfw.Release { w.keyFocus.KeyPress(k) } else { w.keyFocus.KeyRelease(k) } } } }) }) m := MouseEvent{} w.w.OnMouseMove(func(x, y float64) { m.Pos = Pt(x, y) m.Move, m.Press, m.Release, m.Drag = true, false, false, false w.mouse(m) }) w.w.OnMouseButton(func(button, action, mods int) { m.Button = button m.Move, m.Press, m.Release, m.Drag = false, action == glfw.Press, action == glfw.Release, false w.mouse(m) }) w.w.OnScroll(func(dx, dy float64) { w.Do(func() { s := ScrollEvent{m.Pos, Pt(dx, -dy)} s.Pos = w.mapToWindow(s.Pos) v, _ := viewAtFunc(w.Self, s.Pos, func(v View) View { v, _ = v.(ScrollerView) return v }).(ScrollerView) if v != nil { s.Pos = Map(s.Pos, w.Self, v) v.Scroll(s) } }) }) }
func (w *Window) framebufferResized(width, height int) { w.bufWidth, w.bufHeight = gl.Sizei(width), gl.Sizei(height) gl.Viewport(0, 0, w.bufWidth, w.bufHeight) }
func (g *Game) renderLocalArchitect(region g2.Region, local *LocalData) { local.architect.camera.doArchitectFocusRegion(g, local.sys) gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() // Set the viewport so that we only render into the region that we're supposed // to render to. // TODO: Check if this works on all graphics cards - I've heard that the opengl // spec doesn't actually require that viewport does any clipping. gl.PushAttrib(gl.VIEWPORT_BIT) gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy)) defer gl.PopAttrib() current := local.architect.camera.current gl.Ortho( gl.Double(current.mid.X-current.dims.X/2), gl.Double(current.mid.X+current.dims.X/2), gl.Double(current.mid.Y+current.dims.Y/2), gl.Double(current.mid.Y-current.dims.Y/2), gl.Double(1000), gl.Double(-1000), ) defer func() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) }() gl.MatrixMode(gl.MODELVIEW) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) zoom := local.architect.camera.current.dims.X / float64(region.Dims.Dx) level := g.Levels[GidInvadersStart] level.ManaSource.Draw(local, zoom, float64(level.Room.Dx), float64(level.Room.Dy)) gl.Begin(gl.LINES) gl.Color4d(1, 1, 1, 1) for _, poly := range g.Levels[GidInvadersStart].Room.Walls { for i := range poly { seg := poly.Seg(i) gl.Vertex2d(gl.Double(seg.P.X), gl.Double(seg.P.Y)) gl.Vertex2d(gl.Double(seg.Q.X), gl.Double(seg.Q.Y)) } } gl.End() gl.Color4ub(0, 255, 0, 255) for side, pos := range g.Levels[GidInvadersStart].Room.Starts { base.GetDictionary("luxisr").RenderString(fmt.Sprintf("S%d", side), pos.X, pos.Y, 0, 100, gui.Center) } gl.Color4d(1, 1, 1, 1) for _, ent := range g.temp.AllEnts { ent.Draw(g, -1) // TODO: Side isn't defined for architect yet } gl.Disable(gl.TEXTURE_2D) g.renderLosMask(local) if local.architect.abs.activeAbility != nil { local.architect.abs.activeAbility.Draw("", g, -1) // TODO: side not defined for architect } }
// For invaders or moba, does a lot of basic stuff common to both func (g *Game) renderLocalHelper(region g2.Region, local *LocalData, camera *cameraInfo, side int) { camera.doInvadersFocusRegion(g, side) gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() // Set the viewport so that we only render into the region that we're supposed // to render to. // TODO: Check if this works on all graphics cards - I've heard that the opengl // spec doesn't actually require that viewport does any clipping. gl.PushAttrib(gl.VIEWPORT_BIT) gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy)) defer gl.PopAttrib() current := camera.current gl.Ortho( gl.Double(current.mid.X-current.dims.X/2), gl.Double(current.mid.X+current.dims.X/2), gl.Double(current.mid.Y+current.dims.Y/2), gl.Double(current.mid.Y-current.dims.Y/2), gl.Double(1000), gl.Double(-1000), ) defer func() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) }() gl.MatrixMode(gl.MODELVIEW) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) level := g.Levels[GidInvadersStart] zoom := camera.current.dims.X / float64(region.Dims.Dx) level.ManaSource.Draw(local, zoom, float64(level.Room.Dx), float64(level.Room.Dy)) gl.Color4d(1, 1, 1, 1) var expandedPoly linear.Poly for _, poly := range g.Levels[GidInvadersStart].Room.Walls { // Don't draw counter-clockwise polys, specifically this means don't draw // the boundary of the level. if poly.IsCounterClockwise() { continue } // KLUDGE: This will expand the polygon slightly so that it actually shows // up when the los shadows are drawn over it. Eventually there should be // separate los polys, colision polys, and draw polys so that this isn't // necessary. gl.Begin(gl.TRIANGLE_FAN) expandPoly(poly, &expandedPoly) for _, v := range expandedPoly { gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y)) } gl.End() } gui.SetFontColor(0, 255, 0, 255) for side, pos := range g.Levels[GidInvadersStart].Room.Starts { base.GetDictionary("luxisr").RenderString(fmt.Sprintf("S%d", side), pos.X, pos.Y, 0, 100, gui.Center) } gl.Color4d(1, 1, 1, 1) for _, ent := range g.temp.AllEnts { ent.Draw(g, side) } gl.Disable(gl.TEXTURE_2D) if local.mode != LocalModeMoba { panic("Need to implement drawing players from standard mode data") } for i := range local.moba.players { p := &local.moba.players[i] if p.abs.activeAbility != nil { p.abs.activeAbility.Draw(p.gid, g, side) } } for _, proc := range g.Processes { proc.Draw(Gid(""), g, side) } gl.Color4ub(0, 0, 255, 200) g.renderLosMask(local) }
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() } }