(bind-func Shader
"create (and compile) an OpenGL shader"
(lambda (source:String* type:GLenum)
(if (not (or (= type GL_VERTEX_SHADER)
(= type GL_FRAGMENT_SHADER)
(= type GL_GEOMETRY_SHADER)))
(begin (println "Error: shader type must be one of GL_VERTEX_SHADER, GL_FRAGMENT_SHADER or GL_GEOMETRY_SHADER")
null)
(let ((shader_id (glCreateShader type))
(source_ptr:i8** (salloc))
(shader (Shader:[Shader*,i32,i32]* shader_id type)))
(pset! source_ptr 0 (cstring source))
(glShaderSource shader_id 1 source_ptr (cast null i32*))
(glCompileShader shader_id)
(println 'Shader: shader)
(gl_print_error "Error compiling shader")
shader))))