Example #1
0
func (r *GoRect) Paint(p *qml.Painter) {
	obj := p.Object()

	width := gl.Float(obj.Int("width"))
	height := gl.Float(obj.Int("height"))

	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Color4f(1.0, 1.0, 1.0, 0.8)
	gl.Begin(gl.QUADS)
	gl.Vertex2f(0, 0)
	gl.Vertex2f(width, 0)
	gl.Vertex2f(width, height)
	gl.Vertex2f(0, height)
	gl.End()

	gl.LineWidth(2.5)
	gl.Color4f(0.0, 0.0, 0.0, 1.0)
	gl.Begin(gl.LINES)
	gl.Vertex2f(0, 0)
	gl.Vertex2f(width, height)
	gl.Vertex2f(width, 0)
	gl.Vertex2f(0, height)
	gl.End()
}
Example #2
0
func (r *Gopher) Paint(p *qml.Painter) {
	width := gl.Float(r.Int("width"))

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

	gl.ShadeModel(gl.SMOOTH)
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthMask(gl.TRUE)
	gl.Enable(gl.NORMALIZE)

	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.Scalef(width/3, width/3, width/3)

	lka := []gl.Float{0.3, 0.3, 0.3, 1.0}
	lkd := []gl.Float{1.0, 1.0, 1.0, 0.0}
	lks := []gl.Float{1.0, 1.0, 1.0, 1.0}
	lpos := []gl.Float{-2, 6, 3, 1.0}

	gl.Enable(gl.LIGHTING)
	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, lka)
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, lkd)
	gl.Lightfv(gl.LIGHT0, gl.SPECULAR, lks)
	gl.Lightfv(gl.LIGHT0, gl.POSITION, lpos)
	gl.Enable(gl.LIGHT0)

	gl.EnableClientState(gl.NORMAL_ARRAY)
	gl.EnableClientState(gl.VERTEX_ARRAY)

	gl.Translatef(1.5, 1.5, 0)
	gl.Rotatef(-90, 0, 0, 1)
	gl.Rotatef(gl.Float(90+((36000+r.Rotation)%360)), 1, 0, 0)

	gl.Disable(gl.COLOR_MATERIAL)

	for _, obj := range r.model {
		for _, group := range obj.Groups {
			gl.Materialfv(gl.FRONT, gl.AMBIENT, group.Material.Ambient)
			gl.Materialfv(gl.FRONT, gl.DIFFUSE, group.Material.Diffuse)
			gl.Materialfv(gl.FRONT, gl.SPECULAR, group.Material.Specular)
			gl.Materialf(gl.FRONT, gl.SHININESS, group.Material.Shininess)
			gl.VertexPointer(3, gl.FLOAT, 0, group.Vertexes)
			gl.NormalPointer(gl.FLOAT, 0, group.Normals)
			gl.DrawArrays(gl.TRIANGLES, 0, gl.Sizei(len(group.Vertexes)/3))
		}
	}

	gl.Enable(gl.COLOR_MATERIAL)

	gl.DisableClientState(gl.NORMAL_ARRAY)
	gl.DisableClientState(gl.VERTEX_ARRAY)
}