Exemple #1
0
func (pen *Pen) lineTo(p Point) {

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

	gl.Color4f(0.0, 0.0, 0.0, 0.1)

	gl.Begin(gl.LINES)

	for _, s := range pen.points {

		if s.x == 0 && s.y == 0 {
			continue
		}

		if p.distanceTo(s) < 20.0 {

			gl.Vertex2i(int(p.x), int(p.y))
			gl.Vertex2i(int(s.x), int(s.y))

		}

	}

	gl.End()

	pen.n = (pen.n + 1) % len(pen.points)
	pen.points[pen.n] = p

	pen.moveTo(p)

}
Exemple #2
0
func (pen *Pen) lineTo(x, y int) {
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Color4f(0.0, 0.0, 0.0, 0.1)
	gl.Begin(gl.LINES)

	var p [2]int
	for i := range pen.points {
		p = pen.points[i]
		if p[0] == 0 && p[1] == 0 {
			continue
		}

		if distanceTo(x, y, p[0], p[1]) < 10.0 {
			gl.Vertex2i(x, y)
			gl.Vertex2i(p[0], p[1])
		}
	}

	gl.End()

	pen.n = (pen.n + 1) % len(pen.points)
	pen.points[pen.n][0] = x
	pen.points[pen.n][1] = y
	pen.moveTo(x, y)
}
Exemple #3
0
func display() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Begin(gl.TRIANGLES)
	gl.Color3f(0.0, 0.0, 1.0) /* blue */
	gl.Vertex2i(0, 0)
	gl.Color3f(0.0, 1.0, 0.0) /* green */
	gl.Vertex2i(200, 200)
	gl.Color3f(1.0, 0.0, 0.0) /* red */
	gl.Vertex2i(20, 200)
	gl.End()
	gl.Flush() /* Single buffered, so needs a flush. */
}
Exemple #4
0
func drawQuad(x, y, w, h int, u, v, u2, v2 float32) {
	gl.Begin(gl.QUADS)

	gl.TexCoord2f(float32(u), float32(v))
	gl.Vertex2i(int(x), int(y))

	gl.TexCoord2f(float32(u2), float32(v))
	gl.Vertex2i(int(x+w), int(y))

	gl.TexCoord2f(float32(u2), float32(v2))
	gl.Vertex2i(int(x+w), int(y+h))

	gl.TexCoord2f(float32(u), float32(v2))
	gl.Vertex2i(int(x), int(y+h))

	gl.End()
}
Exemple #5
0
func drawBlock(x, y int, color TetrisBlockColor) {
	glx := gl.GLint(x)
	gly := gl.GLint(y)

	gl.Color3ub(color.R/2, color.G/2, color.B/2)
	gl.Begin(gl.QUADS)
	gl.Vertex2i(int(glx), int(gly))
	gl.Vertex2i(int(glx+blockSize), int(gly))
	gl.Vertex2i(int(glx+blockSize), int(gly+blockSize))
	gl.Vertex2i(int(glx), int(gly+blockSize))
	gl.Color3ub(color.R, color.G, color.B)
	gl.Vertex2i(int(glx+smallBlockOffset), int(gly+smallBlockOffset))
	gl.Vertex2i(int(glx+blockSize-smallBlockOffset), int(gly+smallBlockOffset))
	gl.Vertex2i(int(glx+blockSize-smallBlockOffset), int(gly+blockSize-smallBlockOffset))
	gl.Vertex2i(int(glx+smallBlockOffset), int(gly+blockSize-smallBlockOffset))
	gl.End()
}
Exemple #6
0
func drawSelection(p1, p2 Point) {
	min, max := minMaxPoints(p1, p2)

	gl.Color3ub(255, 0, 0)
	gl.Begin(gl.LINES)
	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(min.X), int(max.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(min.X), int(max.Y))
	gl.End()
	gl.Color3ub(255, 255, 255)
}
func (s *Sim) Draw() {

	//start := time.Now()

	// Init OpenGL
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

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

	gl.Begin(gl.POINTS)

	gl.PointSize(1)
	for x := int(0); x < int(300); x += 1 {
		for y := int(0); y < int(300); y += 1 {
			pot := s.potential(s.units[0], float64(x), float64(y))

			//r := math.Min(pot*2, 1)
			//g := math.Min(pot*2, 2)-1
			gl.Color4f(1-float32(pot), 1-float32(pot), 1-float32(pot), 1)
			gl.Vertex2i(x, y)
		}
	}

	gl.End()

	// Draw Units
	gl.Begin(gl.POINTS)
	for i, unit := range s.units {
		if i == 0 {
			gl.Color4f(1, 0, 0, 1)
			fmt.Println(unit.pos.X)
		} else {
			gl.Color4f(0, 1, 0, 1)
		}

		gl.Vertex2f(float32(unit.pos.X), float32(unit.pos.Y))
	}
	gl.End()

	// Nav mesh
	/*
		for e := s.nav.nodes.Front(); e != nil; e = e.Next() {
			nn := e.Value.(*NavNode)

			gl.Color4f(0, 0, 1, 0.2)

			if s.markedNodes[nn] {
				gl.Color4f(1, 0, 0, 0.2)
			}

			gl.Begin(gl.POLYGON)
			for _, pos := range nn.node.Points {
				if pos == nil {
					continue
				}

				gl.Vertex2f(float32(pos.X), float32(pos.Y))
			}
			gl.End()

			gl.Color4f(0, 0, 1, 1)
			gl.Begin(gl.LINE_LOOP)
			for _, pos := range nn.node.Points {
				if pos == nil {
					continue
				}

				gl.Vertex2f(float32(pos.X), float32(pos.Y))
			}
			gl.End()
		}
	*/
	// Draw Path
	if s.units[0].path != nil {
		gl.Begin(gl.LINE_STRIP)
		gl.Color4f(1, 0, 0, 0.2)
		for e := s.units[0].path.Front(); e != nil; e = e.Next() {
			pos := e.Value.(*geo.Vec)
			gl.Vertex2f(float32(pos.X), float32(pos.Y))
		}
		gl.End()
	}

	// Draw Links
	/*gl.Color4f(1, 0, 0, 1)
	gl.Begin(gl.LINES)
	for i, link := range nn.links {
		pt1 := nn.node.Points[i]
		pt2 := nn.node.Points[(i+1)%nn.node.Len()]
		lineCenter := &geo.Vec{(pt1.X+pt2.X)/2, (pt1.Y+pt2.Y)/2}

		center := link.node.Center()

		gl.Vertex2d(lineCenter.X, lineCenter.Y)
		gl.Vertex2d(center.X, center.Y)
	}
	gl.End()*/

	/*
		fps := 1/(float64(time.Since(start))/float64(time.Second))
		s.ui.fpsLabel2.SetLabel(fmt.Sprintf("%f", fps))
	*/
}