Beispiel #1
0
func (r Region) PopClipPlanes() {
	clippers = clippers[0 : len(clippers)-1]
	if len(clippers) == 0 {
		gl.Disable(gl.CLIP_PLANE0)
		gl.Disable(gl.CLIP_PLANE1)
		gl.Disable(gl.CLIP_PLANE2)
		gl.Disable(gl.CLIP_PLANE3)
	} else {
		clippers[len(clippers)-1].setClipPlanes()
	}
}
Beispiel #2
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()
}
Beispiel #3
0
func (gw *GameWindow) Draw(region g2.Region, style g2.StyleStack) {
	defer base.StackCatcher()
	defer func() {
		// gl.Translated(gl.Double(gw.region.X), gl.Double(gw.region.Y), 0)
		gl.Disable(gl.TEXTURE_2D)
		gl.Color4ub(255, 255, 255, 255)
		gl.LineWidth(3)
		gl.Begin(gl.LINES)
		bx, by := gl.Int(region.X), gl.Int(region.Y)
		bdx, bdy := gl.Int(region.Dx), gl.Int(region.Dy)
		gl.Vertex2i(bx, by)
		gl.Vertex2i(bx, by+bdy)
		gl.Vertex2i(bx, by+bdy)
		gl.Vertex2i(bx+bdx, by+bdy)
		gl.Vertex2i(bx+bdx, by+bdy)
		gl.Vertex2i(bx+bdx, by)
		gl.Vertex2i(bx+bdx, by)
		gl.Vertex2i(bx, by)
		gl.End()
		gl.LineWidth(1)
	}()

	gw.Engine.Pause()
	game := gw.Engine.GetState().(*Game)
	// Note that since we do a READER lock on game.local we cannot do any writes
	// to local data while rendering.
	game.local.RLock()
	game.RenderLocal(region)
	game.local.RUnlock()
	gw.Engine.Unpause()
}
Beispiel #4
0
func (tsm *ThunderSubMenu) Draw(region Region, style StyleStack) {
	gl.Disable(gl.TEXTURE_2D)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Enable(gl.BLEND)
	base.EnableShader("marble")
	offset, ok := style.Get("offset").(linear.Vec2)
	if ok {
		base.SetUniformV2("marble", "offset", offset)
	} else {
		base.SetUniformV2("marble", "offset", linear.Vec2{})
	}
	gl.Color4ub(255, 255, 255, 255)
	gl.Begin(gl.QUADS)
	x := gl.Int(region.X)
	y := gl.Int(region.Y)
	dx := gl.Int(region.Dx)
	dy := gl.Int(region.Dy)
	gl.Vertex2i(x, y)
	gl.Vertex2i(x, y+dy)
	gl.Vertex2i(x+dx, y+dy)
	gl.Vertex2i(x+dx, y)
	gl.End()
	base.EnableShader("")
	for i, option := range tsm.Options {
		region.Dy = tsm.requests[option].Dy
		if i == tsm.selected {
			style.PushStyle(map[string]interface{}{"selected": true})
		} else {
			style.PushStyle(map[string]interface{}{"selected": false})
		}
		option.Draw(region, style)
		style.Pop()
		region.Y += tsm.requests[option].Dy
	}
}
Beispiel #5
0
func (gw *GameWindow) Draw(region gui.Region, style gui.StyleStack) {
	defer base.StackCatcher()
	defer func() {
		// gl.Translated(gl.Double(gw.region.X), gl.Double(gw.region.Y), 0)
		gl.Disable(gl.TEXTURE_2D)
		gl.Color4ub(255, 255, 255, 255)
		gl.LineWidth(3)
		gl.Begin(gl.LINES)
		bx, by := gl.Int(region.X), gl.Int(region.Y)
		bdx, bdy := gl.Int(region.Dx), gl.Int(region.Dy)
		gl.Vertex2i(bx, by)
		gl.Vertex2i(bx, by+bdy)
		gl.Vertex2i(bx, by+bdy)
		gl.Vertex2i(bx+bdx, by+bdy)
		gl.Vertex2i(bx+bdx, by+bdy)
		gl.Vertex2i(bx+bdx, by)
		gl.Vertex2i(bx+bdx, by)
		gl.Vertex2i(bx, by)
		gl.End()
		gl.LineWidth(1)
	}()

	gw.Engine.Pause()
	game := gw.Engine.GetState().(*Game)
	game.RenderLocal(region, gw.Local)
	gw.Engine.Unpause()
}
Beispiel #6
0
func (ms *ManaSource) Draw(local *LocalData, zoom float64, dx float64, dy float64) {
	if local.nodeTextureData == nil {
		//		gl.Enable(gl.TEXTURE_2D)
		local.nodeTextureData = make([]byte, ms.options.NumNodeRows*ms.options.NumNodeCols*3)
		gl.GenTextures(1, &local.nodeTextureId)
		gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
		gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
		gl.TexImage2D(
			gl.TEXTURE_2D,
			0,
			gl.RGB,
			gl.Sizei(ms.options.NumNodeRows),
			gl.Sizei(ms.options.NumNodeCols),
			0,
			gl.RGB,
			gl.UNSIGNED_BYTE,
			gl.Pointer(&local.nodeTextureData[0]))
	}
	for i := range ms.rawNodes {
		for c := 0; c < 3; c++ {
			color_frac := ms.rawNodes[i].Mana[c] * 1.0 / ms.options.NodeMagnitude
			color_range := float64(ms.options.MaxNodeBrightness - ms.options.MinNodeBrightness)
			local.nodeTextureData[i*3+c] = byte(
				color_frac*color_range + float64(ms.options.MinNodeBrightness))
		}
	}
	gl.Enable(gl.TEXTURE_2D)
	//gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)
	gl.TexSubImage2D(
		gl.TEXTURE_2D,
		0,
		0,
		0,
		gl.Sizei(ms.options.NumNodeRows),
		gl.Sizei(ms.options.NumNodeCols),
		gl.RGB,
		gl.UNSIGNED_BYTE,
		gl.Pointer(&local.nodeTextureData[0]))

	base.EnableShader("nodes")
	base.SetUniformI("nodes", "width", ms.options.NumNodeRows*3)
	base.SetUniformI("nodes", "height", ms.options.NumNodeCols*3)
	base.SetUniformI("nodes", "drains", 1)
	base.SetUniformI("nodes", "tex0", 0)
	base.SetUniformI("nodes", "tex1", 1)
	base.SetUniformF("nodes", "zoom", float32(zoom))
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)

	// I have no idea why this value for move works, but it does.  So, hooray.
	move := (dx - dy) / 2
	texture.RenderAdvanced(move, -move, dy, dx, 3.1415926535/2, true)
	base.EnableShader("")
	gl.Disable(gl.TEXTURE_2D)
}
Beispiel #7
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
}
Beispiel #8
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()
	}
}
Beispiel #9
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)
}
Beispiel #10
0
func (co *colorOption) DrawInfo(x, y, dx, dy int) {
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4ub(co.r, co.g, co.b, co.a)
	gl.Begin(gl.QUADS)
	gl.Vertex2i(int32(x), int32(y))
	gl.Vertex2i(int32(x), int32(y+dy))
	gl.Vertex2i(int32(x+dx), int32(y+dy))
	gl.Vertex2i(int32(x+dx), int32(y))
	gl.End()
}
Beispiel #11
0
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()
}
Beispiel #12
0
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)
}
Beispiel #13
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()
}
Beispiel #14
0
func Text(x, y, z float32, str string) {
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Enable(gl.BLEND)

	gl.RasterPos3f(x, y, z)
	for _, ch := range str {
		//glut.BitmapCharacter(glut.BITMAP_9_BY_15, string(ch))
	}

	gl.Disable(gl.BLEND)
}
Beispiel #15
0
func Number(x, y, z, n float32) {
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Enable(gl.BLEND)

	s := ""
	fmt.Fprintf(s, "%f", n)
	gl.RasterPos3f(x, y, z)
	for _, ch := range s {
		//glut.BitmapCharacter(glut.BITMAP_9_BY_15, string(ch))
	}

	gl.Disable(gl.BLEND)
}
Beispiel #16
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()
}
Beispiel #17
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
}
Beispiel #18
0
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
		}
	}
}
Beispiel #19
0
func (p *PosWidget) Draw(region Region, style StyleStack) {
	gl.Disable(gl.TEXTURE_2D)
	gl.Color4ub(0, 255, 0, 255)
	gl.Begin(gl.QUADS)
	x := gl.Int(region.X)
	y := gl.Int(region.Y)
	dx := gl.Int(base.GetDictionary("luxisr").StringWidth(p.text, float64(p.Size)))
	dy := gl.Int(p.Size)
	gl.Vertex2i(x, y)
	gl.Vertex2i(x, y+dy)
	gl.Vertex2i(x+dx, y+dy)
	gl.Vertex2i(x+dx, y)
	gl.End()
	base.Log().Printf("%v %v %v %v", x, y, dx, dy)
	gl.Color4ub(255, 0, 255, 255)
	base.GetDictionary("luxisr").RenderString(p.text, float64(region.X), float64(region.Y), 0, float64(p.Size), gui.Left)
}
Beispiel #20
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)
}
Beispiel #21
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()
}
Beispiel #22
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("")
}
Beispiel #23
0
func DrawStarTex(t *data.Star) {

	// Find the center point of the texture to rotate around
	xav := (t.X1 + t.X2) / 2
	yav := (t.Y1 + t.Y2) / 2

	//Translate there, rotate, translate back
	gl.MatrixMode(gl.MODELVIEW)
	gl.Translatef(xav, yav, 0)
	gl.Rotatef(gl.Float(t.Theta), 0, 0, 1)
	gl.Translatef(-xav, -yav, 0)

	//Bind our texture to be drawn by id
	gl.Color3f(1, 1, 1)
	gl.Enable(gl.TEXTURE_2D)
	gl.BindTexture(gl.TEXTURE_2D, t.TexId)

	// Draw a rectangle with the texture stretched to the corners
	gl.Begin(gl.QUADS)

	// Stretch the texture to its 4 corners.
	gl.TexCoord2d(0, 0)
	gl.Vertex2f(t.X1, t.Y1)

	gl.TexCoord2d(0, 1)
	gl.Vertex2f(t.X1, t.Y2)

	gl.TexCoord2d(1, 1)
	gl.Vertex2f(t.X2, t.Y2)

	gl.TexCoord2d(1, 0)
	gl.Vertex2f(t.X2, t.Y1)

	gl.End()

	// Unbind the texture in case something else wants to draw
	gl.Disable(gl.TEXTURE_2D)

	// Reset the matrix
	gl.LoadIdentity()

}
Beispiel #24
0
func (a *app) OnGLInit() {
	gl.Init()
	var ntex int
	if *blend {
		ntex = 6
	} else {
		ntex = 3
	}
	for i := 0; i < ntex; i++ {
		texinit(i + 1)
	}
	a.factorloc = shinit()
	initquad()
	gl.Enable(gl.TEXTURE_2D)
	gl.Disable(gl.DEPTH_TEST)
	a.tbase = time.Now()
	if *fullscreen {
		a.enterFullscreen()
	}
}
Beispiel #25
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)
}
Beispiel #26
0
func drawCells() {

	if input.Zoom > 0 {
		gl.PointSize(gl.Float(float64(Width) / float64(*flagSize) * input.Zoom))
	}

	gl.Color4f(1, 1, 1, 1)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Begin(gl.POINTS)

	for i, j := 0, 0; i < (life.Size * life.Size); i, j = i+life.Size, j+1 {
		for k, v := range life.Cells[i : i+life.Size] {
			if v {
				gl.Vertex2f(gl.Float(k), gl.Float(j))
			}
		}
	}

	gl.End()
	gl.Disable(gl.POINT_SMOOTH)
}
Beispiel #27
0
func (b *Box) Draw(region Region, style StyleStack) {
	b.Last = region
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Disable(gl.TEXTURE_2D)
	if b.Hover {
		gl.Color4ub(gl.Ubyte(b.Color[0]), gl.Ubyte(b.Color[1]), gl.Ubyte(b.Color[2]), gl.Ubyte(b.Color[3]))
	} else {
		gl.Color4ub(gl.Ubyte(b.Color[0]), gl.Ubyte(b.Color[1]), gl.Ubyte(b.Color[2]), gl.Ubyte(b.Color[3])/2)
	}
	gl.Begin(gl.QUADS)
	x := gl.Int(region.X)
	y := gl.Int(region.Y)
	dx := gl.Int(region.Dx)
	dy := gl.Int(region.Dy)
	gl.Vertex2i(x, y)
	gl.Vertex2i(x+dx, y)
	gl.Vertex2i(x+dx, y+dy)
	gl.Vertex2i(x, y+dy)
	gl.End()
}
Beispiel #28
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)
	}
}
Beispiel #29
0
func (sp *SpawnPoint) RenderOnFloor() {
	re := topSpawnRegexp()
	if re == nil || !re.MatchString(sp.Name) {
		return
	}

	var rgba [4]float64
	gl.GetDoublev(gl.CURRENT_COLOR, &rgba[0])
	gl.PushAttrib(gl.CURRENT_BIT)
	gl.Disable(gl.TEXTURE_2D)

	// This just creates a color that is consistent among all spawn points whose
	// names match SpawnName-.*
	prefix := sp.Name
	for i := range prefix {
		if prefix[i] == '-' {
			prefix = prefix[0:i]
			break
		}
	}
	h := fnv.New32()
	h.Write([]byte(prefix))
	hs := h.Sum32()
	gl.Color4ub(byte(hs%256), byte((hs/256)%256), byte((hs/(256*256))%256), byte(255*rgba[3]))

	base.EnableShader("box")
	base.SetUniformF("box", "dx", float32(sp.Dx))
	base.SetUniformF("box", "dy", float32(sp.Dy))
	if !sp.temporary {
		base.SetUniformI("box", "temp_invalid", 0)
	} else if !sp.invalid {
		base.SetUniformI("box", "temp_invalid", 1)
	} else {
		base.SetUniformI("box", "temp_invalid", 2)
	}
	(&texture.Object{}).Data().Render(float64(sp.X), float64(sp.Y), float64(sp.Dx), float64(sp.Dy))
	base.EnableShader("")
	gl.PopAttrib()
}
Beispiel #30
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()
}