Skip to content

Commit 824184a

Browse files
committed
zig-raylib: Add raygui and raymath coverage, and mistakes section to SKILL.md
1 parent af619f9 commit 824184a

7 files changed

Lines changed: 807 additions & 54 deletions

File tree

zig-raylib/SKILL.md

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub fn build(b: *std.Build) void {
5151
exe.root_module.addImport("raylib", raylib_dep.module("raylib"));
5252
exe.root_module.linkLibrary(raylib_dep.artifact("raylib"));
5353
54+
// Optional: add raygui for GUI widgets
55+
exe.root_module.addImport("raygui", raylib_dep.module("raygui"));
56+
5457
b.installArtifact(exe);
5558
5659
const run_cmd = b.addRunArtifact(exe);
@@ -120,6 +123,52 @@ const shader = try rl.loadShader(null, "shaders/effect.fs");
120123
defer rl.unloadShader(shader);
121124
```
122125

126+
## Critical: Common Mistakes (WRONG vs CORRECT)
127+
128+
```zig
129+
// WRONG: Importing raymath as a separate module
130+
const raymath = @import("raymath");
131+
// CORRECT: Access raymath through the raylib module
132+
const rl = @import("raylib");
133+
// then use: rl.math.clamp(), rl.math.lerp(), rl.math.matrixMultiply(), etc.
134+
135+
// WRONG: Importing rlgl as a separate module
136+
const rlgl = @import("rlgl");
137+
// CORRECT: Access rlgl through the raylib module
138+
const rlgl = rl.gl; // or use rl.gl.* directly
139+
140+
// WRONG: Calling play as a method on sound
141+
sound.play();
142+
// CORRECT: Use free function for sound playback
143+
rl.playSound(sound);
144+
145+
// WRONG: Calling crossProduct as a method on Vector2
146+
const cross = v1.crossProduct(v2);
147+
// CORRECT: Vector2 crossProduct is a FREE FUNCTION only
148+
const cross = rl.math.vector2CrossProduct(v1, v2);
149+
// NOTE: Vector3 DOES have crossProduct as a method: v1.crossProduct(v2)
150+
151+
// WRONG: Using try on functions that don't return error unions
152+
const s = try rl.loadSoundFromWave(wave);
153+
const a = try rl.loadSoundAlias(sound);
154+
const img = try rl.getClipboardImage();
155+
// CORRECT: These return their types directly (no error union)
156+
const s = rl.loadSoundFromWave(wave);
157+
const a = rl.loadSoundAlias(sound);
158+
const img = rl.getClipboardImage();
159+
160+
// WRONG: Expecting raygui button() to return i32
161+
const result: i32 = rg.button(bounds, "Click");
162+
// CORRECT: raygui button() returns bool
163+
if (rg.button(bounds, "Click")) { ... }
164+
165+
// WRONG: Passing const slice to raygui textBox
166+
rg.textBox(bounds, "text", 64, editMode);
167+
// CORRECT: textBox requires a mutable [:0]u8 slice
168+
var buf: [64:0]u8 = .{0} ** 64;
169+
_ = rg.textBox(bounds, &buf, 64, editMode);
170+
```
171+
123172
## Critical: Resource Management with Defer
124173

125174
**Always pair load with unload using defer:**
@@ -405,66 +454,24 @@ if (rl.checkCollisionBoxSphere(box, sphereCenter, sphereRadius)) {
405454
}
406455
```
407456

408-
## Quick Reference: Named Colors
409-
410-
| Color | Usage |
411-
|-------|-------|
412-
| `.white` | White (255, 255, 255) |
413-
| `.black` | Black (0, 0, 0) |
414-
| `.ray_white` | Off-white background (245, 245, 245) |
415-
| `.blank` | Transparent (0, 0, 0, 0) |
416-
| `.red` | Red |
417-
| `.green` | Green |
418-
| `.blue` | Blue |
419-
| `.yellow` | Yellow |
420-
| `.orange` | Orange |
421-
| `.pink` | Pink |
422-
| `.purple` | Purple |
423-
| `.gray` | Gray |
424-
| `.dark_gray` | Dark gray |
425-
| `.light_gray` | Light gray |
426-
| `.gold` | Gold |
427-
| `.lime` | Lime green |
428-
| `.sky_blue` | Sky blue |
429-
| `.maroon` | Maroon |
430-
| `.violet` | Violet |
431-
| `.beige` | Beige |
432-
| `.brown` | Brown |
433-
| `.dark_brown` | Dark brown |
434-
| `.dark_green` | Dark green |
435-
| `.dark_purple` | Dark purple |
436-
| `.magenta` | Magenta |
437-
438-
## Quick Reference: Key Codes
439-
440-
| Key | Code | Key | Code |
441-
|-----|------|-----|------|
442-
| Space | `.space` | Escape | `.escape` |
443-
| Enter | `.enter` | Tab | `.tab` |
444-
| Backspace | `.backspace` | Delete | `.delete` |
445-
| Arrow Right | `.right` | Arrow Left | `.left` |
446-
| Arrow Up | `.up` | Arrow Down | `.down` |
447-
| A-Z | `.a` to `.z` | 0-9 | `.zero` to `.nine` |
448-
| F1-F12 | `.f1` to `.f12` | | |
449-
450-
## Quick Reference: Mouse Buttons
451-
452-
| Button | Code |
453-
|--------|------|
454-
| Left | `.left` |
455-
| Right | `.right` |
456-
| Middle | `.middle` |
457-
| Side | `.side` |
458-
| Extra | `.extra` |
459-
| Forward | `.forward` |
460-
| Back | `.back` |
457+
## Quick Reference
458+
459+
**Named Colors:** `.white`, `.black`, `.ray_white`, `.blank`, `.red`, `.green`, `.blue`, `.yellow`, `.orange`, `.pink`, `.purple`, `.gray`, `.dark_gray`, `.light_gray`, `.gold`, `.lime`, `.sky_blue`, `.maroon`, `.violet`, `.beige`, `.brown`, `.dark_brown`, `.dark_green`, `.dark_purple`, `.magenta` — or `rl.Color.init(r, g, b, a)` for custom.
460+
461+
**Key Codes:** `.a`-`.z`, `.zero`-`.nine`, `.f1`-`.f12`, `.space`, `.enter`, `.escape`, `.tab`, `.backspace`, `.delete`, `.up`/`.down`/`.left`/`.right`, `.left_shift`, `.left_control`, `.left_alt`
462+
463+
**Mouse Buttons:** `.left`, `.right`, `.middle`, `.side`, `.extra`, `.forward`, `.back`
461464

462465
## Module Reference
463466

464467
### Core
465468
- **[Core API](references/api-core.md)** - Window, input, timing, Camera2D
466469
- **[Drawing API](references/api-drawing.md)** - 2D shapes, textures, text, collision
467470
- **[3D API](references/api-3d.md)** - Camera3D, models, animation, shaders, PBR
471+
- **[Math & GL API](references/api-math-gl.md)** - raymath (`rl.math.*`), rlgl (`rl.gl.*`)
472+
473+
### GUI
474+
- **[Raygui API](references/api-raygui.md)** - GUI widgets, styling, dialogs
468475

469476
### Resources
470477
- **[Resources API](references/api-resources.md)** - Loading/unloading patterns

zig-raylib/references/api-3d.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ shader.locs[@intFromEnum(rl.ShaderLocationIndex.map_albedo)] =
575575
rl.drawTexture(texture, 0, 0, .white);
576576
}
577577
578+
// Method syntax alternatives
579+
shader.activate(); // Same as rl.beginShaderMode(shader)
580+
defer shader.deactivate(); // Same as rl.endShaderMode()
581+
578582
// For models (assign to material)
579583
model.materials[0].shader = shader;
580584
model.draw(.init(0, 0, 0), 1.0, .white);

zig-raylib/references/api-audio.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ defer rl.unloadSound(sound);
4444
// From wave data
4545
const wave = try rl.loadWave("assets/explosion.wav");
4646
defer rl.unloadWave(wave);
47+
// NOTE: loadSoundFromWave does NOT return an error union (no try needed)
4748
const soundFromWave = rl.loadSoundFromWave(wave);
4849
defer rl.unloadSound(soundFromWave);
4950
5051
// Sound alias (shares audio buffer, saves memory)
52+
// NOTE: loadSoundAlias does NOT return an error union (no try needed)
5153
const soundAlias = rl.loadSoundAlias(sound);
5254
defer rl.unloadSoundAlias(soundAlias);
5355

zig-raylib/references/api-core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ rl.openURL("https://www.raylib.com");
484484
// Clipboard
485485
rl.setClipboardText("Hello");
486486
const text = rl.getClipboardText();
487-
const clipImage = rl.getClipboardImage(); // Get image from clipboard
487+
const clipImage = rl.getClipboardImage(); // Returns Image directly (no try needed)
488488
489489
// Event waiting (for non-game apps to reduce CPU)
490490
rl.enableEventWaiting(); // Only process on events (saves CPU)

0 commit comments

Comments
 (0)