func (c *Console) DrawFocused(region gui.Region) { gl.Color4d(0.2, 0, 0.3, 0.8) gl.Disable(gl.TEXTURE_2D) gl.Begin(gl.QUADS) { x := gl.Int(region.X) y := gl.Int(region.Y) x2 := gl.Int(region.X + region.Dx) y2 := gl.Int(region.Y + region.Dy) gl.Vertex2i(x, y) gl.Vertex2i(x, y2) gl.Vertex2i(x2, y2) gl.Vertex2i(x2, y) } gl.End() gl.Color4d(1, 1, 1, 1) y := float64(region.Y) + float64(len(c.lines))*lineHeight do_color := func(line string) { if strings.HasPrefix(line, "LOG") { gl.Color4d(1, 1, 1, 1) } if strings.HasPrefix(line, "WARN") { gl.Color4d(1, 1, 0, 1) } if strings.HasPrefix(line, "ERROR") { gl.Color4d(1, 0, 0, 1) } } if c.start > c.end { for i := c.start; i < len(c.lines); i++ { do_color(c.lines[i]) c.dict.RenderString(c.lines[i], c.xscroll, y, 0, lineHeight, gui.Left) y -= lineHeight } for i := 0; i < c.end; i++ { do_color(c.lines[i]) c.dict.RenderString(c.lines[i], c.xscroll, y, 0, lineHeight, gui.Left) y -= lineHeight } } else { for i := c.start; i < c.end && i < len(c.lines); i++ { do_color(c.lines[i]) c.dict.RenderString(c.lines[i], c.xscroll, y, 0, lineHeight, gui.Left) y -= lineHeight } } }
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) }
func (g *Game) renderEntsAndAbilities() { gl.Color4d(1, 1, 1, 1) for _, ent := range g.local.temp.AllEnts { ent.Draw(g) for _, ab := range ent.Abilities() { ab.Draw(ent, g) } } }
func (sp *SpawnPoint) Render(pos mathgl.Vec2, width float32) { gl.Disable(gl.TEXTURE_2D) gl.Color4d(1, 1, 1, 0.1) gl.Begin(gl.QUADS) gl.Vertex2f(pos.X-width/2, pos.Y) gl.Vertex2f(pos.X-width/2, pos.Y+width) gl.Vertex2f(pos.X+width/2, pos.Y+width) gl.Vertex2f(pos.X+width/2, pos.Y) gl.End() }
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() }
func (c *iconWithText) Draw(hovered, selected, selectable bool, region gui.Region) { var f float64 switch { case selected: f = 1.0 case hovered || selectable: f = 0.6 default: f = 0.4 } gl.Color4d(f, f, f, 1) c.Icon.Data().RenderNatural(region.X, region.Y) if hovered && selectable { if selected { gl.Color4d(1, 0, 0, 0.3) } else { gl.Color4d(1, 0, 0, 1) } gl.Disable(gl.TEXTURE_2D) gl.Begin(gl.LINES) x := int32(region.X + 1) y := int32(region.Y + 1) x2 := int32(region.X + region.Dx - 1) y2 := int32(region.Y + region.Dy - 1) gl.Vertex2i(x, y) gl.Vertex2i(x, y2) gl.Vertex2i(x, y2) gl.Vertex2i(x2, y2) gl.Vertex2i(x2, y2) gl.Vertex2i(x2, y) gl.Vertex2i(x2, y) gl.Vertex2i(x, y) gl.End() } }
func (sb *spriteBox) Draw(region gui.Region) { gl.Disable(gl.TEXTURE_2D) gl.Color4d(sb.r, sb.g, sb.b, 1) gl.Begin(gl.QUADS) gl.Vertex2i(int32(region.X+region.Dx/3), int32(region.Y)) gl.Vertex2i(int32(region.X+region.Dx/3), int32(region.Y+region.Dy)) gl.Vertex2i(int32(region.X+region.Dx/3*2), int32(region.Y+region.Dy)) gl.Vertex2i(int32(region.X+region.Dx/3*2), int32(region.Y)) gl.End() if sb.s != nil { gl.Enable(gl.TEXTURE_2D) tx, ty, tx2, ty2 := sb.s.Bind() // fmt.Printf("Tex: %f %f %f %f\n", tx, ty, tx2, ty2) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Color4f(1, 1, 1, 1) gl.Begin(gl.QUADS) x := int32(region.X + region.Dx/2) y := int32(region.Y + region.Dy/2) gl.TexCoord2d(tx, -ty) gl.Vertex2i(x-50, y-75) gl.TexCoord2d(tx, -ty2) gl.Vertex2i(x-50, y+75) gl.TexCoord2d(tx2, -ty2) gl.Vertex2i(x+50, y+75) gl.TexCoord2d(tx2, -ty) gl.Vertex2i(x+50, y-75) gl.End() gl.Color4d(1, 1, 1, 1) text := fmt.Sprintf("%d : %s : %s", sb.s.Facing(), sb.s.Anim(), sb.s.AnimState()) if sb.top { dict.RenderString(text, float64(region.X), float64(region.Y+region.Dy)-dict.MaxHeight(), 0, dict.MaxHeight(), gui.Left) } else { dict.RenderString(text, float64(region.X), float64(region.Y), 0, dict.MaxHeight(), gui.Left) } } }
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() }
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() }
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) } }
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() } }
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() }
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() }
func (c *Console) Draw(x, y, dx, dy int) { if !gin.In().GetKeyFlat(gin.EitherShift, gin.DeviceTypeAny, gin.DeviceIndexAny).IsDown() { return } c.tail.GetLines(c.lines) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Color4d(0.2, 0, 0.3, 0.8) gl.Disable(gl.TEXTURE_2D) gl.Begin(gl.QUADS) { glx := gl.Int(x) gly := gl.Int(y) glx2 := gl.Int(x + dx) gly2 := gl.Int(y + dy) gl.Vertex2i(glx, gly) gl.Vertex2i(glx, gly2) gl.Vertex2i(glx2, gly2) gl.Vertex2i(glx2, gly) } gl.End() gui.SetFontColor(1, 1, 1, 1) startY := float64(y + dy - len(c.lines)*lineHeight) for i, line := range c.lines { switch { case strings.HasPrefix(line, "LOG"): gui.SetFontColor(1, 1, 1, 1) case strings.HasPrefix(line, "WARN"): gui.SetFontColor(1, 1, 0, 1) case strings.HasPrefix(line, "ERROR"): gui.SetFontColor(1, 0, 0, 1) default: gui.SetFontColor(1, 1, 1, 0.7) } c.dict.RenderString(line, float64(x), startY+float64(i*lineHeight), 0, lineHeight, gui.Left) } }
func (c *Console) Draw(region Region, stlye StyleStack) { if !c.visible { return } gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Color4d(0.2, 0, 0.3, 0.8) gl.Disable(gl.TEXTURE_2D) gl.Begin(gl.QUADS) { x := gl.Int(region.X) y := gl.Int(region.Y) x2 := gl.Int(region.X + region.Dx) y2 := gl.Int(region.Y + region.Dy) gl.Vertex2i(x, y) gl.Vertex2i(x, y2) gl.Vertex2i(x2, y2) gl.Vertex2i(x2, y) } gl.End() gui.SetFontColor(1, 1, 1, 1) startY := float64(region.Y + region.Dy - len(c.lines)*lineHeight) for i, line := range c.lines { switch { case strings.HasPrefix(line, "LOG"): gui.SetFontColor(1, 1, 1, 1) case strings.HasPrefix(line, "WARN"): gui.SetFontColor(1, 1, 0, 1) case strings.HasPrefix(line, "ERROR"): gui.SetFontColor(1, 0, 0, 1) default: gui.SetFontColor(1, 1, 1, 0.7) } c.dict.RenderString(line, float64(region.X), startY+float64(i*lineHeight), 0, lineHeight, gui.Left) } }
// 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 (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 } }