Example #1
0
File: mesh.go Project: klkblake/sge
func setupAttrib(location gl33.Uint, type_ gl33.Enum, dimensions int, offset uintptr, vertexSize int) {
	gl33.EnableVertexAttribArray(location)
	if type_ == gl33.FLOAT || type_ == gl33.DOUBLE {
		gl33.VertexAttribPointer(location, gl33.Int(dimensions), type_, gl33.FALSE, gl33.Sizei(vertexSize), gl33.Pointer(offset))
	} else {
		gl33.VertexAttribIPointer(location, gl33.Int(dimensions), type_, gl33.Sizei(vertexSize), gl33.Pointer(offset))
	}
}
Example #2
0
func (p *Program) Link() error {
	linkOk := gl.Int(gl.FALSE)
	gl.LinkProgram(p.id)
	gl.GetProgramiv(p.id, gl.LINK_STATUS, &linkOk)
	if linkOk == gl.FALSE {
		return p.getError()
	}
	return nil
}
Example #3
0
func (s *Shader) Compile() error {
	compileOk := gl.Int(gl.FALSE)
	gl.CompileShader(s.id)
	gl.GetShaderiv(s.id, gl.COMPILE_STATUS, &compileOk)
	if compileOk == gl.FALSE {
		return s.getError()
	}
	return nil
}
Example #4
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)

}
Example #5
0
func LoadShader(data string, shaderType ShaderType) (*Shader, error) {
	var id gl.Uint
	switch shaderType {
	case VertexShader:
		id = gl.CreateShader(gl.VERTEX_SHADER)
	case FragmentShader:
		id = gl.CreateShader(gl.FRAGMENT_SHADER)
	default:
		return nil, ErrUnknownShader
	}
	shader := &Shader{id: id}
	src := gl.GLStringArray(data)
	length := gl.Int(-1)
	gl.ShaderSource(shader.id, gl.Sizei(1), &src[0], &length)
	gl.GLStringArrayFree(src)
	return shader, nil
}
Example #6
0
func (vbo *VertexBufferObject) DrawArrays(start, end int) {
	gl.DrawArrays(gl.TRIANGLES, gl.Int(start), gl.Sizei(end))
}
Example #7
0
func (tex *Texture) SetFilters(minFilter int, magFilter int) {
	tex.Bind(0)
	gl33.TexParameteri(tex.Type, gl33.TEXTURE_MIN_FILTER, gl33.Int(minFilter))
	gl33.TexParameteri(tex.Type, gl33.TEXTURE_MAG_FILTER, gl33.Int(magFilter))
}
func (loc *UniformLocation) Uniform1i(value int) {
	gl.Uniform1i(loc.id, gl.Int(value))
}
Example #9
0
func (shader *Shader) Source(source string) {
	str := gl33.GLString(source)
	defer gl33.GLStringFree(str)
	length := gl33.Int(len(source))
	gl33.ShaderSource(shader.Id, 1, &str, &length)
}
Example #10
0
func SetViewport(left, top, right, bottom int) {
	gl.Viewport(gl.Int(left), gl.Int(top), gl.Sizei(right), gl.Sizei(bottom))
}
func (loc *AttributeLocation) AttribPointerFloat(size int, normalized bool, stride int, pointer gl.Pointer) {
	gl.VertexAttribPointer(loc.id, gl.Int(size), gl.FLOAT, gl.GLBool(normalized), gl.Sizei(stride), pointer)
}