Exemplo n.º 1
0
func (f *lightning) Draw(ent game.Ent, g *game.Game) {
	if !f.draw {
		return
	}
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4ub(255, 255, 255, 255)
	forward := (linear.Vec2{1, 0}).Rotate(ent.Angle()).Scale(100000.0)
	gl.Begin(gl.LINES)
	v := ent.Pos().Add(forward)
	gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y))
	v = ent.Pos().Sub(forward)
	gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y))
	gl.End()
}
Exemplo n.º 2
0
func (p *riftWalkProcess) Draw(gid game.Gid, g *game.Game, side int) {
	player, ok := g.Ents[p.PlayerGid].(*game.PlayerEnt)
	if !ok {
		return
	}
	if side != player.Side() {
		return
	}
	frac := p.Stored.Magnitude() / p.Threshold
	if frac < 1 {
		gl.Color4ub(255, 0, 0, 255)
	} else {
		gl.Color4ub(0, 255, 0, 255)
	}
	base.EnableShader("status_bar")
	var outer float32 = 0.2
	var increase float32 = 0.01
	if frac > 1 {
		frac = 1
	}
	base.SetUniformF("status_bar", "frac", float32(frac))
	base.SetUniformF("status_bar", "inner", outer-increase)
	base.SetUniformF("status_bar", "outer", outer)
	base.SetUniformF("status_bar", "buffer", 0.01)
	texture.Render(player.Pos().X-100, player.Pos().Y-100, 200, 200)
	base.EnableShader("")

	dist, radius := p.GetVals()
	dest := player.Pos().Add((linear.Vec2{dist, 0}).Rotate(player.Angle))
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4d(1, 1, 1, 1)
	gl.Begin(gl.LINES)
	gl.Vertex2d(gl.Double(player.Pos().X), gl.Double(player.Pos().Y))
	gl.Vertex2d(gl.Double(dest.X), gl.Double(dest.Y))
	gl.End()
	n := 20
	gl.Begin(gl.LINES)
	for i := 0; i < n; i++ {
		v1 := dest.Add((linear.Vec2{radius, 0}).Rotate(float64(i) / float64(n) * 2 * math.Pi))
		v2 := dest.Add((linear.Vec2{radius, 0}).Rotate(float64(i+1) / float64(n) * 2 * math.Pi))
		gl.Vertex2d(gl.Double(v1.X), gl.Double(v1.Y))
		gl.Vertex2d(gl.Double(v2.X), gl.Double(v2.Y))
	}
	gl.End()
}
Exemplo n.º 3
0
func (gw *GameWindow) Draw(region gui.Region) {
	gw.region = region
	latest_region = region
	gl.PushMatrix()
	defer gl.PopMatrix()
	gl.Translated(gl.Double(gw.region.X), gl.Double(gw.region.Y), 0)

	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gw.game.manaSource.Draw(gw, float64(gw.game.Dx), float64(gw.game.Dy))

	gl.Begin(gl.LINES)
	gl.Color4d(1, 1, 1, 1)
	for _, poly := range gw.game.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.Begin(gl.TRIANGLE_FAN)
	gl.Color4d(1, 0, 0, 1)
	for _, poly := range gw.game.Room.Lava {
		for _, v := range poly {
			gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y))
		}
	}
	gl.End()

	gl.Color4d(1, 1, 1, 1)
	for _, ent := range gw.game.Ents {
		ent.Draw(gw.game)
	}
	gl.Disable(gl.TEXTURE_2D)

	for _, player := range local.players {
		if player.active_ability != nil {
			player.active_ability.Draw(player.id, gw.game)
		}
	}
	// base.GetDictionary("luxisr").RenderString("monkeys!!!", 10, 10, 0, float64(gw.game.Game_thinks), gin.Left)
}
Exemplo n.º 4
0
func (l *Los) Render() {
	var v0, v1 linear.Vec2
	gl.Begin(gl.TRIANGLES)
	v1 = (linear.Vec2{-1, 0}).Scale(math.Sqrt(float64(l.in.Buffer.ZBuffer[0]))).Add(l.in.Pos)
	for i := 1; i <= len(l.in.Buffer.ZBuffer); i++ {
		dist := math.Sqrt(float64(l.in.Buffer.ZBuffer[i%len(l.in.Buffer.ZBuffer)]))
		angle := 2 * math.Pi * (float64(i%len(l.in.Buffer.ZBuffer))/float64(len(l.in.Buffer.ZBuffer)) - 0.5)
		if dist <= 0.0 {
			continue
		}
		v0 = v1
		gl.Color4d(gl.Double(1.0-dist/math.Sqrt(float64(l.in.Horizon))), 1.0, 0.0, 1.0)
		v1 = (linear.Vec2{1, 0}).Rotate(angle).Scale(dist).Add(l.in.Pos)
		gl.Vertex2d(gl.Double(l.in.Pos.X), gl.Double(l.in.Pos.Y))
		gl.Vertex2d(gl.Double(v0.X), gl.Double(v0.Y))
		gl.Vertex2d(gl.Double(v1.X), gl.Double(v1.Y))
	}
	gl.End()
}
Exemplo n.º 5
0
func (g *Game) renderEdges() {
	// Draw edges between nodes
	for _, ent := range g.Ents {
		cp0, ok := ent.(*ControlPoint)
		if !ok {
			continue
		}
		for _, target := range cp0.Targets {
			cp1, ok := g.Ents[target].(*ControlPoint)
			if !ok {
				continue
			}
			ally := 0
			enemy := 0
			if cp0.Side() == g.local.Side {
				ally++
			} else if cp0.Side() == -1 {
				enemy++
			}
			if cp1.Side() == g.local.Side {
				ally++
			} else if cp1.Side() == -1 {
				enemy++
			}
			if ally == 2 {
				gl.Color4ub(0, 255, 0, 255)
			} else if enemy == 2 {
				gl.Color4ub(255, 0, 0, 255)
			} else if ally == 1 {
				gl.Color4ub(255, 255, 0, 255)
			} else if enemy == 1 {
				gl.Color4ub(255, 0, 0, 255)
			} else {
				gl.Color4ub(200, 200, 200, 255)
			}
			gl.Begin(gl.LINES)
			gl.Vertex2d(gl.Double(cp0.Pos().X), gl.Double(cp0.Pos().Y))
			gl.Vertex2d(gl.Double(cp1.Pos().X), gl.Double(cp1.Pos().Y))
			gl.End()
		}
	}
}
Exemplo n.º 6
0
func (editor *editorData) renderPlaceBlock(g *Game) {
	var expandedPoly linear.Poly
	expandPoly(editor.getPoly(g), &expandedPoly)
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4d(1, 1, 1, 1)
	gl.Begin(gl.TRIANGLE_FAN)
	for _, v := range expandedPoly {
		gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y))
	}
	gl.End()
}
Exemplo n.º 7
0
func (editor *editorData) renderPathing(room *Room, pathing *PathingData) {
	if !editor.pathing.on {
		return
	}
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4ub(255, 255, 255, 255)
	gl.Begin(gl.LINES)
	for x := 0; x <= room.Dx; x += pathingDataGrid {
		gl.Vertex2d(gl.Double(x), 0)
		gl.Vertex2d(gl.Double(x), gl.Double(room.Dy))
	}
	for y := 0; y <= room.Dy; y += pathingDataGrid {
		gl.Vertex2d(0, gl.Double(y))
		gl.Vertex2d(gl.Double(room.Dx), gl.Double(y))
	}
	gl.End()
	dst := editor.cursorPosInGameCoords(room)

	tri := [3]linear.Vec2{
		(linear.Vec2{0.6, 0}).Scale(pathingDataGrid / 2),
		(linear.Vec2{-0.2, 0.2}).Scale(pathingDataGrid / 2),
		(linear.Vec2{-0.2, -0.2}).Scale(pathingDataGrid / 2),
	}

	gl.Begin(gl.TRIANGLES)
	for x := 0; x < room.Dx; x += pathingDataGrid {
		for y := 0; y < room.Dy; y += pathingDataGrid {
			src := linear.Vec2{
				float64(x) + pathingDataGrid/2.0,
				float64(y) + pathingDataGrid/2.0,
			}
			angle := pathing.Dir(src, dst).Angle()
			for _, v := range tri {
				p := v.Rotate(angle).Add(src)
				gl.Vertex2d(gl.Double(p.X), gl.Double(p.Y))
			}
		}
	}
	gl.End()
	// pathing.Dir(src, dst)
}
Exemplo n.º 8
0
func (p *pullProcess) Draw(player_id int, g *game.Game) {
	gl.Color4d(1, 1, 1, 1)
	gl.Disable(gl.TEXTURE_2D)
	player := g.GetEnt(player_id).(*game.Player)
	v1 := player.Pos()
	v2 := v1.Add(linear.Vec2{1000, 0})
	v3 := v2.RotateAround(v1, player.Angle-p.Angle/2)
	v4 := v2.RotateAround(v1, player.Angle+p.Angle/2)
	gl.Begin(gl.LINES)
	vs := []linear.Vec2{v3, v4, linear.Vec2{player.X, player.Y}}
	for i := range vs {
		gl.Vertex2d(gl.Double(vs[i].X), gl.Double(vs[i].Y))
		gl.Vertex2d(gl.Double(vs[(i+1)%len(vs)].X), gl.Double(vs[(i+1)%len(vs)].Y))
	}
	gl.End()
	s := fmt.Sprintf("%.2f", p.supplied)
	base.Log().Printf("'%s'", s)
	if true {
		base.GetDictionary("luxisr").RenderString(s, 10, 10, 0, 50, gin.Left)
	}
}
Exemplo n.º 9
0
func (g *Game) renderLosMask(local *LocalData) {
	ent := g.Ents[local.moba.currentPlayer.gid]
	if ent == nil {
		return
	}
	walls := g.temp.VisibleWallCache[GidInvadersStart].GetWalls(int(ent.Pos().X), int(ent.Pos().Y))
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4ub(0, 0, 0, 255)
	gl.Begin(gl.TRIANGLES)
	for _, wall := range walls {
		if wall.Right(ent.Pos()) {
			continue
		}
		a := wall.P
		b := ent.Pos().Sub(wall.P).Norm().Scale(-10000.0).Add(wall.P)
		mid := wall.P.Add(wall.Q).Scale(0.5)
		c := ent.Pos().Sub(mid).Norm().Scale(-10000.0).Add(mid)
		d := ent.Pos().Sub(wall.Q).Norm().Scale(-10000.0).Add(wall.Q)
		e := wall.Q
		gl.Vertex2d(gl.Double(a.X), gl.Double(a.Y))
		gl.Vertex2d(gl.Double(b.X), gl.Double(b.Y))
		gl.Vertex2d(gl.Double(c.X), gl.Double(c.Y))

		gl.Vertex2d(gl.Double(a.X), gl.Double(a.Y))
		gl.Vertex2d(gl.Double(c.X), gl.Double(c.Y))
		gl.Vertex2d(gl.Double(d.X), gl.Double(d.Y))

		gl.Vertex2d(gl.Double(a.X), gl.Double(a.Y))
		gl.Vertex2d(gl.Double(d.X), gl.Double(d.Y))
		gl.Vertex2d(gl.Double(e.X), gl.Double(e.Y))
	}
	gl.End()
	base.EnableShader("horizon")
	base.SetUniformV2("horizon", "center", ent.Pos())
	base.SetUniformF("horizon", "horizon", LosMaxDist)
	gl.Begin(gl.QUADS)
	dx := gl.Int(g.Levels[GidInvadersStart].Room.Dx)
	dy := gl.Int(g.Levels[GidInvadersStart].Room.Dy)
	gl.Vertex2i(0, 0)
	gl.Vertex2i(dx, 0)
	gl.Vertex2i(dx, dy)
	gl.Vertex2i(0, dy)
	gl.End()
	base.EnableShader("")
}
Exemplo n.º 10
0
func (p *lightningBoltProc) Draw(src, obs game.Gid, game *game.Game) {
	if p.NumThinks < p.BuildThinks {
		return
	}
	base.EnableShader("lightning")
	base.SetUniformV2("lightning", "dir", p.Seg.Ray().Norm())
	base.SetUniformV2("lightning", "bolt_root", p.Seg.P.Add(p.Seg.Q).Scale(0.5))

	base.SetUniformF("lightning", "bolt_thickness", 1.1)
	gl.Disable(gl.TEXTURE_2D)
	displayWidth := p.Width * 10
	perp := p.Seg.Ray().Cross().Norm().Scale(displayWidth / 2)
	move := float32(p.NumThinks) / float32(60) / 10.0
	for i := 0; i < 3; i++ {
		base.SetUniformF("lightning", "rand_offset", float32(i)+move)
		if i == 2 {
			base.SetUniformF("lightning", "bolt_thickness", 1.3)
		}
		switch i {
		case 0:
			gl.Color4ub(255, 200, 200, 200)
		case 1:
			gl.Color4ub(255, 255, 200, 200)
		case 2:
			gl.Color4ub(255, 255, 230, 225)
		}
		gl.Begin(gl.QUADS)
		v := p.Seg.P.Add(perp)
		gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y))
		v = p.Seg.Q.Add(perp)
		gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y))
		v = p.Seg.Q.Sub(perp)
		gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y))
		v = p.Seg.P.Sub(perp)
		gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y))
		gl.End()
	}
	base.EnableShader("")
}
Exemplo n.º 11
0
func (p *pullProcess) Draw(gid game.Gid, g *game.Game, side int) {
	player, ok := g.Ents[p.PlayerGid].(*game.PlayerEnt)
	if !ok {
		return
	}
	if side != player.Side() {
		return
	}
	gl.Color4d(1, 1, 1, 1)
	gl.Disable(gl.TEXTURE_2D)
	v1 := player.Pos()
	v2 := v1.Add(linear.Vec2{1000, 0})
	v3 := v2.RotateAround(v1, player.Angle-p.Angle/2)
	v4 := v2.RotateAround(v1, player.Angle+p.Angle/2)
	gl.Begin(gl.LINES)
	vs := []linear.Vec2{v3, v4, player.Pos()}
	for i := range vs {
		gl.Vertex2d(gl.Double(vs[i].X), gl.Double(vs[i].Y))
		gl.Vertex2d(gl.Double(vs[(i+1)%len(vs)].X), gl.Double(vs[(i+1)%len(vs)].Y))
	}
	gl.End()
}
Exemplo n.º 12
0
func (p *pull) Draw(ent game.Ent, g *game.Game) {
	if !p.draw {
		return
	}
	player, ok := ent.(*game.PlayerEnt)
	if !ok {
		return
	}
	// TODO: Don't draw for enemies?
	gl.Color4d(1, 1, 1, 1)
	gl.Disable(gl.TEXTURE_2D)
	v1 := player.Pos()
	v2 := v1.Add(linear.Vec2{1000, 0})
	v3 := v2.RotateAround(v1, player.Angle()-p.angle/2)
	v4 := v2.RotateAround(v1, player.Angle()+p.angle/2)
	gl.Begin(gl.LINES)
	vs := []linear.Vec2{v3, v4, player.Pos()}
	for i := range vs {
		gl.Vertex2d(gl.Double(vs[i].X), gl.Double(vs[i].Y))
		gl.Vertex2d(gl.Double(vs[(i+1)%len(vs)].X), gl.Double(vs[(i+1)%len(vs)].Y))
	}
	gl.End()
}
Exemplo n.º 13
0
func (s *SegDisplay) top() {
	gl.Begin(gl.POLYGON)
	gl.Vertex2d(-s.mW*0.8, +s.mH*0.8)
	gl.Vertex2d(-s.mW*0.9, +s.mH*0.9)
	gl.Vertex2d(-s.mW*0.8, +s.mH*1.0)
	gl.Vertex2d(+s.mW*0.8, +s.mH*1.0)
	gl.Vertex2d(+s.mW*0.9, +s.mH*0.9)
	gl.Vertex2d(+s.mW*0.8, +s.mH*0.8)
	gl.End()
}
Exemplo n.º 14
0
func (s *SegDisplay) upperMidRight() {
	gl.Begin(gl.POLYGON)
	gl.Vertex2d(+s.mW*0.8, +s.mH*0.1)
	gl.Vertex2d(+s.mW*0.9, +s.mH*0.1)
	gl.Vertex2d(+s.mW*0.9, +s.mH*0.2)
	gl.Vertex2d(+s.mW*0.1, +s.mH*0.9)
	gl.Vertex2d(+s.mW*0.0, +s.mH*0.9)
	gl.Vertex2d(+s.mW*0.0, +s.mH*0.8)
	gl.End()
}
Exemplo n.º 15
0
func (s *SegDisplay) upperLeft() {
	gl.Begin(gl.POLYGON)
	gl.Vertex2d(-s.mW*1.0, +s.mH*0.8)
	gl.Vertex2d(-s.mW*0.9, +s.mH*0.9)
	gl.Vertex2d(-s.mW*0.8, +s.mH*0.8)
	gl.Vertex2d(-s.mW*0.8, +s.mH*0.1)
	gl.Vertex2d(-s.mW*0.9, +s.mH*0.0)
	gl.Vertex2d(-s.mW*1.0, +s.mH*0.1)
	gl.End()
}
Exemplo n.º 16
0
func (s *SegDisplay) midRight() {
	gl.Begin(gl.POLYGON)
	gl.Vertex2d(+s.mW*0.1, -s.mH*0.1)
	gl.Vertex2d(+s.mW*0.0, +s.mH*0.0)
	gl.Vertex2d(+s.mW*0.1, +s.mH*0.1)
	gl.Vertex2d(+s.mW*0.8, +s.mH*0.1)
	gl.Vertex2d(+s.mW*0.9, +s.mH*0.0)
	gl.Vertex2d(+s.mW*0.8, -s.mH*0.1)
	gl.End()
}
Exemplo n.º 17
0
func (s *SegDisplay) lowerMid() {
	gl.Begin(gl.POLYGON)
	gl.Vertex2d(-s.mW*0.1, -s.mH*0.8)
	gl.Vertex2d(+s.mW*0.0, -s.mH*0.9)
	gl.Vertex2d(+s.mW*0.1, -s.mH*0.8)
	gl.Vertex2d(+s.mW*0.1, -s.mH*0.1)
	gl.Vertex2d(+s.mW*0.0, -s.mH*0.0)
	gl.Vertex2d(-s.mW*0.1, -s.mH*0.1)
	gl.End()
}
Exemplo n.º 18
0
func (s *SegDisplay) lowerRight() {
	gl.Begin(gl.POLYGON)
	gl.Vertex2d(+s.mW*1.0, -s.mH*0.8)
	gl.Vertex2d(+s.mW*0.9, -s.mH*0.9)
	gl.Vertex2d(+s.mW*0.8, -s.mH*0.8)
	gl.Vertex2d(+s.mW*0.8, -s.mH*0.1)
	gl.Vertex2d(+s.mW*0.9, -s.mH*0.0)
	gl.Vertex2d(+s.mW*1.0, -s.mH*0.1)
	gl.End()
}
Exemplo n.º 19
0
func (g *Game) renderWalls() {
	gl.Color4d(1, 1, 1, 1)
	var expandedPoly linear.Poly
	for _, poly := range g.Level.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()
	}
}
Exemplo n.º 20
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
	}
}
Exemplo n.º 21
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)
}
Exemplo n.º 22
0
func main() {
	{
		f, err := os.Create("/Users/jwills/code/src/github.com/runningwild/shadertest/log.err")
		if err != nil {
			panic("shoot")
		}
		os.Stderr = f
		f, err = os.Create("/Users/jwills/code/src/github.com/runningwild/shadertest/log.out")
		if err != nil {
			panic("shoot")
		}
		os.Stdout = f
	}
	sys.Startup()
	err := gl.Init()
	if err != nil {
		panic(err)
	}
	fmt.Printf("RAWR!!!\n")
	render.Init()
	render.Queue(func() {
		sys.CreateWindow(10, 10, wdx, wdy)
		sys.EnableVSync(true)
		err := gl.Init()
		if err != nil {
			panic(err)
		}
	})
	base.InitShaders()
	runtime.GOMAXPROCS(2)
	ui, err = gui.Make(gin.In(), gui.Dims{wdx, wdy}, filepath.Join(datadir, "fonts", "skia.ttf"))
	if err != nil {
		panic(err)
	}

	anchor := gui.MakeAnchorBox(gui.Dims{wdx, wdy})
	ui.AddChild(anchor)
	var v float64
	// var profile_output *os.File
	// var num_mem_profiles int
	// ui.AddChild(base.MakeConsole())
	size := 19.0
	base.InitShaders()
	x := gl.Double(0.0)
	// y := 0.0
	// tex := texture.LoadFromPath(filepath.Join(base.GetDataDir(), "test/out.dff.small.png"))
	fmt.Printf("RAWR!\n")
	listener := Listener{}
	gin.In().RegisterEventListener(&listener)
	button := gin.In().GetKeyFlat(gin.ControllerButton0+6, gin.DeviceTypeController, gin.DeviceIndexAny)
	fmt.Printf("RAWR!\n")
	for button.FramePressCount() == 0 {
		sys.Think()
		// dsize := gin.In().GetKey(gin.MouseWheelVertical).FramePressAmt()
		// size += dsize
		// x -= float64(tex.Dx()) * dsize / 2
		// y -= float64(tex.Dy()) * dsize / 2
		// if gin.In().GetKey(gin.Down).FramePressAmt() > 0 {
		// 	y += 10
		// }
		// if gin.In().GetKey(gin.Up).FramePressAmt() > 0 {
		// 	y -= 10
		// }
		// if gin.In().GetKey(gin.Left).FramePressAmt() > 0 {
		// 	x += 10
		// }
		// if gin.In().GetKey(gin.Right).FramePressAmt() > 0 {
		// 	x -= 10
		// }
		render.Queue(func() {
			ui.Draw()
			gl.Enable(gl.BLEND)
			gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			gl.Disable(gl.TEXTURE_2D)
			gl.Color4ub(255, 0, 0, 255)
			gl.Begin(gl.QUADS)
			gl.Vertex2d(100+x, 20)
			gl.Vertex2d(100+x, gl.Double(size+20))
			gl.Vertex2d(200+x, gl.Double(size+20))
			gl.Vertex2d(200+x, 20)
			x += 1
			gl.End()
			gl.Enable(gl.TEXTURE_2D)
			gl.Color4ub(255, 255, 255, 255)
			// // str := "!@#$%^&*"
			// diff := 5.0 / (math.Log(size) + math.Pow(size, 0.7))

			// // Works for 1200
			// diff = 50 * math.Pow(base.GetDictionary("skia").Scale(), 2) / math.Pow(size, 1.0)

			// // Works for 3000
			// diff = 50 * math.Pow(base.GetDictionary("skia").Scale(), 1.5) / math.Pow(size, 0.8)
			// //0.340637
			// //0.159241
			// diff = 75 * math.Pow(base.GetDictionary("skia").Scale(), 1.0) / math.Pow(size, 1.0)
			// diff = 10 / math.Pow(size, 1.0)
			// diff = 20/math.Pow(size, 1.0) + 5*math.Pow(base.GetDictionary("skia").Scale(), 1.0)/math.Pow(size, 1.0)
			// if diff > 0.45 {
			//   diff = 0.45
			// }
			// base.EnableShader("distance_field")
			// base.SetUniformF("distance_field", "dist_min", float32(0.5-diff))
			// base.SetUniformF("distance_field", "dist_max", float32(0.5+diff))
			// base.GetDictionary("skia").RenderString(str, 100, 20, 0, dy, gui.Left)
			// base.GetDictionary("skia").RenderString(str, 100, 20+2*dy, 0, dy/4, gui.Left)
			// base.GetDictionary("skia").RenderString(str, 100, 20, 0, size, gui.Left)
			lorem := "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"
			kk := gin.In().GetKeyFlat(gin.ControllerAxis0Positive+1, gin.DeviceTypeController, device_index)
			kl := gin.In().GetKeyFlat(gin.ControllerAxis0Positive+1, gin.DeviceTypeController, gin.DeviceIndexAny)
			s := fmt.Sprintf("%1.2f %1.2f - %1.2f %1.2f", kk.FramePressAvg(), kk.FramePressAmt(), kl.FramePressAvg(), kl.FramePressAmt())
			devices := sys.GetActiveDevices()
			y := 500.0
			for _, t := range []gin.DeviceType{gin.DeviceTypeController, gin.DeviceTypeKeyboard, gin.DeviceTypeMouse} {
				for _, d := range devices[t] {
					var s string
					switch t {
					case gin.DeviceTypeController:
						s = "controller"
					case gin.DeviceTypeKeyboard:
						s = "keyboard"
					case gin.DeviceTypeMouse:
						s = "mouse"
					}
					base.GetDictionary("skia").RenderString(fmt.Sprintf("%s: %d", s, d), 100, y, 0, 45, gui.Left)
					y -= 50
				}
			}
			base.GetDictionary("luxisr").RenderString(s, 50, 50, 0, size, gui.Left)
			// base.GetDictionary("luxisr").RenderString(lorem, 50, 50+size, 0, size, gui.Left)
			base.GetDictionary("skia").RenderString(lorem, 50, 50+2*size, 0, size, gui.Left)
			base.Log().Printf("Foo")
			//      base.EnableShader("")
			// gl.Enable(gl.ALPHA_TEST)
			// gl.AlphaFunc(gl.GREATER, 0.5)
			// tex := texture.LoadFromPath(filepath.Join(base.GetDataDir(), "ships/ship.png"))
			// tex.Bind()
			// tex.RenderAdvanced(x, y, float64(tex.Dx())*size, float64(tex.Dy())*size, 0, true)
			// tex.RenderNatural(300, 100)
			// gl.Disable(gl.ALPHA_TEST)
		})
		render.Queue(func() {
			sys.SwapBuffers()
		})
		render.Purge()

		// if key_map["cpu profile"].FramePressCount() > 0 {
		// 	if profile_output == nil {
		// 		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 start CPU profile: %v\n", err)
		// 		}
		// 	} else {
		// 		pprof.StopCPUProfile()
		// 		profile_output.Close()
		// 		profile_output = nil
		// 	}
		// }

		// if key_map["mem profile"].FramePressCount() > 0 {
		// 	f, err := os.Create(filepath.Join(datadir, fmt.Sprintf("mem.%d.prof", num_mem_profiles)))
		// 	if err != nil {
		// 		base.Error().Printf("Unable to write mem profile: %v", err)
		// 	}
		// 	pprof.WriteHeapProfile(f)
		// 	f.Close()
		// 	num_mem_profiles++
		// }

		v += 0.01
	}
}