gl-init
gl-viewport/ restrict
gl-draw-point
gl-draw-line
mode/ c
gl-draw-circle
gl-draw-rectangle
call-with-rotation
call-with-mirror
call-with-scale
call-with-translate
with-rotation
with-mirror
with-scale
with-translate
1 Textures
gl-texture?
valid-gl-texture?
gl-texture-width
gl-texture-height
gl-load-texture
gl-bind-texture
gl-draw-rectangle/ texture
gl-draw-rectangle/ texture-part
gl-free-texture
Version: 4.2.1.5

OpenGL 2D Graphics

Jay McCarthy <jay at plt-scheme dot org>

This package provides convenience routines for 2D graphics with OpenGL.

 (require (planet jaymccarthy/gl2d))

(gl-init width height)  void
  width : integer?
  height : integer?

Initializes the GL canvas to be width wide and height tall (in pixels).

(gl-viewport/restrict mw mh vw vh cx cy)  void
  mw : real?
  mh : real?
  vw : real?
  vh : real?
  cx : real?
  cy : real?

Initializes the GL canvas with a vw by vh viewport centered around (cx,cy) where the maximum area in the scene is mw by mh. All real values are not necessarily pixels.

(gl-draw-point x y)  void
  x : real?
  y : real?
(gl-draw-line x1 y1 x2 y2)  void
  x1 : real?
  y1 : real?
  x2 : real?
  y2 : real?

The obvious operations.

mode/c : contract?

Equivalent to (symbols 'solid 'outline)

(gl-draw-circle mode)  void
  mode : mode/c

Draws an approximation of the unit circle. Use call-with-scale for a different radius and call-with-translate for a different center.

(gl-draw-rectangle mode w h)  void
  mode : mode/c
  w : real?
  h : real?

Draws a rectangle. Use call-with-translate for a different corner.

(call-with-rotation degrees thnk)  void
  degrees : real?
  thnk : (-> void)
(call-with-mirror figure-width thnk)  void
  figure-width : real?
  thnk : (-> void)
(call-with-scale x y thnk)  void
  x : real?
  y : real?
  thnk : (-> void)
(call-with-translate x y thnk)  void
  x : real?
  y : real?
  thnk : (-> void)

Render with a transformation matrix.

(with-rotation degrees e ...)
(with-mirror figure-width e ...)
(with-scale x y e ...)
(with-translate x y e ...)

Syntax versions of the above.

1 Textures

(gl-texture? v)  boolean?
  v : any/c

Tests texture-ness.

(valid-gl-texture? v)  boolean?
  v : any/c

Only true if texture has not been freed.

(gl-texture-width tex)  exact-nonnegative-integer?
  tex : gl-texture?
(gl-texture-height tex)  exact-nonnegative-integer?
  tex : gl-texture?

Accessors

(gl-load-texture pth)  valid-gl-texture?
  pth : path-string?

Loads a PNG with an alpha mask as a texture.

(gl-bind-texture tex)  void
  tex : valid-gl-texture?

Binds a texture for subsequent rendering.

(gl-draw-rectangle/texture w h)  void
  w : real?
  h : real?

Renders the currently bound texture on a rectangle.

(gl-draw-rectangle/texture-part tx    
  ty    
  tw    
  th    
  w    
  h)  void
  tx : (real-in 0 1)
  ty : (real-in 0 1)
  tw : (real-in 0 1)
  th : (real-in 0 1)
  w : real?
  h : real?

Renders part of the currently bound texture on a rectangle. (The texture is normalized to a 1x1 square.)

(gl-free-texture tex)  void
  tex : valid-gl-texture?

Frees a texture. It is no longer a valid-gl-texture?.