core-2d-camera, core-scissor-test, core-window-flags, core-world-screen
and core-window-should-close, ported from raylib 5.5's examples/core.
What each one asked of vendor/raylib:
2d-camera nothing. A whole Camera2D by value, per frame, into the
call that actually draws with it — the layout the
acceptance table pins through arithmetic, now going
through the path it was bound for.
scissor-test begin-scissor-mode / end-scissor-mode, hand-written.
window-flags twelve more ConfigFlags constants; raylib.flan carried
the four sand.flan sets and this reads eleven.
world-screen the 3D surface did not exist: no Vector3, no Camera3D,
and the importer refused every 3D function in raylib.h
by name for want of them. Two defstructs, two defenums,
begin/end-mode-3d, update-camera, get-world-to-screen,
draw-cube, draw-cube-wires, draw-grid — and 24 more 3D
lines the importer can generate now that the types are
described.
window-should-close set-exit-key, and Key/null to pass it.
The hand-written/generated line, written down in vendor/raylib/bindings:
a drawing pair inside a frame is hand-written, and so is anything whose
Flan face is not the C signature — set-exit-key takes a Key, update-camera
takes a (Ptr Camera3D) and a CameraMode. The window-state family and
get-mouse-x/y stay generated: plain scalars in and bool out, with nothing
for a hand-written line to add.
Camera3D's projection field stays i32, because the header says int and the
layout check holds this file to that; rl/camera-projection is the
conversion, and still takes a keyword.
73 lines
3.0 KiB
Plaintext
73 lines
3.0 KiB
Plaintext
;;;; raylib [core] example - scissor test
|
|
;;;;
|
|
;;;; examples/core/core_scissor_test.c. Needed begin-scissor-mode and
|
|
;;;; end-scissor-mode, now hand-written in vendor/raylib/raylib.flan: they are
|
|
;;;; a begin/end pair inside a frame, which is the class PORTING.md §1 says
|
|
;;;; belongs in the hand-written half and not in the importer's. get-mouse-x
|
|
;;;; and get-mouse-y come from the generated half — their Flan face is the C
|
|
;;;; one, two plain i32s, and there is nothing for a hand-written line to say
|
|
;;;; about them that the header does not already say.
|
|
;;;;
|
|
;;;; The scissor rectangle is a Rectangle of floats in the C and stays one
|
|
;;;; here, even though every use of it casts back to i32, because the one call
|
|
;;;; that takes it whole — draw-rectangle-lines-ex — wants a Rectangle. That
|
|
;;;; is also why the mouse is read through get-mouse-x/get-mouse-y rather than
|
|
;;;; get-mouse-position: the C does the arithmetic in floats from integer
|
|
;;;; readings, and doing it the other way round would round differently on the
|
|
;;;; odd pixel.
|
|
;;;;
|
|
;;;; What this example is really a test of, and what no headless case could
|
|
;;;; be: raylib's scissor rectangle is in screen pixels with y growing DOWN,
|
|
;;;; and the GL call underneath measures from the bottom. raylib flips it. If
|
|
;;;; the binding or the flip were wrong the clip would appear mirrored about
|
|
;;;; the middle of the window — a perfectly plausible picture, in the wrong
|
|
;;;; place — so the only check is the outline drawn around it afterwards
|
|
;;;; landing on the revealed patch.
|
|
|
|
(import rl "vendor:raylib")
|
|
|
|
(defconst screen-width 800)
|
|
(defconst screen-height 450)
|
|
|
|
(defvar scissor rl/Rectangle)
|
|
(defvar scissor-mode bool)
|
|
|
|
(defn main [] ()
|
|
(rl/init-window screen-width screen-height
|
|
"raylib [core] example - scissor test")
|
|
(defer (rl/close-window))
|
|
|
|
(set scissor (rl/Rectangle {.x 0.0 .y 0.0 .width 300.0 .height 300.0}))
|
|
(set scissor-mode true)
|
|
|
|
(rl/set-target-fps 60)
|
|
|
|
(until (rl/window-should-close?)
|
|
;; Update
|
|
(when (rl/key-pressed? :s) (set scissor-mode (not scissor-mode)))
|
|
|
|
;; Centre the scissor area on the mouse.
|
|
(set (.x scissor) (- (f32 (rl/get-mouse-x)) (/ (.width scissor) 2.0)))
|
|
(set (.y scissor) (- (f32 (rl/get-mouse-y)) (/ (.height scissor) 2.0)))
|
|
|
|
;; Draw
|
|
(rl/begin-drawing)
|
|
(rl/clear-background rl/raywhite)
|
|
|
|
(when scissor-mode
|
|
(rl/begin-scissor-mode (i32 (.x scissor)) (i32 (.y scissor))
|
|
(i32 (.width scissor)) (i32 (.height scissor))))
|
|
|
|
;; A full-screen rectangle and a line of text. Only the part inside the
|
|
;; scissor rectangle reaches the framebuffer, which is the whole example.
|
|
(rl/draw-rectangle 0 0 (rl/get-screen-width) (rl/get-screen-height) rl/red)
|
|
(rl/draw-text "Move the mouse around to reveal this text!" 190 200 20
|
|
rl/lightgray)
|
|
|
|
(when scissor-mode (rl/end-scissor-mode))
|
|
|
|
(rl/draw-rectangle-lines-ex scissor 1.0 rl/black)
|
|
(rl/draw-text "Press S to toggle scissor test" 10 10 20 rl/black)
|
|
|
|
(rl/end-drawing)))
|