Ejemplo n.º 1
0
func Bind(bindings interface{}) {
	value := reflect.ValueOf(bindings).Elem()
	n := value.NumField()

	for i := 0; i < n; i++ {
		field := value.Field(i)
		switch field.Type() {
		case bufferType:
			buffer := gl.GenBuffer()
			field.Set(reflect.ValueOf(buffer))
		case textureType:
			texture := gl.GenTexture()
			field.Set(reflect.ValueOf(texture))
		case vaoType:
			vao := gl.GenVertexArray()
			field.Set(reflect.ValueOf(vao))
		case vertexShaderType:
			shader := gl.VertexShader(gl.CreateShader(gl.VERTEX_SHADER))
			field.Set(reflect.ValueOf(shader))
		case fragmentShaderType:
			shader := gl.FragmentShader(gl.CreateShader(gl.FRAGMENT_SHADER))
			field.Set(reflect.ValueOf(shader))
		case programType:
			program := gl.CreateProgram()
			field.Set(reflect.ValueOf(program))
		}
	}
}
Ejemplo n.º 2
0
func NewGeometry(name string, verticies, normals []float64, elements []*DrawElements) *Geometry {
	var vertexBuffer gl.Buffer = 0
	var normalBuffer gl.Buffer = 0
	if len(verticies) > 0 {
		vertexBuffer = gl.GenBuffer()
		BindArrayData(vertexBuffer, verticies)
	}
	if len(normals) > 0 {
		normalBuffer = gl.GenBuffer()
		BindArrayData(normalBuffer, normals)
	}
	return &Geometry{
		name,
		vertexBuffer,
		normalBuffer,
		elements,
	}
}
Ejemplo n.º 3
0
func NewDrawElements(elements []int16, drawType gl.Enum) *DrawElements {
	count := len(elements)
	if count > 0 {
		buffer := gl.GenBuffer()
		BindArrayData(buffer, elements)
		return &DrawElements{
			buffer,
			drawType,
			count,
		}
	}
	return nil
}