flan/test/programs/raylib-strings.flan

41 lines
1.9 KiB
Plaintext

;;;; raylib, headless: strings returned from C, a directory listing, and the
;;;; Model, Mesh and Matrix layouts. Nothing here opens a window.
;;;;
;;;; get-file-name answers a pointer into its own argument, which is the
;;;; wrapper's temporary copy, so this is the case the scratch buffer exists
;;;; for. text-to-upper answers raylib's static buffer, which the second call
;;;; overwrites; the first answer must not change when it does.
;;;;
;;;; The layouts are pinned by making raylib compute with them.
;;;; GetMeshBoundingBox reads vertex-count and the vertices pointer, and
;;;; GetModelBoundingBox reads mesh-count, meshes and the transform — a
;;;; translation by (10, 20, 30), which lands in m-12, m-13 and m-14 and moves
;;;; the box by exactly that. A permuted field reads a wrong count, a wrong
;;;; pointer or a wrong translation.
(import rl "vendor:raylib")
(defn show-box [b rl/BoundingBox] ()
(println (.x (.min b)) (.y (.min b)) (.z (.min b)) "/"
(.x (.max b)) (.y (.max b)) (.z (.max b))))
(defn main [] i32
(println (rl/get-file-name "assets/sprites/brush.png"))
(println (rl/get-file-extension "brush.png"))
(println (rl/get-directory-path "assets/sprites/brush.png"))
(let [a (rl/text-to-upper "first")
b (rl/text-to-upper "second")]
(println a b))
(println (length (rl/directory-files "programs/pkgs/cret")))
(let [verts (array 6 f32)]
(set (at verts 0) -1.0) (set (at verts 1) 2.0) (set (at verts 2) -3.0)
(set (at verts 3) 4.0) (set (at verts 4) -5.0) (set (at verts 5) 6.0)
(let [mesh (rl/Mesh {.vertex-count 2 .vertices (addr (at verts 0))})
model (rl/Model {.transform (rl/Matrix {.m-0 1.0 .m-5 1.0 .m-10 1.0 .m-15 1.0
.m-12 10.0 .m-13 20.0 .m-14 30.0})
.mesh-count 1
.meshes (addr mesh)})]
(show-box (rl/get-mesh-bounding-box mesh))
(show-box (rl/get-model-bounding-box model))))
0)