Example #1
0
func drawInnerSlicedBox(pos, size mgl64.Vec2, borderColor, backgroundColor mgl64.Vec3) {
	if size[0] == 0 || size[1] == 0 {
		return
	}

	const OuterDistance = 2.5
	gl.Begin(gl.POLYGON)
	gl.Color3dv((*float64)(&borderColor[0]))
	gl.Vertex2d(float64(pos[0]+OuterDistance), float64(pos[1]))
	gl.Vertex2d(float64(pos[0]), float64(pos[1]+OuterDistance))
	gl.Vertex2d(float64(pos[0]), float64(pos[1]-OuterDistance+size[1]))
	gl.Vertex2d(float64(pos[0]+OuterDistance), float64(pos[1]+size[1]))
	gl.Vertex2d(float64(pos[0]-OuterDistance+size[0]), float64(pos[1]+size[1]))
	gl.Vertex2d(float64(pos[0]+size[0]), float64(pos[1]-OuterDistance+size[1]))
	gl.Vertex2d(float64(pos[0]+size[0]), float64(pos[1]+OuterDistance))
	gl.Vertex2d(float64(pos[0]-OuterDistance+size[0]), float64(pos[1]))
	gl.End()

	const InnerDistance = OuterDistance + (math.Sqrt2 - 1)
	gl.Begin(gl.POLYGON)
	gl.Color3dv((*float64)(&backgroundColor[0]))
	gl.Vertex2d(float64(pos[0]+InnerDistance), float64(pos[1]+1))
	gl.Vertex2d(float64(pos[0]+1), float64(pos[1]+InnerDistance))
	gl.Vertex2d(float64(pos[0]+1), float64(pos[1]-InnerDistance+size[1]))
	gl.Vertex2d(float64(pos[0]+InnerDistance), float64(pos[1]-1+size[1]))
	gl.Vertex2d(float64(pos[0]-InnerDistance+size[0]), float64(pos[1]-1+size[1]))
	gl.Vertex2d(float64(pos[0]-1+size[0]), float64(pos[1]-InnerDistance+size[1]))
	gl.Vertex2d(float64(pos[0]-1+size[0]), float64(pos[1]+InnerDistance))
	gl.Vertex2d(float64(pos[0]-InnerDistance+size[0]), float64(pos[1]+1))
	gl.End()
}
Example #2
0
// Shouldn't have tabs nor newlines
func (o *OpenGlStream) PrintSegment(s string) {
	if s == "" {
		return
	}

	if o.BackgroundColor != nil && o.BorderColor == nil {
		gl.PushAttrib(gl.CURRENT_BIT)
		gl.Color3dv((*float64)(&o.BackgroundColor[0]))
		gl.PushMatrix()
		gl.Translated(float64(o.pos[0]), float64(o.pos[1]), 0)
		for range s {
			gl.CallList(oFontBackground)
		}
		gl.PopMatrix()
		gl.PopAttrib()
	}

	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_LOD_BIAS, float32(lodBias*0.01))

	gl.Enable(gl.BLEND)
	defer gl.Disable(gl.BLEND)
	gl.Enable(gl.TEXTURE_2D)
	defer gl.Disable(gl.TEXTURE_2D)

	gl.PushMatrix()
	gl.Translated(float64(o.pos[0]), float64(o.pos[1]), 0)
	gl.ListBase(oFontBase + uint32(o.FontOptions)*96)
	gl.CallLists(int32(len(s)), gl.UNSIGNED_BYTE, gl.Ptr(&[]byte(s)[0]))
	gl.PopMatrix()

	//CheckGLError()
}
Example #3
0
func (w *MultitouchTestBoxWidget) Render() {
	colors := [...]mgl64.Vec3{
		{0 / 255.0, 140 / 255.0, 0 / 255.0},
		{0 / 255.0, 98 / 255.0, 140 / 255.0},
		{194 / 255.0, 74 / 255.0, 0 / 255.0},
		{89 / 255.0, 0 / 255.0, 140 / 255.0},
		{191 / 255.0, 150 / 255.0, 0 / 255.0},
		{140 / 255.0, 0 / 255.0, 0 / 255.0},
	}

	backgroundColor := colors[w.color]

	//borderColor := backgroundColor

	switch 1 {
	case 0:
		DrawBorderlessBox(w.pos, mgl64.Vec2{200, 200}, backgroundColor)
	case 1:
		gl.PushMatrix()
		gl.Translated(w.pos[0], w.pos[1], 0)
		gl.Color3dv(&backgroundColor[0])

		gl.EnableClientState(gl.VERTEX_ARRAY)
		gl.BindBuffer(gl.ARRAY_BUFFER, w.buffer)
		gl.VertexPointer(2, gl.FLOAT, 0, nil)

		gl.DrawArrays(gl.TRIANGLE_FAN, 0, 4)

		gl.PopMatrix()
	}
}
Example #4
0
func drawInnerRoundedBox(pos, size mgl64.Vec2, borderColor, backgroundColor mgl64.Vec3) {
	if size[0] == 0 || size[1] == 0 {
		return
	}

	const totalSlices = 4 * 16
	const borderWidth = 1
	const radius = 2.5 + borderWidth
	var x = float64(totalSlices)

	gl.Color3dv((*float64)(&backgroundColor[0]))
	gl.Begin(gl.TRIANGLE_STRIP)
	for i := 0; i <= totalSlices/4; i++ {
		gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
		gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(totalSlices-i)/x)*(radius-borderWidth), pos[1]+radius-math.Cos(Tau*float64(totalSlices-i)/x)*(radius-borderWidth))
	}
	for i := totalSlices / 4; i <= totalSlices/2; i++ {
		gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
		gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(totalSlices-i)/x)*(radius-borderWidth), pos[1]+size[1]-radius-math.Cos(Tau*float64(totalSlices-i)/x)*(radius-borderWidth))
	}
	gl.End()

	gl.Color3dv((*float64)(&borderColor[0]))
	gl.Begin(gl.TRIANGLE_STRIP)
	gl.Vertex2d(pos[0]+radius, pos[1])
	gl.Vertex2d(pos[0]+radius, pos[1]+borderWidth)
	for i := 0; i <= totalSlices/4; i++ {
		gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*radius, pos[1]+radius-math.Cos(Tau*float64(i)/x)*radius)
		gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
	}
	for i := totalSlices / 4; i <= totalSlices/2; i++ {
		gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*radius, pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*radius)
		gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
	}
	for i := totalSlices / 2; i <= totalSlices*3/4; i++ {
		gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(i)/x)*radius, pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*radius)
		gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
	}
	for i := totalSlices * 3 / 4; i <= totalSlices; i++ {
		gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(i)/x)*radius, pos[1]+radius-math.Cos(Tau*float64(i)/x)*radius)
		gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
	}
	gl.End()
}
Example #5
0
func (textStyle *TextStyle) Apply(glt *OpenGlStream) {
	if textStyle == nil {
		return
	}

	if textStyle.FontOptions != nil {
		glt.FontOptions = *textStyle.FontOptions
	}
	if textStyle.TextColor != nil {
		textColor := *textStyle.TextColor
		gl.Color3dv((*float64)(&textColor[0]))
	}
	if textStyle.BorderColor != nil {
		borderColor := *textStyle.BorderColor
		glt.BorderColor = borderColor
	}
	if textStyle.BackgroundColor != nil {
		backgroundColor := *textStyle.BackgroundColor
		glt.BackgroundColor = backgroundColor
	}
	if textStyle.ShowInvisibles != nil {
		glt.ShowInvisibles = *textStyle.ShowInvisibles
	}
}
Example #6
0
func DrawBorderlessBox(pos, size mgl64.Vec2, backgroundColor mgl64.Vec3) {
	gl.Color3dv(&backgroundColor[0])
	gl.Rectd(float64(pos[0]), float64(pos[1]), float64(pos.Add(size)[0]), float64(pos.Add(size)[1]))
}