Пример #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
	gl.UseProgram(program)

	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangle)
	gl.EnableVertexAttribArray(attributeCoord2d)

	// Describe our vertices array to OpenGL (it can't guess its format automatically)
	gl.VertexAttribPointer(attributeCoord2d, 2, gl.FLOAT, gl.FALSE, 0, gl.Pointer(nil))

	gl.EnableVertexAttribArray(attributeColor)
	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangleColors)
	gl.VertexAttribPointer(attributeColor, 3, gl.FLOAT, gl.FALSE, 0, gl.Pointer(nil))

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

	gl.DisableVertexAttribArray(attributeCoord2d)
	gl.DisableVertexAttribArray(attributeColor)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0) // Unbind

	// Display the result
	glfw.SwapBuffers()
}
Пример #2
0
func drawgl() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	uniYaw = yrot * (math.Pi / 180.0)
	yrot = yrot - 1.0
	uniPitch = zrot * (math.Pi / 180.0)
	zrot = zrot - 0.5
	uniRoll = xrot * (math.Pi / 180.0)
	xrot = xrot - 0.2

	gl.Uniform4f(UniScale, gl.Float(uniRoll), gl.Float(uniYaw), gl.Float(uniPitch), gl.Float(uniscale))
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.DrawArrays(gl.TRIANGLES, gl.Int(0), gl.Sizei(len(triangle_vertices)*4))

	time.Sleep(50 * time.Millisecond)

}
Пример #3
0
func drawPrimitives(color color.Color, mode gl.Enum, vecs ...geometry.Vector2) {
	vertices := make([]float32, len(vecs)*2)
	r, g, b, a := glcolor.ConvertColorF(color)
	var colors []float32
	for i := range vecs {
		vertices[i*2] = vecs[i].X
		vertices[i*2+1] = vecs[i].Y
		colors = append(colors, r, g, b, a)
	}
	DefaultPrimitivesShaderProgram.Use()
	primitivesUniformMatrix.UniformMatrix4fv(1, false, DefaultCamera.Transposed())
	primitivesAttributeCoord.Enable()
	primitivesAttributeCoord.AttribPointer(2, gl.FLOAT, false, 0, gl.Pointer(&vertices[0]))

	primitivesAttributeColor.Enable()
	primitivesAttributeColor.AttribPointer(4, gl.FLOAT, false, 0, gl.Pointer(&colors[0]))

	gl.DrawArrays(mode, 0, gl.Sizei(len(vecs)))

	primitivesAttributeColor.Disable()
	primitivesAttributeCoord.Disable()
}
Пример #4
0
func (vbo *VertexBufferObject) DrawArrays(start, end int) {
	gl.DrawArrays(gl.TRIANGLES, gl.Int(start), gl.Sizei(end))
}