Пример #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)
}
Пример #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()
	}
}
Пример #3
0
// Used in classic render mode.
// Defines vertex colors.
func (a *Attr) color(i int) {
	i *= a.size

	switch a.size {
	case 3:
		switch v := a.data.(type) {
		case []int8:
			gl.Color3b(v[i], v[i+1], v[i+2])
		case []uint8:
			gl.Color3ub(v[i], v[i+1], v[i+2])
		case []int16:
			gl.Color3s(v[i], v[i+1], v[i+2])
		case []int32:
			gl.Color3i(int(v[i]), int(v[i+1]), int(v[i+2]))
		case []float32:
			gl.Color3f(v[i], v[i+1], v[i+2])
		case []float64:
			gl.Color3d(v[i], v[i+1], v[i+2])
		}
	case 4:
		switch v := a.data.(type) {
		case []int8:
			gl.Color4b(v[i], v[i+1], v[i+2], v[i+3])
		case []uint8:
			gl.Color4ub(v[i], v[i+1], v[i+2], v[i+3])
		case []int16:
			gl.Color4s(v[i], v[i+1], v[i+2], v[i+3])
		case []int32:
			gl.Color4i(int(v[i]), int(v[i+1]), int(v[i+2]), int(v[i+3]))
		case []float32:
			gl.Color4f(v[i], v[i+1], v[i+2], v[i+3])
		case []float64:
			gl.Color4d(v[i], v[i+1], v[i+2], v[i+3])
		}
	}
}
Пример #4
0
func renderBlock_(color ColorDef, w, h, radius, lineWidth float32) {
	setColor(color)
	gl.Begin(gl.QUADS)
	// Render inner square
	gl.Vertex2f(radius, radius)
	gl.Vertex2f(radius, h-radius)
	gl.Vertex2f(w-radius, h-radius)
	gl.Vertex2f(w-radius, radius)
	// Render top square
	gl.Vertex2f(radius, h-radius)
	gl.Vertex2f(radius, h)
	gl.Vertex2f(w-radius, h)
	gl.Vertex2f(w-radius, h-radius)
	// Render bottom square
	gl.Vertex2f(radius, radius)
	gl.Vertex2f(radius, 0)
	gl.Vertex2f(w-radius, 0)
	gl.Vertex2f(w-radius, radius)
	// Render left square
	gl.Vertex2f(w-radius, radius)
	gl.Vertex2f(w, radius)
	gl.Vertex2f(w, h-radius)
	gl.Vertex2f(w-radius, h-radius)
	// Render right square
	gl.Vertex2f(radius, radius)
	gl.Vertex2f(0, radius)
	gl.Vertex2f(0, h-radius)
	gl.Vertex2f(radius, h-radius)
	gl.End()
	// Render bottom right corner
	ww, hh := float64(w-radius), float64(h-radius)
	renderCorner(color, ww, hh, 0, radius, lineWidth)
	// Render bottom left corner
	ww, hh = float64(radius), float64(h-radius)
	renderCorner(color, ww, hh, 1, radius, lineWidth)
	// Render top left corner
	ww, hh = float64(radius), float64(radius)
	renderCorner(color, ww, hh, 2, radius, lineWidth)
	// Render top right corner
	ww, hh = float64(w-radius), float64(radius)
	renderCorner(color, ww, hh, 3, radius, lineWidth)

	if lineWidth != 0 {
		// Render the shape
		gl.LineWidth(lineWidth)
		gl.Color3i(0, 0, 0)
		gl.Begin(gl.LINES)

		gl.Vertex2f(radius, 0)
		gl.Vertex2f(w-radius, 0)

		gl.Vertex2f(0, radius)
		gl.Vertex2f(0, h-radius)

		gl.Vertex2f(w, radius)
		gl.Vertex2f(w, h-radius)

		gl.Vertex2f(radius, h)
		gl.Vertex2f(w-radius, h)

		gl.End()
	}
	gl.PopMatrix()
}