Raylib Module
GX includes a raylib module for game and graphics development. Raylib is a
simple C library for games — no callbacks, no complex setup, just a polling
game loop. The GX module wraps raylib’s C API directly via extern fn and
extern struct, keeping the familiar PascalCase naming.
The bindings target raylib 6.0. The bundled header/lib is currently 5.5,
so 6.0-only declarations are commented out in each .gx file under a
raylib 6.0 ONLY banner. Drop in a raylib 6.0 raylib.h and rebuilt libs,
then uncomment those blocks to enable the full 6.0 surface.
Prerequisites
Raylib must be installed separately. You need:
raylib.h — place in modules/raylib/c/
raylib.lib (MSVC) or libraylib.a (GCC) — place in modules/raylib/lib/
- Clang or GCC — required for linking
Usage
Import the sub-modules you need:
import raylib.core // window, timing, drawing, shaders, camera, files, memory, automation, structs
import raylib.input // keyboard/mouse enums and basic query functions
import raylib.shapes // 2D shape drawing, splines, collision
import raylib.text // text drawing, fonts, codepoints, text utilities
import raylib.textures // texture/image loading, drawing, color utilities
import raylib.colors // color constants (RED, BLUE, RAYWHITE, ...)
import raylib.models // 3D shapes, model loading, mesh, materials, animation
import raylib.audio // sound, music streaming, audio streams + callbacks
Build with -I modules:
gx myapp.gx -I modules -o myapp.exe
Hello World
import raylib.core
import raylib.input
import raylib.shapes
import raylib.text
import raylib.colors
fn main() {
InitWindow(800, 450, "GX + Raylib")
SetTargetFPS(60)
while (!WindowShouldClose()) {
BeginDrawing()
ClearBackground(RAYWHITE)
DrawText("Hello from GX!", 190, 200, 20, DARKGRAY)
DrawRectangle(100, 100, 200, 80, RED)
DrawCircle(400, 300, 50.0, BLUE)
DrawFPS(10, 10)
if (IsKeyPressed(KEY_ESCAPE)) {
CloseWindow()
return
}
EndDrawing()
}
CloseWindow()
}
Note: Colors are top-level const values, not functions — write
RED, not rl_red(). See the Colors section.
Core (raylib.core)
Structs
All raylib types are declared as extern struct and used directly:
| Struct | Purpose |
|---|
Vector2 / Vector3 / Vector4 | 2D/3D/4D vectors (mapped to GX vec2/vec3/vec4 with operator overloading + swizzles) |
Matrix | 4x4 transform matrix (column-major, named fields m0..m15) |
Color | r, g, b, a: u8 |
Rectangle | x, y, width, height: f32 |
Image | CPU image (data: *void, width, height, mipmaps, format) |
Texture / Texture2D | GPU texture (id, width, height, mipmaps, format) |
RenderTexture | Render target (id, texture, depth) |
NPatchInfo | N-patch layout (source, left, top, right, bottom, layout) |
GlyphInfo | Glyph data (value, offsetX/Y, advanceX, image) |
Font | Font (baseSize, glyphCount, glyphPadding, texture, recs, glyphs) |
Camera2D | 2D camera (offset, target, rotation, zoom) |
Camera3D / Camera | 3D camera (position, target, up, fovy, projection) |
Shader | Shader program (id, locs: *c_int) |
MaterialMap | Material slot (texture, color, value) |
Material | Rendering material (shader, maps, params: f32[4]) |
Mesh | Vertex data (positions, normals, tangents, colors, indices, bone weights, VAO/VBO ids) |
Model | 3D model (transform, meshes, materials, meshMaterial, bones, bindPose) |
ModelAnimation | Skeletal animation (boneCount, frameCount, bones, framePoses, name) |
Transform | Bone transform (translation, rotation, scale) |
BoneInfo | Skeleton bone (name: c_char[32], parent) |
Ray | Ray (position, direction) |
RayCollision | Hit info (hit, distance, point, normal) |
BoundingBox | AABB (min, max) |
Wave | Audio wave (frameCount, sampleRate, sampleSize, channels, data) |
AudioStream | Stream (buffer, processor, sampleRate, sampleSize, channels) |
Sound | Loaded sound (stream, frameCount) |
Music | Streamed music (stream, frameCount, looping, ctxType, ctxData) |
VrDeviceInfo | HMD parameters (resolution, screen size, IPD, lens distortion) |
VrStereoConfig | VR stereo render config (per-eye projection/view, lens centers) |
FilePathList | Returned by directory listing (capacity, count, paths) |
AutomationEvent | Recorded input event (opaque on GX side) |
AutomationEventList | Event list (capacity, count, events) |
Construct structs by declaring a variable and setting fields:
var pos:Vector2
pos.x = 100.0
pos.y = 200.0
Window
| Function | Signature | Description |
|---|
InitWindow | (c_int, c_int, cstr) | Create window with width, height, title |
CloseWindow | () | Close window and unload OpenGL context |
WindowShouldClose | → bool | True when ESC pressed or close button clicked |
IsWindowReady | → bool | Window initialized successfully |
IsWindowFullscreen | → bool | Currently fullscreen |
IsWindowHidden | → bool | Currently hidden |
IsWindowMinimized / IsWindowMaximized | → bool | Window state |
IsWindowFocused / IsWindowResized | → bool | Focus / resize this frame |
IsWindowState | (c_uint) → bool | Test specific flag |
SetWindowState / ClearWindowState | (c_uint) | Set / clear window flags |
ToggleFullscreen / ToggleBorderlessWindowed | () | Toggle fullscreen modes |
MaximizeWindow / MinimizeWindow / RestoreWindow | () | Window state changes |
SetWindowIcon | (Image) | Single-image icon (RGBA 32-bit) |
SetWindowIcons (6.0) | (*Image, c_int) | Multi-image icon set |
SetWindowTitle | (cstr) | Change title |
SetWindowPosition / SetWindowMonitor | | Place window |
SetWindowMinSize / SetWindowMaxSize / SetWindowSize | | Dimensions |
SetWindowOpacity | (f32) | 0.0–1.0 |
SetWindowFocused | () | Bring to front |
GetWindowHandle | → *void | Native HWND/NSWindow/X11 handle |
GetScreenWidth / GetScreenHeight | → c_int | Logical size |
GetRenderWidth / GetRenderHeight | → c_int | Pixel size (HiDPI) |
GetMonitorCount / GetCurrentMonitor | → c_int | Monitor info |
GetMonitorPosition | (c_int) → Vector2 | |
GetMonitorWidth / GetMonitorHeight / GetMonitorRefreshRate | (c_int) → c_int | |
GetMonitorPhysicalWidth / GetMonitorPhysicalHeight | (c_int) → c_int | In mm |
GetMonitorName | (c_int) → cstr | UTF-8 monitor name |
GetWindowPosition / GetWindowScaleDPI | → Vector2 | |
SetClipboardText / GetClipboardText | | Text clipboard |
GetClipboardImage | → Image | Image clipboard |
EnableEventWaiting / DisableEventWaiting | () | Block on events vs poll |
Cursor
ShowCursor, HideCursor, IsCursorHidden, EnableCursor, DisableCursor,
IsCursorOnScreen.
Drawing Lifecycle
| Function | Description |
|---|
BeginDrawing() / EndDrawing() | Frame boundary |
ClearBackground(color) | Clear framebuffer |
BeginMode2D(camera) / EndMode2D() | 2D camera mode |
BeginMode3D(camera) / EndMode3D() | 3D camera mode |
BeginTextureMode(target) / EndTextureMode() | Render to texture |
BeginShaderMode(shader) / EndShaderMode() | Custom shader |
BeginBlendMode(mode) / EndBlendMode() | Blending mode |
BeginScissorMode(x,y,w,h) / EndScissorMode() | Scissor clipping |
BeginVrStereoMode(config) / EndVrStereoMode() | VR stereo |
VR Stereo
| Function | Signature |
|---|
LoadVrStereoConfig | (VrDeviceInfo) → VrStereoConfig |
UnloadVrStereoConfig | (VrStereoConfig) |
Shaders
| Function | Signature |
|---|
LoadShader | (cstr, cstr) → Shader — vertex + fragment file paths |
LoadShaderFromMemory | (cstr, cstr) → Shader — source strings |
IsShaderValid | (Shader) → bool |
GetShaderLocation / GetShaderLocationAttrib | (Shader, cstr) → c_int |
SetShaderValue | (Shader, c_int, *void, c_int) |
SetShaderValueV | (Shader, c_int, *void, c_int, c_int) — vector |
SetShaderValueMatrix | (Shader, c_int, Matrix) |
SetShaderValueTexture | (Shader, c_int, Texture) |
UnloadShader | (Shader) |
Screen-Space
| Function | Description |
|---|
GetScreenToWorldRay(pos, camera) | Screen point to 3D ray |
GetScreenToWorldRayEx(pos, camera, w, h) | Same, in custom viewport |
GetWorldToScreen(pos3d, camera) | 3D to screen |
GetWorldToScreenEx(pos3d, camera, w, h) | Same, custom viewport |
GetWorldToScreen2D / GetScreenToWorld2D | 2D camera space conversions |
GetCameraMatrix / GetCameraMatrix2D | View matrix |
Timing
| Function | Description |
|---|
SetTargetFPS(fps) | Frame rate cap (0 = unlimited) |
GetFPS() | Current FPS |
GetFrameTime() | Delta time (seconds) |
GetTime() | Time since InitWindow (seconds) |
SwapScreenBuffer() | Manual buffer swap (custom frame control) |
PollInputEvents() | Manual input pump |
WaitTime(seconds) | Halt execution |
Random
| Function | Description |
|---|
SetRandomSeed(seed) | Seed RNG |
GetRandomValue(min, max) | Inclusive integer in range |
LoadRandomSequence(count, min, max) → *c_int | Unique-value sequence |
UnloadRandomSequence(seq) | Free sequence |
Logging
| Function | Description |
|---|
SetTraceLogLevel(level) | Min log level |
TraceLog(level, text) | Log a string (variadic version not exposed — pre-format with string interpolation) |
Memory
| Function | Description |
|---|
MemAlloc(size) → *void | Raylib’s internal allocator |
MemRealloc(ptr, size) → *void | |
MemFree(ptr) | |
File I/O — Data & Text
| Function | Description |
|---|
LoadFileData(name, *size) → *u8 | Read binary file |
UnloadFileData(data) | Free LoadFileData result |
SaveFileData(name, data, size) → bool | Write binary file |
ExportDataAsCode(data, size, name) → bool | Dump as .h array |
LoadFileText(name) → *c_char | Read text file |
UnloadFileText(text) | Free text |
SaveFileText(name, text) → bool | Write text file |
File System Management
| Function | Description |
|---|
FileExists(name) → bool | |
DirectoryExists(path) → bool | |
IsFileExtension(name, ext) → bool | |
IsPathFile(path) → bool | |
IsFileNameValid(name) → bool | |
GetFileLength(name) → c_int | Size in bytes |
GetFileModTime(name) → c_long | Last write time |
GetFileExtension(name) → cstr | Returns .png, .gx, … |
GetFileName(path) → cstr | Strip directory |
GetFileNameWithoutExt(path) → cstr | Strip directory + extension |
GetDirectoryPath(path) → cstr | Containing directory |
GetPrevDirectoryPath(path) → cstr | Parent directory |
GetWorkingDirectory() → cstr | CWD |
GetApplicationDirectory() → cstr | Executable’s directory |
MakeDirectory(path) → c_int | Create (recursively) |
ChangeDirectory(path) → bool | chdir |
LoadDirectoryFiles(path) → FilePathList | List directory |
LoadDirectoryFilesEx(base, filter, scanSubdirs) → FilePathList | Filtered listing |
UnloadDirectoryFiles(list) | Free |
IsFileDropped() → bool | Drag-and-drop detected |
LoadDroppedFiles() → FilePathList | Get dropped paths |
UnloadDroppedFiles(list) | Free |
| 6.0 only | FileRename, FileRemove, FileCopy, FileMove, FileTextReplace, FileTextFindIndex, GetDirectoryFileCount, GetDirectoryFileCountEx |
Compression / Encoding / Hashes
| Function | Description |
|---|
CompressData(data, size, *outSize) → *u8 | DEFLATE compress |
DecompressData(comp, size, *outSize) → *u8 | DEFLATE decompress |
EncodeDataBase64(data, size, *outSize) → *c_char | Base64 encode |
DecodeDataBase64(text, *outSize) → *u8 | Base64 decode |
ComputeCRC32(data, size) → c_uint | |
ComputeMD5(data, size) → *c_uint | Returns 4×u32 |
ComputeSHA1(data, size) → *c_uint | Returns 5×u32 |
ComputeSHA256(data, size) → *c_uint (6.0) | Returns 8×u32 |
All allocate via raylib’s allocator — free with MemFree.
Automation Events
Record and replay input for testing:
var list = LoadAutomationEventList("") // empty list
SetAutomationEventList(&list)
StartAutomationEventRecording()
// ... gameplay ...
StopAutomationEventRecording()
ExportAutomationEventList(list, "playback.txt")
| Function | Description |
|---|
LoadAutomationEventList(name) → AutomationEventList | |
UnloadAutomationEventList(list) | |
ExportAutomationEventList(list, name) → bool | |
SetAutomationEventList(*list) | Set recording target |
SetAutomationEventBaseFrame(frame) | |
StartAutomationEventRecording() / StopAutomationEventRecording() | |
PlayAutomationEvent(event) | Replay one event |
Misc
| Function | Description |
|---|
TakeScreenshot(name) | Save screenshot (extension determines format) |
OpenURL(url) | Open URL in default browser |
SetConfigFlags(flags) | Init flags (call before InitWindow) |
Mouse (Core)
GetMousePosition, GetMouseDelta, GetMouseX/Y, SetMousePosition,
SetMouseOffset, SetMouseScale, GetMouseWheelMove, GetMouseWheelMoveV,
SetMouseCursor.
Touch & Gestures
GetTouchPosition, GetTouchPointId, GetTouchPointCount, GetTouchX,
GetTouchY, SetGesturesEnabled, IsGestureDetected, GetGestureDetected,
GetGestureHoldDuration, GetGestureDragVector, GetGestureDragAngle,
GetGesturePinchVector, GetGesturePinchAngle.
Camera
UpdateCamera(camera, mode), UpdateCameraPro(camera, movement, rotation, zoom).
Gamepad
| Function | Description |
|---|
IsGamepadAvailable(id) | |
GetGamepadName(id) → cstr | |
IsGamepadButtonPressed/Down/Released/Up(id, btn) | |
GetGamepadButtonPressed() → c_int | |
GetGamepadAxisCount(id) → c_int | |
GetGamepadAxisMovement(id, axis) → f32 | |
SetGamepadVibration(id, left, right, dur) | |
SetGamepadMappings(mappings) → c_int (6.0) | SDL_GameControllerDB string |
| Function | Description |
|---|
GetCharPressed() → c_int | Unicode char queue |
SetExitKey(key) | Override default ESC quit |
GetKeyName(key) → cstr (6.0) | Layout-aware key label |
Keyboard
if (IsKeyPressed(KEY_SPACE)) { jump() }
if (IsKeyDown(KEY_A)) { move_left() }
| Function | Description |
|---|
IsKeyPressed(key) → bool | Pressed this frame |
IsKeyPressedRepeat(key) → bool | Pressed (with OS repeat) |
IsKeyDown(key) → bool | Held |
IsKeyReleased(key) → bool | Released this frame |
IsKeyUp(key) → bool | Not held |
GetKeyPressed() → c_int | Pop from queue (0 when empty) |
Key constants: KEY_A..KEY_Z, KEY_ZERO..KEY_NINE, KEY_SPACE, KEY_ESCAPE,
KEY_ENTER, KEY_TAB, KEY_BACKSPACE, KEY_INSERT, KEY_DELETE,
arrow keys, KEY_HOME/KEY_END/KEY_PAGE_UP/KEY_PAGE_DOWN,
KEY_F1..KEY_F12, modifiers (KEY_LEFT_SHIFT, KEY_LEFT_CONTROL,
KEY_LEFT_ALT, KEY_LEFT_SUPER plus RIGHT_*), keypad
(KEY_KP_0..KEY_KP_9, KEY_KP_ADD, KEY_KP_SUBTRACT, KEY_KP_MULTIPLY,
KEY_KP_DIVIDE, KEY_KP_DECIMAL, KEY_KP_ENTER).
| Function | Description |
|---|
IsMouseButtonPressed/Down/Released/Up(button) → bool | |
Constants: MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT, MOUSE_BUTTON_MIDDLE,
MOUSE_BUTTON_SIDE, MOUSE_BUTTON_EXTRA, MOUSE_BUTTON_FORWARD,
MOUSE_BUTTON_BACK.
Shapes (raylib.shapes)
Pixel & Lines
| Function | Description |
|---|
DrawPixel(x, y, color) / DrawPixelV(pos, color) | Single pixel |
DrawLine(x1, y1, x2, y2, color) / DrawLineV(start, end, color) | Line |
DrawLineEx(start, end, thick, color) | Thick line (triangles) |
DrawLineStrip(*points, count, color) | Connected lines |
DrawLineBezier(start, end, thick, color) | Cubic bezier in-out |
DrawLineDashed(start, end, dashSize, spaceSize, color) (6.0) | Dashed |
Circles & Ellipses
| Function | Description |
|---|
DrawCircle(cx, cy, r, color) / DrawCircleV(c, r, color) | Filled |
DrawCircleLines(cx, cy, r, color) / DrawCircleLinesV(c, r, color) | Outline |
DrawCircleGradient(c, r, inner, outer) | Gradient fill |
DrawCircleSector(c, r, start, end, segments, color) | Pie slice |
DrawCircleSectorLines(...) | Sector outline |
DrawEllipse(cx, cy, rh, rv, color) | Filled ellipse |
DrawEllipseLines(cx, cy, rh, rv, color) | Outline |
DrawEllipseV(c, rh, rv, color) (6.0) | Vector center |
DrawEllipseLinesV(c, rh, rv, color) (6.0) | Vector outline |
DrawRing(c, inner, outer, start, end, segments, color) | Annulus sector |
DrawRingLines(...) | Ring outline |
Rectangles
| Function | Description |
|---|
DrawRectangle(x, y, w, h, color) | Filled |
DrawRectangleV(pos, size, color) / DrawRectangleRec(rec, color) | Vector / Rectangle forms |
DrawRectanglePro(rec, origin, rotation, color) | Rotated around origin |
DrawRectangleGradientV(x, y, w, h, top, bottom) | Vertical gradient |
DrawRectangleGradientH(x, y, w, h, left, right) | Horizontal gradient |
DrawRectangleGradientEx(rec, tl, bl, br, tr) | Per-corner colors |
DrawRectangleLines(x, y, w, h, color) | Outline |
DrawRectangleLinesEx(rec, thick, color) | Thick outline |
DrawRectangleRounded(rec, roundness, segments, color) | Rounded fill |
DrawRectangleRoundedLines(rec, roundness, segments, color) | Rounded outline |
DrawRectangleRoundedLinesEx(rec, roundness, segments, thick, color) | Thick rounded outline |
Triangles & Polygons
| Function | Description |
|---|
DrawTriangle(v1, v2, v3, color) | CCW filled triangle |
DrawTriangleLines(...) | Triangle outline |
DrawTriangleFan(*points, count, color) | Fan from first vertex |
DrawTriangleStrip(*points, count, color) | Triangle strip |
DrawPoly(center, sides, radius, rotation, color) | Regular polygon |
DrawPolyLines(...) | Polygon outline |
DrawPolyLinesEx(..., thick, color) | Thick polygon outline |
Splines
DrawSplineLinear, DrawSplineBasis, DrawSplineCatmullRom,
DrawSplineBezierQuadratic, DrawSplineBezierCubic. Per-segment variants:
DrawSplineSegmentLinear/Basis/CatmullRom/BezierQuadratic/BezierCubic.
Evaluators: GetSplinePointLinear/Basis/CatmullRom/BezierQuad/BezierCubic —
each returns the point on the spline for a parameter t ∈ [0, 1].
Shapes Texture (atlas batching)
SetShapesTexture(myAtlas, sourceRect) // route shape draws through atlas
| Function | Description |
|---|
SetShapesTexture(texture, source) | Set atlas |
GetShapesTexture() → Texture (6.0) | Currently set texture |
GetShapesTextureRectangle() → Rectangle (6.0) | Currently set source |
Collision
| Function | Description |
|---|
CheckCollisionRecs(r1, r2) | Rectangle vs rectangle |
CheckCollisionCircles(c1, r1, c2, r2) | Circle vs circle |
CheckCollisionCircleRec(c, r, rec) | Circle vs rectangle |
CheckCollisionCircleLine(c, r, p1, p2) | Circle vs segment |
CheckCollisionPointRec/Circle/Triangle(point, ...) | Point inclusion |
CheckCollisionPointLine(point, p1, p2, threshold) | Point on segment |
CheckCollisionPointPoly(point, *points, count) | Point in polygon |
CheckCollisionLines(s1, e1, s2, e2, *out) | Segment intersection |
GetCollisionRec(r1, r2) → Rectangle | Overlap rect |
Text (raylib.text)
Drawing
| Function | Description |
|---|
DrawFPS(x, y) | FPS counter |
DrawText(text, x, y, fontSize, color) | Default font |
DrawTextEx(font, text, pos, fontSize, spacing, tint) | Custom font |
DrawTextPro(font, text, pos, origin, rotation, fontSize, spacing, tint) | With rotation |
DrawTextCodepoint(font, codepoint, pos, fontSize, tint) | Single glyph |
DrawTextCodepoints(font, *codepoints, count, pos, fontSize, spacing, tint) | Glyph array |
Font Loading
| Function | Description |
|---|
GetFontDefault() → Font | Built-in font |
LoadFont(name) → Font | TTF / FNT / etc. |
LoadFontEx(name, fontSize, *codepoints, count) → Font | With custom charset |
LoadFontFromImage(image, key, firstChar) → Font | XNA-style sprite font |
LoadFontFromMemory(type, data, size, fontSize, *codepoints, count) → Font | From buffer |
IsFontValid(font) → bool | |
UnloadFont(font) | |
ExportFontAsCode(font, name) → bool | Dump as .h |
Font Atlas (low-level)
var glyphs = LoadFontData(ttfData, ttfSize, 32, NULL, 0, FONT_DEFAULT)
var atlas = GenImageFontAtlas(glyphs, &recs, 95, 32, 4, 0)
UnloadFontData(glyphs, 95)
| Function | Description |
|---|
LoadFontData(data, size, fontSize, *codepoints, count, fontType) → *GlyphInfo | (5.5 form — 6 args; 6.0 adds *glyphCount) |
UnloadFontData(*glyphs, count) | |
GenImageFontAtlas(*glyphs, *recsOut, count, fontSize, padding, packMethod) → Image | |
Measurement
| Function | Description |
|---|
MeasureText(text, fontSize) → c_int | Width with default font |
MeasureTextEx(font, text, fontSize, spacing) → Vector2 | With custom font |
MeasureTextCodepoints(font, *codepoints, len, fontSize, spacing) → Vector2 (6.0) | |
SetTextLineSpacing(spacing) | Newline gap |
GetGlyphIndex(font, codepoint) → c_int | Atlas index |
GetGlyphInfo(font, codepoint) → GlyphInfo | Glyph metrics |
GetGlyphAtlasRec(font, codepoint) → Rectangle | UV rect |
Codepoints / UTF-8
| Function | Description |
|---|
LoadUTF8(*codepoints, length) → *c_char | Encode |
UnloadUTF8(text) | Free |
LoadCodepoints(text, *count) → *c_int | Decode |
UnloadCodepoints(*codepoints) | Free |
GetCodepointCount(text) → c_int | |
GetCodepoint(text, *size) → c_int | Next codepoint |
GetCodepointNext/Previous(text, *size) → c_int | |
CodepointToUTF8(codepoint, *size) → cstr | |
Text Strings
⚠ Most return either a static buffer (overwritten by next call) or a heap
allocation that you must MemFree(). Read each docstring.
| Function | Description |
|---|
TextCopy(dst, src) → c_int | Bytes copied |
TextIsEqual(a, b) → bool | |
TextLength(text) → c_uint | \0-terminated |
TextFormat(text) → cstr | Single-arg form (variadic version not exposed) |
TextSubtext(text, position, length) → cstr | |
TextReplace(text, search, replacement) → *c_char | Free with MemFree |
TextInsert(text, insert, position) → *c_char | Free with MemFree |
TextJoin(textList, count, delimiter) → cstr | |
TextSplit(text, delimiter, *count) → *void | Returns char** |
TextAppend(text, append, *position) | In-place |
TextFindIndex(text, search) → c_int | |
TextToUpper/Lower/Pascal/Snake/Camel(text) → cstr | Case conversion |
TextToInteger(text) → c_int / TextToFloat(text) → f32 | Parse |
| 6.0 only | TextRemoveSpaces, GetTextBetween, TextReplaceAlloc, TextReplaceBetween[Alloc], TextInsertAlloc, LoadTextLines, UnloadTextLines |
Textures (raylib.textures)
Image Loading (CPU)
| Function | Description |
|---|
LoadImage(name) → Image | PNG, JPG, BMP, TGA, GIF, QOI, PSD, DDS, HDR, KTX, ASTC, PKM, PVR |
LoadImageRaw(name, w, h, format, headerSize) → Image | Raw pixel data |
LoadImageAnim(name, *frames) → Image | Animated GIF |
LoadImageAnimFromMemory(type, data, size, *frames) → Image | From buffer |
LoadImageFromMemory(type, data, size) → Image | Decoded image from buffer |
LoadImageFromTexture(texture) → Image | Read GPU → CPU |
LoadImageFromScreen() → Image | Screenshot to Image |
IsImageValid(image) → bool | |
UnloadImage(image) | |
ExportImage(image, name) → bool | |
ExportImageToMemory(image, type, *size) → *u8 | Free with MemFree |
ExportImageAsCode(image, name) → bool | Dump as .h |
Image Generation
| Function | Description |
|---|
GenImageColor(w, h, color) | Solid fill |
GenImageGradientLinear(w, h, direction, start, end) | Linear gradient (degrees) |
GenImageGradientRadial(w, h, density, inner, outer) | Radial |
GenImageGradientSquare(w, h, density, inner, outer) | Square |
GenImageChecked(w, h, cx, cy, c1, c2) | Checkerboard |
GenImageWhiteNoise(w, h, factor) | Noise |
GenImagePerlinNoise(w, h, ox, oy, scale) | Perlin |
GenImageCellular(w, h, tileSize) | Cellular automaton |
GenImageText(w, h, text) | Grayscale text |
Image Manipulation
ImageCopy, ImageFromImage, ImageFromChannel, ImageText, ImageTextEx,
ImageFormat, ImageToPOT, ImageCrop, ImageAlphaCrop/Clear/Mask/Premultiply,
ImageBlurGaussian, ImageKernelConvolution, ImageResize, ImageResizeNN,
ImageResizeCanvas, ImageMipmaps, ImageDither, ImageFlipVertical,
ImageFlipHorizontal, ImageRotate(image, degrees), ImageRotateCW/CCW,
ImageColorTint/Invert/Grayscale/Contrast/Brightness/Replace,
GetImageAlphaBorder, GetImageColor.
| Function | Description |
|---|
LoadImageColors(image) → *Color | Pixels as RGBA32 array |
LoadImagePalette(image, max, *count) → *Color | Distinct colors |
UnloadImageColors(*colors) / UnloadImagePalette(*colors) | |
Image Drawing (CPU rasterizer)
ImageClearBackground, ImageDrawPixel/V, ImageDrawLine/V/Ex,
ImageDrawCircle/V, ImageDrawCircleLines/V, ImageDrawRectangle/V/Rec,
ImageDrawRectangleLines, ImageDrawTriangle/Ex/Lines,
ImageDrawTriangleFan, ImageDrawTriangleStrip, ImageDraw,
ImageDrawText/Ex.
Texture Loading (GPU)
| Function | Description |
|---|
LoadTexture(name) → Texture | |
LoadTextureFromImage(image) → Texture | |
LoadTextureCubemap(image, layout) → Texture | |
LoadRenderTexture(w, h) → RenderTexture | FBO |
IsTextureValid(texture) → bool / IsRenderTextureValid(target) → bool | |
UnloadTexture(texture) / UnloadRenderTexture(target) | |
UpdateTexture(texture, *pixels) / UpdateTextureRec(texture, rec, *pixels) | |
GenTextureMipmaps(*texture) | |
SetTextureFilter(texture, filter) / SetTextureWrap(texture, wrap) | |
Texture Drawing
| Function | Description |
|---|
DrawTexture(texture, x, y, tint) | |
DrawTextureV(texture, pos, tint) | |
DrawTextureEx(texture, pos, rot, scale, tint) | |
DrawTextureRec(texture, source, pos, tint) | Sub-rectangle |
DrawTexturePro(texture, source, dest, origin, rotation, tint) | Full transform |
DrawTextureNPatch(texture, npatchInfo, dest, origin, rotation, tint) | 9-slice |
Color & Pixel Utilities
| Function | Description |
|---|
ColorIsEqual(c1, c2) → bool | |
Fade(color, alpha) → Color | |
ColorToInt(color) → c_int | 0xRRGGBBAA |
ColorNormalize(color) → Vector4 | 0..1 floats |
ColorFromNormalized(v) → Color | Inverse |
ColorToHSV(color) → Vector3 | Hue 0..360, sat/val 0..1 |
ColorFromHSV(h, s, v) → Color | |
ColorTint/Brightness/Contrast/Alpha(color, ...) → Color | Adjustments |
ColorAlphaBlend(dst, src, tint) → Color | |
ColorLerp(c1, c2, factor) → Color | |
GetColor(hex) → Color | From 0xRRGGBBAA |
GetPixelColor(srcPtr, format) → Color | Decode pixel |
SetPixelColor(dstPtr, color, format) | Encode pixel |
GetPixelDataSize(w, h, format) → c_int | Bytes |
Models (raylib.models)
3D Shape Drawing
DrawCube(pos, 2.0, 2.0, 2.0, RED)
DrawSphere(pos, 1.0, BLUE)
DrawGrid(10, 1.0)
| Function | Description |
|---|
DrawLine3D / DrawPoint3D / DrawCircle3D / DrawTriangle3D / DrawTriangleStrip3D | Primitives |
DrawCube / DrawCubeV / DrawCubeWires / DrawCubeWiresV | Cuboid |
DrawSphere / DrawSphereEx / DrawSphereWires | Sphere variants |
DrawCylinder / DrawCylinderEx / DrawCylinderWires / DrawCylinderWiresEx | Cylinder |
DrawCapsule / DrawCapsuleWires | Capsule |
DrawPlane(centerPos, size, color) | XZ plane |
DrawRay(ray, color) | |
DrawGrid(slices, spacing) | Reference grid |
Model Management
| Function | Description |
|---|
LoadModel(name) → Model | OBJ, glTF, IQM, M3D, VOX |
LoadModelFromMesh(mesh) → Model | Single-mesh model |
IsModelValid(model) → bool | |
UnloadModel(model) | |
GetModelBoundingBox(model) → BoundingBox | |
DrawModel(model, pos, scale, tint) | |
DrawModelEx(model, pos, axis, angle, scale, tint) | With rotation |
DrawModelWires(...) / DrawModelWiresEx(...) | Wireframe |
DrawModelPoints(...) / DrawModelPointsEx(...) | (5.5 — removed in 6.0) |
DrawBoundingBox(box, color) | |
DrawBillboard(camera, texture, pos, scale, tint) | |
DrawBillboardRec(camera, texture, source, pos, size, tint) | Sub-rect billboard |
DrawBillboardPro(camera, texture, source, pos, up, size, origin, rotation, tint) | Full control |
Mesh
| Function | Description |
|---|
UploadMesh(*mesh, dynamic) | Push to GPU |
UpdateMeshBuffer(mesh, index, *data, size, offset) | Update VBO |
UnloadMesh(mesh) | |
DrawMesh(mesh, material, transform) | |
DrawMeshInstanced(mesh, material, *transforms, instances) | |
GetMeshBoundingBox(mesh) → BoundingBox | |
GenMeshTangents(*mesh) | |
ExportMesh(mesh, name) → bool | |
ExportMeshAsCode(mesh, name) → bool | Dump as .h |
Mesh Generation
GenMeshPoly, GenMeshPlane, GenMeshCube, GenMeshSphere,
GenMeshHemiSphere, GenMeshCylinder, GenMeshCone, GenMeshTorus,
GenMeshKnot, GenMeshHeightmap, GenMeshCubicmap.
Material
| Function | Description |
|---|
LoadMaterials(name, *count) → *Material | From model file |
LoadMaterialDefault() → Material | DIFFUSE/SPECULAR/NORMAL |
IsMaterialValid(material) → bool | |
UnloadMaterial(material) | |
SetMaterialTexture(*material, mapType, texture) | MATERIAL_MAP_DIFFUSE, etc. |
SetModelMeshMaterial(*model, meshId, materialId) | |
Animation
Signature differs between 5.5 and 6.0:
- 5.5:
UpdateModelAnimation(model, anim, frame: c_int),
UpdateModelAnimationBones(model, anim, frame: c_int),
UnloadModelAnimation(anim).
- 6.0:
UpdateModelAnimation(..., frame: f32),
UpdateModelAnimationEx(model, animA, frameA, animB, frameB, blend) for cross-fading.
| Function | Description |
|---|
LoadModelAnimations(name, *count) → *ModelAnimation | Load all anims |
UpdateModelAnimation(model, anim, frame) | Vertex CPU pose |
UpdateModelAnimationBones(model, anim, frame) (5.5 — replaced in 6.0) | GPU skinning |
UpdateModelAnimationEx(model, a, fa, b, fb, blend) (6.0) | Blended pose |
UnloadModelAnimation(anim) (5.5 — removed in 6.0) | |
UnloadModelAnimations(*animations, count) | Free array |
IsModelAnimationValid(model, anim) → bool | Skeleton compatible |
3D Collision
| Function | Description |
|---|
CheckCollisionSpheres(c1, r1, c2, r2) | |
CheckCollisionBoxes(b1, b2) | |
CheckCollisionBoxSphere(box, c, r) | |
GetRayCollisionSphere(ray, c, r) → RayCollision | |
GetRayCollisionBox(ray, box) → RayCollision | |
GetRayCollisionMesh(ray, mesh, transform) → RayCollision | |
GetRayCollisionTriangle(ray, p1, p2, p3) → RayCollision | |
GetRayCollisionQuad(ray, p1, p2, p3, p4) → RayCollision | |
Audio (raylib.audio)
Device
InitAudioDevice()
defer CloseAudioDevice()
| Function | Description |
|---|
InitAudioDevice() / CloseAudioDevice() | |
IsAudioDeviceReady() → bool | |
SetMasterVolume(volume) / GetMasterVolume() → f32 | 0.0..1.0 |
Wave
| Function | Description |
|---|
LoadWave(name) → Wave | WAV, OGG, MP3, FLAC, QOA, XM, MOD |
LoadWaveFromMemory(type, data, size) → Wave | |
IsWaveValid(wave) → bool | |
UnloadWave(wave) | |
ExportWave(wave, name) → bool | |
WaveCopy(wave) → Wave | |
WaveCrop(*wave, init, final) | Trim |
WaveFormat(*wave, sampleRate, sampleSize, channels) | Convert |
LoadWaveSamples(wave) → *f32 | f32 stereo samples |
UnloadWaveSamples(*samples) | |
Sound
var sfx = LoadSound("explosion.wav")
defer UnloadSound(sfx)
PlaySound(sfx)
SetSoundVolume(sfx, 0.8)
| Function | Description |
|---|
LoadSound(name) → Sound | |
LoadSoundFromWave(wave) → Sound | |
LoadSoundAlias(source) → Sound | Shares sample data; use to play multiple instances |
IsSoundValid(sound) → bool | |
UpdateSound(sound, data, sampleCount) | f32 stereo |
UnloadSound(sound) / UnloadSoundAlias(alias) | |
PlaySound/StopSound/PauseSound/ResumeSound(sound) | |
IsSoundPlaying(sound) → bool | |
SetSoundVolume/Pitch/Pan(sound, value) | |
Music (Streaming)
var music = LoadMusicStream("background.ogg")
PlayMusicStream(music)
while (!WindowShouldClose()) {
UpdateMusicStream(music) // call every frame
// ...
}
| Function | Description |
|---|
LoadMusicStream(name) → Music | |
LoadMusicStreamFromMemory(type, data, size) → Music | |
IsMusicValid(music) → bool | |
UnloadMusicStream(music) | |
PlayMusicStream/Stop/Pause/Resume(music) | |
UpdateMusicStream(music) | Call every frame |
IsMusicStreamPlaying(music) → bool | |
SeekMusicStream(music, seconds) | |
SetMusicVolume/Pitch/Pan(music, value) | |
GetMusicTimeLength(music) → f32 / GetMusicTimePlayed(music) → f32 | Seconds |
AudioStream (Raw PCM)
| Function | Description |
|---|
LoadAudioStream(sampleRate, sampleSize, channels) → AudioStream | |
IsAudioStreamValid(stream) → bool | |
UnloadAudioStream(stream) | |
UpdateAudioStream(stream, data, frameCount) | Push frames |
IsAudioStreamProcessed(stream) → bool | Buffer needs refill |
PlayAudioStream/Pause/Resume/Stop(stream) | |
IsAudioStreamPlaying(stream) → bool | |
SetAudioStreamVolume/Pitch/Pan(stream, value) | |
SetAudioStreamBufferSizeDefault(size) | New-stream default |
Audio Callbacks (raylib 6.0)
AudioCallback signature: fn(*void, c_uint) — (bufferData, frameCount),
each frame = 2 floats (stereo).
| Function | Description |
|---|
SetAudioStreamCallback(stream, callback) | Audio thread requests new data |
AttachAudioStreamProcessor(stream, processor) | Pre-mix per-stream effect |
DetachAudioStreamProcessor(stream, processor) | |
AttachAudioMixedProcessor(processor) | Post-mix master effect |
DetachAudioMixedProcessor(processor) | |
Colors (raylib.colors)
Colors are top-level const values — zero overhead, used directly:
var bg = RAYWHITE
var fg = DARKGRAY
var highlight = RED
ClearBackground(BLACK)
DrawText("Hi", 10, 10, 20, GREEN)
| Constant | RGBA | | Constant | RGBA |
|---|
LIGHTGRAY | 200,200,200,255 | | DARKBLUE | 0,82,172,255 |
GRAY | 130,130,130,255 | | PURPLE | 200,122,255,255 |
DARKGRAY | 80,80,80,255 | | VIOLET | 135,60,190,255 |
YELLOW | 253,249,0,255 | | DARKPURPLE | 112,31,126,255 |
GOLD | 255,203,0,255 | | BEIGE | 211,176,131,255 |
ORANGE | 255,161,0,255 | | BROWN | 127,106,79,255 |
PINK | 255,109,194,255 | | DARKBROWN | 76,63,47,255 |
RED | 230,41,55,255 | | WHITE | 255,255,255,255 |
MAROON | 190,33,55,255 | | BLACK | 0,0,0,255 |
GREEN | 0,228,48,255 | | BLANK | 0,0,0,0 |
LIME | 0,158,47,255 | | MAGENTA | 255,0,255,255 |
DARKGREEN | 0,117,44,255 | | RAYWHITE | 245,245,245,255 |
SKYBLUE | 102,191,255,255 | | | |
BLUE | 0,121,241,255 | | | |
Custom colors: just construct a Color:
var custom = Color{128, 64, 200, 255} // r, g, b, a
Config Flags
Set before InitWindow with SetConfigFlags:
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT)
InitWindow(800, 600, "Resizable Window")
| Flag | Description |
|---|
FLAG_VSYNC_HINT | Enable V-Sync |
FLAG_FULLSCREEN_MODE | Start fullscreen |
FLAG_WINDOW_RESIZABLE | Allow resizing |
FLAG_WINDOW_UNDECORATED | No window frame |
FLAG_WINDOW_HIDDEN | Start hidden |
FLAG_WINDOW_MINIMIZED / FLAG_WINDOW_MAXIMIZED | Start minimized/maximized |
FLAG_WINDOW_UNFOCUSED | Start unfocused |
FLAG_WINDOW_TOPMOST | Always on top |
FLAG_WINDOW_ALWAYS_RUN | Keep running when minimized |
FLAG_WINDOW_TRANSPARENT | Transparent framebuffer |
FLAG_WINDOW_HIGHDPI | High-DPI support |
FLAG_MSAA_4X_HINT | 4x MSAA anti-aliasing |
- Windows: Auto-switches to Clang for linking. The
-DNOGDI -DNOUSER
flags are automatically applied to prevent windows.h from conflicting
with raylib’s Rectangle, CloseWindow, and ShowCursor definitions.
- Linux: Links against
libraylib.a with -lGL -lm -lpthread -ldl -lrt -lX11.
- macOS: Links against
libraylib.a with CoreVideo, IOKit, Cocoa, OpenGL frameworks.
- Web (
--target web): Uses libraylib_web.a (Emscripten build) with
GLFW3, ASYNCIFY, 256 MB initial heap, 16 MB stack. Some extern struct
patterns crash the compiler — see the GX compiler gotchas doc.
- TCC: Not supported for raylib (can’t link static libraries). Clang is
used automatically.
Why Not Source Compilation?
Unlike Sokol (which uses a single @cfile bridge), raylib cannot be compiled
in a single translation unit. Its internal headers (rlgl.h, glad.h) define
global variables that cause redefinition errors when multiple .c files are
included together. Additionally, TCC lacks the Windows SDK headers that
raylib’s GLFW backend requires. The prebuilt library approach is the most
reliable path.
Module Layout
modules/
raylib/
c/
raylib.h Raylib header (currently 5.5; replace with 6.0 to enable 6.0-only bindings)
gx_raylib_types.h Type bridge (vec2/3/4 → Vector2/3/4, color macro undefs)
lib/
raylib.lib Prebuilt static library (MSVC/Windows)
libraylib.a Prebuilt static library (GCC/Linux/macOS)
libraylib_web.a Prebuilt static library (Emscripten/web)
gx/
core.gx Build directives, structs, window, timing, camera, shaders, files, memory, automation
input.gx Keyboard/mouse enums + basic IsKey*/IsMouseButton* queries
shapes.gx 2D shapes, splines, 2D collision
text.gx Text drawing, fonts, codepoints, text utilities
textures.gx Image/texture loading, manipulation, color/pixel utilities
colors.gx Color constants (RED, BLUE, RAYWHITE, ...)
models.gx 3D shapes, model/mesh/material, animations, 3D collision
audio.gx Sound, music streaming, wave, audio streams + 6.0 callbacks
Migrating From raylib 5.5 to 6.0
When you swap modules/raylib/c/raylib.h and the lib/*.lib/*.a files for
raylib 6.0 builds, perform these .gx file edits:
core.gx — uncomment the raylib 6.0 ONLY block at the bottom (adds
SetWindowIcons, GetKeyName, SetGamepadMappings, FileRename/Remove/Copy/Move,
FileTextReplace/FindIndex, GetDirectoryFileCount[Ex], ComputeSHA256).
shapes.gx — uncomment the raylib 6.0 ONLY block (adds
DrawLineDashed, DrawEllipseV, DrawEllipseLinesV, GetShapesTexture,
GetShapesTextureRectangle).
text.gx — uncomment the raylib 6.0 ONLY block (adds TextRemoveSpaces,
GetTextBetween, TextReplaceAlloc, TextReplaceBetween[Alloc],
TextInsertAlloc, LoadTextLines, UnloadTextLines,
MeasureTextCodepoints). Also widen LoadFontData to add a 7th param
glyphCount: *c_int.
models.gx — three breaking changes:
- Change
UpdateModelAnimation frame param from c_int to f32.
- Remove
UpdateModelAnimationBones and UnloadModelAnimation (singular);
uncomment UpdateModelAnimationEx from the 6.0 block.
- Remove
DrawModelPoints and DrawModelPointsEx (gone in 6.0).
audio.gx — no edits needed (6.0 callbacks already declared and
present in 5.5 too).
After these edits, all examples in examples/raylib/ continue to compile —
the breaking changes are localized to model animation, which no current
example exercises.