raylib

  1. raylib
    1. Description
    2. Requirements
    3. Documentation
      1. Color interface
      2. Vector interface
      3. Rectangle interface
      4. Texture interface
      5. Camera2D interface
      6. Camera3D interface
      7. Constants
      8. General interface
        1. Window-related functions
        2. Drawing-related functions
        3. Timing-related functions
        4. Input-related functions: keyboard
        5. Input-related functions: mouse
        6. Misc. functions
        7. File system functions
        8. Texture loading functions
        9. Basic shapes drawing functions
        10. Texture drawing functions
        11. Text drawing functions
      9. Quality of life
    4. Example
    5. Source repository
    6. Authors
    7. 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

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)

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:

General interface

[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?)
[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] (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.

[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.

[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)

Draw text (using default font).

[procedure] (measure-text TEXT FONTSIZE)

Measure string width for default font.

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)

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