Exemple #1
0
func Draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.PushMatrix()
	defer gl.PopMatrix()

	gl.Color4f(0, 1, 0, .5)
	DrawCircle(vect.Vect{ScreenSize.X / 2, ScreenSize.Y / 2}, ScreenSize.Y/2.0-5.0, false)

	if Settings.Paused {
		gl.Color3f(1, 1, 1)
		RenderFontAt("Paused", 20, 30)
	}

	//draw collision objects

	gl.PushMatrix()

	gl.Translated(ScreenSize.X/2, ScreenSize.Y/2, 0)
	gl.Scaled(Settings.Scale, Settings.Scale, 1)

	DrawDebugData(space)

	gl.PopMatrix()
}
Exemple #2
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 #3
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)
}
// general OpenGL initialization
func initGL() {
	gl.Enable(gl.TEXTURE_2D)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.0, 0.0, 0.0, 0.5)
	gl.ClearDepth(1.0)
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

	// Setup the light
	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, lightAmbient[:])   // ambient lighting
	gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, lightDiffuse[:])   // make it diffuse
	gl.Lightfv(gl.LIGHT1, gl.POSITION, lightPosition[:]) // and place it
	gl.Enable(gl.LIGHT1)                                 // and finally turn it on.

	gl.Color4f(1.0, 1.0, 1.0, 0.5)     // Full Brightness, 50% Alpha ( NEW )
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE) // Blending Function For Translucency Based On Source Alpha Value ( NEW )
}
// general OpenGL initialization
func initGL() {
	LoadGLTextures("data/mud.bmp")

	gl.Enable(gl.TEXTURE_2D)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)
	gl.ClearDepth(1.0)
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, lightAmbient[:])
	gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, lightDiffuse[:])
	gl.Lightfv(gl.LIGHT1, gl.POSITION, lightPosition[:])
	gl.Enable(gl.LIGHT1)

	gl.Color4f(1.0, 1.0, 1.0, 0.5)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)
}
Exemple #6
0
func initGL() (err error) {
	if err = loadTextures(); err != nil {
		return
	}

	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0, 0, 0, 0)
	gl.ClearDepth(1)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.DEPTH_TEST)
	gl.Color4f(1, 1, 1, 0.5)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)

	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, ambient)
	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, diffuse)
	gl.Lightfv(gl.LIGHT1, gl.POSITION, lightpos)
	gl.Enable(gl.LIGHT1)
	return
}
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))
	*/
}