You are looking at historical revision 30828 of this page. It may differ significantly from its current revision.


Bindings to OpenGL with GLEW extension loading.

Chicken's other opengl bindings are based on the old fixed function pipeline OpenGL. These bindings generated by bind with the OpenGL core header file. Additionally, bindings to GLEW are provided for extension management.



All functions and constants from the OpenGL core header file are exported. Scheme style names are provided (underscores and camelCase replaced with hyphens), the gl prefix is removed from names, is functions are given question marks, and constants are bookended by +s (e.g. tex-image2d, enabled?, +arb-viewport-array+).

Functions whose C counterparts accept or return GLboolean accept or return a Scheme boolean value. Do not pass +true+ or +false+ to these functions.

GLEW functions

[procedure] (init)

Required to initialize GLEW/OpenGL. An OpenGL context must be created before this is called.

[procedure] (supported? EXTENSION-NAME)

Query whether the OpenGL extension, given as a string, is supported.

GL helper functions

[procedure] (make-shader TYPE SOURCE)

Creates and compiles a shader object given the shader's type (e.g. +vertex-shader+, +geometry-shader+, +fragment-shader), and a string containing the GLSL source. Returns an integer representing the ID of the shader.

[procedure] (make-program SHADER-LIST)

Creates and links a program object, given a list of shader objects (i.e. the integers returned by make-shader. Returns an integer representing the ID of the program.

[procedure] (gen-buffer)
[procedure] (gen-framebuffer)
[procedure] (gen-program-pipeline)
[procedure] (gen-query)
[procedure] (gen-renderbuffer)
[procedure] (gen-sampler)
[procedure] (gen-texture)
[procedure] (gen-transform-feedback)
[procedure] (gen-vertex-array)

Analogous to their pluralized counterparts, but only generates and returns one (integer) object.

[procedure] (delete-buffer BUFFER)
[procedure] (delete-framebuffer FRAMEBUFFER)
[procedure] (delete-program-pipeline PROGRAM-PIPELINE)
[procedure] (delete-query QUERY)
[procedure] (delete-renderbuffer RENDERBUFFER)
[procedure] (delete-sampler SAMPLER)
[procedure] (delete-texture TEXTURE)
[procedure] (delete-transform-feedback TRANSFORM-FEEDBACK)
[procedure] (delete-vertex-array VERTEX-ARRAY)

Analogous to their pluralized counterparts, but only accepts and deletes one (integer) object.


This example depends on the glfw3 egg for window and context creation.

(import chicken scheme)
(use (prefix glfw3 glfw:) (prefix opengl-glew gl:))

(define *vertex* 
#version 330
in vec2 vertex;
in vec3 color;
out vec3 c;
uniform mat4 viewMatrix;

void main(){
   gl_Position = (viewMatrix * vec4(vertex, 0.0, 1.0));
   c = color;

(define *fragment*
#version 330
in vec3 c;
out vec4 fragColor;
void main(){
  fragColor = vec4(c, 1.0);

(glfw:with-window (640 480 "Example" resizable: #f)
  ;; glfw3 automatically calls (gl:init) here when opengl-glew is loaded

  (print (gl:supported? "GL_ARB_framebuffer_object"))

  (set! *vertex* (gl:make-shader gl:+vertex-shader+ *vertex*))
  (set! *fragment* (gl:make-shader gl:+fragment-shader+ *fragment*))

  ;;If this is not zero, then everything is working:
  (print (gl:make-program (list *vertex* *fragment*))))

Version history

Version 0.3.0

Version 0.2.0

Version 0.1.0

Source repository

Source available on GitHub.

Bug reports and patches welcome! Bugs can be reported via GitHub or to alex.n.charlton at gmail.


Alex Charlton