raylib
- raylib
- Description
- Requirements
- Documentation
- Color interface
- Vector interface
- Rectangle interface
- Texture interface
- Font interface
- Camera2D interface
- Camera3D interface
- Constants
- General interface
- Window-related functions
- Drawing-related functions
- Timing-related functions
- Input-related functions: keyboard
- Input-related functions: mouse
- Misc. functions
- File system functions
- Texture loading functions
- Basic shapes drawing functions
- Texture drawing functions
- Text drawing functions
- Basic geometric 3D shapes drawing functions
- Quality of life
- Example
- Source repository
- Authors
- License
Description
Bindings to the raylib game library version 5.5. These are not complete yet, but all of the functions I commonly use are ported over. It's a very thin wrapper around the raylib C library that hopefully has minimal performance drawbacks.
Types such as Color, Vector2, Vector3, and Rectangle are represented as SRFI-4 vectors to keep the memory managed by CHICKEN.
See raylib.h for more info on each function.
Requirements
- foreigners
- raylib c library (should be installed as a SHARED library on your system. See install-raylib.sh)
Documentation
Color interface
[procedure] (make-color R G B A)Represented as u8vector.
Vector interface
[procedure] (make-vec2 X Y)[procedure] (vec2-x V)
[procedure] (vec2-y V)
[procedure] (make-vec3 X Y Z)
[procedure] (vec3-x V)
[procedure] (vec3-y V)
[procedure] (vec3-z V)
Represented as f32vector.
Rectangle interface
[procedure] (make-rect X Y W H)[procedure] (rect-x RECT)
[procedure] (rect-y RECT)
[procedure] (rect-w RECT)
[procedure] (rect-h RECT)
Represented as f32vector.
Texture interface
[procedure] (make-texture)[procedure] (free-texture TEXTURE)
Allocates C struct in unmanaged memory (C_malloc). Remember to free.
[procedure] (texture-id TEXTURE)[procedure] (texture-width TEXTURE)
[procedure] (texture-height TEXTURE)
[procedure] (texture-mipmaps TEXTURE)
[procedure] (texture-format TEXTURE)
Font interface
[procedure] (make-font)[procedure] (free-font FONT)
Allocates C struct in unmanaged memory (C_malloc). Remember to free.
[procedure] (font-base-size FONT)[procedure] (font-glyph-count FONT)
[procedure] (font-glyph-padding FONT)
[procedure] (font-texture TEXTUREOUT FONT)
[procedure] (font-rec FONT INDEX)
[procedure] (font-glyph-value FONT INDEX)
[procedure] (font-glyph-offset-x FONT INDEX)
[procedure] (font-glyph-offset-y FONT INDEX)
[procedure] (font-glyph-advance-x FONT INDEX)
Camera2D interface
[procedure] (make-camera2d)[procedure] (free-camera2d CAMERA)
Allocates C struct in unmanaged memory (C_malloc). Remember to free.
[procedure] (camera2d-offset CAMERA)[procedure] (camera2d-target CAMERA)
Return f32vector (Vector2).
[procedure] (camera2d-rotation CAMERA)[procedure] (camera2d-zoom CAMERA)
Return flonum.
[procedure] (camera2d-offset-set! CAMERA VEC2)[procedure] (camera2d-target-set! CAMERA VEC2)
[procedure] (camera2d-rotation-set! CAMERA ROTATION)
[procedure] (camera2d-zoom-set! CAMERA ZOOM)
Set the specified slots.
Camera3D interface
[procedure] (make-camera3d)[procedure] (free-camera3d CAMERA)
Allocates C struct in unmanaged memory (C_malloc). Remember to free.
[procedure] (camera3d-position CAMERA)[procedure] (camera3d-target CAMERA)
[procedure] (camera3d-up CAMERA)
Return f32vector (Vector3).
[procedure] (camera3d-fovy CAMERA)Return flonum.
[procedure] (camera3d-projection CAMERA)Return fixnum.
[procedure] (camera3d-position-set! CAMERA VEC3)[procedure] (camera3d-target-set! CAMERA VEC3)
[procedure] (camera3d-up-set! CAMERA VEC3)
[procedure] (camera3d-fovy-set! CAMERA FOVY)
[procedure] (camera3d-projection-set! CAMERA PROJ)
Constants
The following are defined from raylib.h:
- Colors (e.g. LIGHTGRAY)
- KEY_* (e.g. KEY_ENTER)
- MOUSE_BUTTON_* (e.g. MOUSE_BUTTON_LEFT)
- LOG_* (e.g. LOG_INFO)
General interface
Window-related functions
[procedure] (init-window WIDTH HEIGHT TITLE)Initialize window and OpenGL context.
[procedure] (close-window)Close window and unload OpenGL context.
[procedure] (get-screen-width)Get current screen width.
[procedure] (get-screen-height)Get current screen height.
[procedure] (window-should-close?)Check if application should close (KEY_ESCAPE pressed or window's close icon clicked).
[procedure] (set-config-flags FLAGS)Setup init configuration flags (view FLAGS in raylib.h).
Drawing-related functions
[procedure] (begin-drawing)Setup canvas (framebuffer) to start drawing.
[procedure] (end-drawing)End canvas drawing and swap buffers (double buffering).
[procedure] (begin-mode-2d CAMERA)Begin 2D mode with custom camera (2D).
[procedure] (end-mode-2d)Ends 2D mode with custom camera.
[procedure] (begin-mode-3d CAMERA)Begin 3D mode with custom camera (3D).
[procedure] (end-mode-3d)Ends 3D mode and returns to default 2D orthographic mode.
[procedure] (clear-background COLOR)Set background color (framebuffer clear color).
[procedure] (begin-scissor-mode X Y WIDTH HEIGHT)Begin scissor mode (define screen area for following drawing).
[procedure] (end-scissor-mode)End scissor mode.
Timing-related functions
[procedure] (set-target-fps FPS)Set target FPS (maximum).
[procedure] (get-frame-time)Get time in seconds for last frame drawn (delta time).
[procedure] (get-time)Get elapsed time in seconds since InitWindow().
[procedure] (get-fps)Get current FPS.
Input-related functions: keyboard
[procedure] (key-pressed? KEY)Check if a key has been pressed once.
[procedure] (key-pressed-repeat? KEY)Check if a key has been pressed again.
[procedure] (key-down? KEY)Check if a key is being pressed.
[procedure] (key-released? KEY)Check if a key has been released once.
[procedure] (key-up? KEY)Check if a key is NOT being pressed.
[procedure] (get-key-pressed)Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty.
[procedure] (get-char-pressed)Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty.
Input-related functions: mouse
[procedure] (mouse-button-pressed? MOUSEBUTTON)Check if a mouse button has been pressed once.
[procedure] (mouse-button-down? MOUSEBUTTON)Check if a mouse button is being pressed.
[procedure] (mouse-button-released? MOUSEBUTTON)Check if a mouse button has been released once.
[procedure] (mouse-button-up? MOUSEBUTTON)Check if a mouse button is NOT being pressed.
[procedure] (get-mouse-x)Get mouse position X.
[procedure] (get-mouse-y)Get mouse position Y.
[procedure] (get-mouse-position)Get mouse position XY.
Misc. functions
[procedure] (trace-log LOGLEVEL TEXT)Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...).
File system functions
[procedure] (change-directory DIR)Change working directory, return true on success.
Texture loading functions
[procedure] (load-texture FILENAME)Load texture from file into GPU memory (VRAM).
Basic shapes drawing functions
[procedure] (draw-pixel POSX POSY COLOR)Draw a pixel using geometry [Can be slow, use with care].
[procedure] (draw-pixel-v POSITION COLOR)Draw a pixel using geometry (Vector version) [Can be slow, use with care].
[procedure] (draw-line STARTPOSX STARTPOSY ENDPOSX ENDPOSY COLOR)Draw a line.
[procedure] (draw-line-v STARTPOS ENDPOS COLOR)Draw a line (using gl lines).
[procedure] (draw-line-ex STARTPOS ENDPOS THICK COLOR)Draw a line (using triangles/quads).
[procedure] (draw-circle CENTERX CENTERY RADIUS COLOR)Draw a color-filled circle.
[procedure] (draw-circle-v CENTER RADIUS COLOR)Draw a color-filled circle (Vector version).
[procedure] (draw-circle-lines CENTERX CENTERY RADIUS COLOR)Draw circle outline.
[procedure] (draw-circle-lines-v CENTER RADIUS COLOR)Draw circle outline (Vector version).
[procedure] (draw-rectangle POSX POSY WIDTH HEIGHT COLOR)Draw a color-filled rectangle.
[procedure] (draw-rectangle-v POSITION SIZE COLOR)Draw a color-filled rectangle (Vector version).
[procedure] (draw-rectangle-rec RECT COLOR)Draw a color-filled rectangle.
[procedure] (draw-rectangle-pro RECT ORIGIN ROTATION COLOR)Draw a color-filled rectangle with pro parameters.
[procedure] (draw-rectangle-lines POSX POSY WIDTH HEIGHT COLOR)Draw rectangle outline.
[procedure] (draw-rectangle-lines-ex RECT LINETHICK COLOR)Draw rectangle outline with extended parameters.
[procedure] (draw-triangle V1 V2 V3 COLOR)Draw a color-filled triangle (vertex in counter-clockwise order!).
[procedure] (draw-triangle-lines V1 V2 V3 COLOR)Draw triangle outline (vertex in counter-clockwise order!).
Texture drawing functions
[procedure] (draw-texture TEXTURE POSX POSY TINT)Draw a Texture2D.
[procedure] (draw-texture-v TEXTURE POSITION TINT)Draw a Texture2D with position defined as Vector2.
[procedure] (draw-texture-ex TEXTURE POSITION ROTATION SCALE TINT)Draw a Texture2D with extended parameters.
[procedure] (draw-texture-rec TEXTURE SOURCERECT POSITION TINT)Draw a part of a texture defined by a rectangle.
[procedure] (draw-texture-pro TEXTURE SOURCERECT DESTRECT ORIGIN ROTATION TINT)Draw a part of a texture defined by a rectangle with 'pro' parameters.
Text drawing functions
[procedure] (draw-text TEXT POSX POSY FONTSIZE TINT)Draw text (using default font).
[procedure] (draw-text-ex FONT TEXT POSITION FONTSIZE SPACING TINT)Draw text using FONT and additional parameters.
[procedure] (draw-text-pro FONT TEXT POSITION ORIGIN ROTATION FONTSIZE SPACING TINT)Draw text using FONT and pro parameters (rotation).
[procedure] (draw-fps POSX POSY)Draw current FPS.
[procedure] (set-text-line-spacing SPACING)Set vertical line spacing when drawing with line-breaks.
[procedure] (measure-text TEXT FONTSIZE)Measure string width for default font.
[procedure] (measure-text-ex FONT TEXT FONTSIZE SPACING)Measure string size for FONT.
[procedure] (load-font FILENAME)Load font from file into GPU memory (VRAM).
[procedure] (load-font-ex FILENAME FONTSIZE CODEPOINTS CODEPOINTCOUNT)Load font from file with extended parameters, use s32vector for CODEPOINTS.
[procedure] (unload-font FONT)Unload font from GPU memory (VRAM).
[procedure] (font-valid? FONT)Check if a font is valid (font data loaded, WARNING: GPU texture not checked).
Basic geometric 3D shapes drawing functions
[procedure] (draw-line-3d STARTPOS ENDPOS COLOR)Draw a line in 3D world space.
[procedure] (draw-point-3d POSITION COLOR)Draw a point in 3D space, actually a small line.
[procedure] (draw-circle-3d CENTER RADIUS ROTATIONAXIS ROTATIONANGLE COLOR)Draw a circle in 3D world space.
[procedure] (draw-triangle-3d V1 V2 V3 COLOR)Draw a color-filled triangle (vertex in counter-clockwise order!).
[procedure] (draw-cube POSITION WIDTH HEIGHT LENGTH COLOR)Draw cube.
[procedure] (draw-cube-v POSITION SIZE COLOR)Draw cube (Vector version).
[procedure] (draw-cube-wires POSITION WIDTH HEIGHT LENGTH COLOR)Draw cube wires.
[procedure] (draw-cube-wires-v POSITION SIZE COLOR)Draw cube wires (Vector version).
[procedure] (draw-sphere CENTERPOS RADIUS COLOR)Draw sphere.
[procedure] (draw-sphere-ex CENTERPOS RADIUS RINGS SLICES COLOR)Draw sphere with extended parameters.
[procedure] (draw-sphere-wires CENTERPOS RADIUS RINGS SLICES COLOR)Draw sphere wires.
[procedure] (draw-cylinder POSITION RADIUSTOP RADIUSBOTTOM HEIGHT SLICES COLOR)Draw cylinder/cone.
[procedure] (draw-cylinder-ex STARTPOS ENDPOS STARTRADIUS ENDRADIUS HEIGHT SIDES COLOR)Draw cylinder with base at STARTPOS and top at ENDPOS.
[procedure] (draw-cylinder-wires POSITION RADIUSTOP RADIUSBOTTOM HEIGHT SLICES COLOR)Draw cylinder/cone wires.
[procedure] (draw-cylinder-wires-ex STARTPOS ENDPOS STARTRADIUS ENDRADIUS HEIGHT SIDES COLOR)Draw cylinder wires with base at STARTPOS and top at ENDPOS.
[procedure] (draw-capsule STARTPOS ENDPOS RADIUS SLICES RINGS COLOR)Draw a capsule with the center of its sphere caps at STARTPOS and ENDPOS.
[procedure] (draw-capsule-wires STARTPOS ENDPOS RADIUS SLICES RINGS COLOR)Draw a capsule wireframe with the center of its sphere caps at STARTPOS and ENDPOS.
[procedure] (draw-plane CENTERPOS SIZE COLOR)Draw plane XZ.
[procedure] (draw-grid SLICES SPACING)Draw a grid (centered at (0, 0, 0)).
Quality of life
[procedure] (with-window WIDTH HEIGHT TITLE THUNK)[procedure] (with-drawing THUNK)
[procedure] (with-mode-2d CAMERA THUNK)
[procedure] (with-mode-3d CAMERA THUNK)
[procedure] (with-scissor-mode X Y W H THUNK)
Example
(import raylib) (init-window 800 450 "raylib [core] example - basic window") (let loop () (with-drawing (lambda () (clear-background RAYWHITE) (draw-text "Congrats! You created your first window!" 190 200 20 LIGHTGRAY))) (unless (window-should-close?) (loop))) (close-window)
Source repository
https://github.com/meowstr/chicken-raylib
Feel free to open issues and PR's!
Authors
Meowster
License
MIT