示例#1
0
func display() {
	// Clear the background as white
	gl.ClearColor(1.0, 1.0, 1.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// Use the GLSL program
	program.Use()

	// Faster fade in and out than in the wikibook
	curFade := math.Sin(glfw.Time())

	uniformFade.Uniform1f(float32(curFade))

	vboTriangle.Bind(gl.ARRAY_BUFFER)

	attributeCoord2d.EnableArray()
	// Describe our vertices array to OpenGL (it can't guess its format automatically)
	attributeCoord2d.AttribPointerOffset(2, gl.FLOAT, false, 5*4, 0)

	attributeColor.EnableArray()
	attributeColor.AttribPointerOffset(3, gl.FLOAT, false, 5*4, 2*4)

	// Push each element in buffer_vertices to the vertex shader
	gl.DrawArrays(gl.TRIANGLES, 0, 3)

	attributeCoord2d.DisableArray()
	attributeColor.DisableArray()

	// Display the result
	glfw.SwapBuffers()
}
示例#2
0
func display() {
	// Clear the background as white
	gl.ClearColor(1.0, 1.0, 1.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// Use the GLSL program
	program.Use()

	uniformMTransform.UniformMatrix4fv(1, false, matrix)

	vboTriangle.Bind(gl.ARRAY_BUFFER)

	attributeCoord3d.EnableArray()
	// Describe our vertices array to OpenGL (it can't guess its format automatically)
	attributeCoord3d.AttribPointerOffset(3, gl.FLOAT, false, 6*4, 0)

	attributeColor.EnableArray()
	attributeColor.AttribPointerOffset(3, gl.FLOAT, false, 6*4, 3*4)

	// Push each element in buffer_vertices to the vertex shader
	gl.DrawArrays(gl.TRIANGLES, 0, 3)

	attributeCoord3d.DisableArray()
	attributeColor.DisableArray()

	// Display the result
	glfw.SwapBuffers()
}
示例#3
0
func DrawAABB(aabb Drawable, t float32, program gl.Program) {
	box := aabb.GetBox3D()
	nverts, normals := GetVerts()
	if box.Animator != nil {
		box.Animator(&box, t)
	}
	drawPos := box.Pos
	drawColor := box.Color
	drawSize := box.Size

	program.GetUniformLocation("SizeVec").Uniform3f(drawSize.X, drawSize.Y, drawSize.Z)
	program.GetUniformLocation("PosVec").Uniform3f(drawPos.X, drawPos.Y, drawPos.Z)
	gl.Color3f(drawColor.X, drawColor.Y, drawColor.Z)
	gl.EnableClientState(gl.VERTEX_ARRAY)
	gl.VertexPointer(3, 0, nverts)
	gl.EnableClientState(gl.NORMAL_ARRAY)
	gl.NormalPointer(0, normals)

	gl.DrawArrays(gl.QUADS, 0, 24)
	gl.DisableClientState(gl.NORMAL_ARRAY)
	gl.DisableClientState(gl.VERTEX_ARRAY)
	for it := aabb.GetChildren(); it != nil; it = it.Next() {
		DrawAABB(it.Value.(Drawable), t, program)
	}
}
示例#4
0
文件: gc.go 项目: xushiwei/draw2d
func (p *GLPainter) Flush() {
	if len(p.vertices) != 0 {
		gl.EnableClientState(gl.COLOR_ARRAY)
		gl.EnableClientState(gl.VERTEX_ARRAY)
		gl.ColorPointer(4, 0, p.colors)
		gl.VertexPointer(2, 0, p.vertices)

		// draw lines
		gl.DrawArrays(gl.LINES, 0, len(p.vertices)/2)
		gl.DisableClientState(gl.VERTEX_ARRAY)
		gl.DisableClientState(gl.COLOR_ARRAY)
		p.vertices = p.vertices[0:0]
		p.colors = p.colors[0:0]
	}
}