OpenGL 2D Graphics
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.
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.
Render with a transformation matrix.
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.
| ||||||||||||||||||||||||||||||||||||||||||
| 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?.