Exemple #1
0
// 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)
}
Exemple #2
0
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()
		}
	}
}
Exemple #3
0
func (w *Window) resized(width, height int) {
	wid, hei := float64(width), float64(height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, gl.Double(wid), 0, gl.Double(hei), -1, 1)
	w.Self.Resize(wid, hei)
	if w.centralView != nil {
		w.centralView.Resize(wid, hei)
	}
}
Exemple #4
0
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{})
}
Exemple #5
0
func (o *OpenGl) set2dView() {
	gl.Disable(gl.TEXTURE_2D)
	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, gl.Double(o.width), 0, gl.Double(o.height), -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Exemple #6
0
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)
	}
}
Exemple #7
0
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)
	}
}
Exemple #8
0
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
}
Exemple #9
0
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()
}
Exemple #10
0
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
}
Exemple #11
0
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()
	}
}
Exemple #12
0
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()
}
Exemple #13
0
func Enable2d(x1, y1, w, h gl.Double) {

	// Save a copy of the proj matrix so we can restore it
	// when we want to do more 3d rendering
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()

	// Set up orthographic projection
	gl.Ortho(x1, x1+w, y1, y1+h, 0.0, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	// Make sure depth testing and lighting are disabled for 2d redering
	// until we are fninished rendering in 2d
	gl.PushAttrib(gl.DEPTH_BUFFER_BIT | gl.LIGHTING_BIT)
	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
}
Exemple #14
0
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]))
}
Exemple #15
0
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)
			}
		})
	})
}
Exemple #16
0
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
	}
}
Exemple #17
0
// 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)
}
Exemple #18
0
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()
	}
}
Exemple #19
0
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()
	}
}