Example #1
0
func renderSwitch(s *Switch) {
	gl.LoadIdentity()
	// TODO constant
	v := SwitchSize / 2
	x, y := float32(s.X+v), float32(s.Y+v)
	gl.Translatef(x, y, 0)
	// Render the switch
	gl.Color3f(1, 1, 1)
	gl.Begin(gl.TRIANGLE_FAN)
	gl.Vertex2d(0, 0)
	vv := float64(v)
	for i := float64(0); i <= SwitchSegments; i++ {
		a := 2 * math.Pi * i / SwitchSegments
		gl.Vertex2d(math.Sin(a)*vv, math.Cos(a)*vv)
	}
	gl.End()

	if LineWidth != 0 {
		// Render the shape
		gl.Color3i(0, 0, 0)
		gl.LineWidth(LineWidth)
		gl.Begin(gl.LINE_LOOP)
		for i := float64(0); i <= SwitchSegments; i++ {
			a := 2 * math.Pi * i / SwitchSegments
			gl.Vertex2d(math.Sin(a)*vv, math.Cos(a)*vv)
		}
		gl.End()
	}

	// Write the switch name
	gl.LoadIdentity()
	w, h := fonts[6].Metrics(s.name)
	gl.Color3i(0, 0, 0)
	fonts[6].Printf(x-float32(w)/2, y-float32(h)/2+2, s.name)
}
Example #2
0
func renderCorner(color ColorDef, ww, hh, start float64, radius, lineWidth float32) {
	setColor(color)
	max := BlockCornerSegments * (start + 1)
	// Render the corner
	gl.Begin(gl.TRIANGLE_FAN)
	gl.Vertex2d(ww, hh)
	for i := start * BlockCornerSegments; i <= max; i++ {
		a := math.Pi / 2 * i / BlockCornerSegments
		x := math.Cos(a) * float64(radius)
		y := math.Sin(a) * float64(radius)
		gl.Vertex2d(ww+x, hh+y)
	}
	gl.End()

	if lineWidth != 0 {
		// Render the shape
		gl.LineWidth(lineWidth)
		gl.Color3i(0, 0, 0)
		gl.Begin(gl.LINE_STRIP)
		for i := start * BlockCornerSegments; i <= max; i++ {
			a := math.Pi / 2 * i / BlockCornerSegments
			x := math.Cos(a) * float64(radius)
			y := math.Sin(a) * float64(radius)
			gl.Vertex2d(ww+x, hh+y)
		}
		gl.End()
	}
}
Example #3
0
// Same as Squarei, double co-ordinates
func Squared(x, y, w, h float64) {
	u, v, u2, v2 := 0, 1, 1, 0

	gl.TexCoord2i(u, v)
	gl.Vertex2d(x, y)

	gl.TexCoord2i(u2, v)
	gl.Vertex2d(x+w, y)

	gl.TexCoord2i(u2, v2)
	gl.Vertex2d(x+w, y+h)

	gl.TexCoord2i(u, v2)
	gl.Vertex2d(x, y+h)
}
Example #4
0
// drawCircle draws a circle for the specified radius, rotation angle, and the specified number of sides
func drawCircle(radius float64, sides int) {
	gl.Begin(gl.LINE_LOOP)
	for a := 0.0; a < 2*math.Pi; a += (2 * math.Pi / float64(sides)) {
		gl.Vertex2d(math.Sin(a)*radius, math.Cos(a)*radius)
	}
	gl.Vertex3f(0, 0, 0)
	gl.End()
}
Example #5
0
// Draws a cross on the screen with known lengths, useful for understanding
// screen dimensions
func DebugLines() {
	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	//gl.LoadIdentity()
	//gl.Ortho(-2.1, 6.1, -4, 8, 1, -1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.LoadIdentity()
	gl.LineWidth(5)
	gl.Color4f(1, 1, 0, 1)
	gl.Begin(gl.LINES)
	gl.Vertex2d(0, -1.6)
	gl.Vertex2d(0, 0.8)
	gl.Vertex2d(-0.8, 0)
	gl.Vertex2d(0.8, 0)
	gl.End()
	gl.PopMatrix()

	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
}
Example #6
0
// vertex draws vertices.
// Used in classic render mode.
func (a *Attr) vertex(i int) {
	i *= a.size

	switch a.size {
	case 2:
		switch v := a.data.(type) {
		case []int16:
			gl.Vertex2s(v[i], v[i+1])
		case []int32:
			gl.Vertex2i(int(v[i]), int(v[i+1]))
		case []float32:
			gl.Vertex2f(v[i], v[i+1])
		case []float64:
			gl.Vertex2d(v[i], v[i+1])
		}
	case 3:
		switch v := a.data.(type) {
		case []int16:
			gl.Vertex3s(v[i], v[i+1], v[i+2])
		case []int32:
			gl.Vertex3i(int(v[i]), int(v[i+1]), int(v[i+2]))
		case []float32:
			gl.Vertex3f(v[i], v[i+1], v[i+2])
		case []float64:
			gl.Vertex3d(v[i], v[i+1], v[i+2])
		}
	case 4:
		switch v := a.data.(type) {
		case []int16:
			gl.Vertex4s(v[i], v[i+1], v[i+2], v[i+3])
		case []int32:
			gl.Vertex4i(int(v[i]), int(v[i+1]), int(v[i+2]), int(v[i+3]))
		case []float32:
			gl.Vertex4f(v[i], v[i+1], v[i+2], v[i+3])
		case []float64:
			gl.Vertex4d(v[i], v[i+1], v[i+2], v[i+3])
		}
	}
}
Example #7
0
func (ent *Entity) GlVertex2d(v Vector) {
	x, y := v.Rotate(ent.Angle)
	gl.Vertex2d(ent.PosX+x, ent.PosY+y)
}
Example #8
0
func (char *Char) glVertex2d(x, y float64) {
	gl.Vertex2d(char.X+(x*char.Size), char.Y+(y*char.Size))
}