diff options
author | Colin Okay <colin@cicadas.surf> | 2022-06-27 08:07:35 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-06-27 08:07:35 -0500 |
commit | 19bbadb810017821f34fa3d186708b7969e43132 (patch) | |
tree | 211cec5d052609658c9f4da737a491625f7dc52d | |
parent | 05ee2bdfd476271d3df1bb8c6aea4abbd09f4d30 (diff) |
[example] working font example with fond!!
-rw-r--r-- | examples/03-font-render.lisp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/examples/03-font-render.lisp b/examples/03-font-render.lisp new file mode 100644 index 0000000..c73db4d --- /dev/null +++ b/examples/03-font-render.lisp @@ -0,0 +1,60 @@ + +(defun make-shader () + (wheelwork::create-shader + '(:vertex + ((vert :vec2) (col :vec2)) + () + ( + (let ((extent (vari:vec4 1.0))) + (values + (vari:vec4 + (* 0.01 vert) 0.0 1.0) + col)))) + '(:fragment + ((tc :vec2)) + ((tex :sampler-2d)) + ((+ (vari:vec4 0.0 1.0 1.0 1.0) (vari:texture tex tc)))))) + +(defun start () + (sdl2:with-init (:everything) + (sdl2:gl-set-attr :context-major-version 3) + (sdl2:gl-set-attr :context-minor-version 3) + (sdl2:gl-set-attr :context-profile-mask + sdl2-ffi:+sdl-gl-context-profile-core+) + (sdl2:gl-set-attr :doublebuffer 1) + (sdl2:with-window (window + :flags '(:shown :opengl) + :title "Font Example") + (sdl2:with-gl-context (ctx window) + (sdl2:gl-make-current window ctx) + (gl:viewport 0 0 800 800) + (gl:enable :depth-test) + (let* ((font + (cl-fond:make-font + #P"~/sites/hyperthings.garden/css/fonts/LibreCaslonDisplay-Regular.ttf" + "ABCDEFGHJIJKLMNOPQRSTUVWXYZabcdefhgjijklmnopqrstuvwxyz0123456789 ,.!?:;-+/\\")) + (shader + (make-shader))) + (gl:program-uniformi shader (gl:get-uniform-location shader "TEX") 0) + (multiple-value-bind (vao elems) (cl-fond:compute-text font "Hey Man") + (print (list :vao vao :elems elems)) + (sdl2:with-event-loop (:method :poll) + (:idle () + (gl:clear-color 0.0 0.5 0.5 1.0) + (gl:clear :depth-buffer-bit :color-buffer-bit) + (gl:use-program shader) + (gl:active-texture 0) + (gl:bind-texture :texture-2d (cl-fond:texture font)) + (gl:bind-vertex-array vao) + (%gl:draw-elements :triangles + elems + :unsigned-int 0) + (gl:bind-vertex-array 0) + (sdl2:gl-swap-window window) + (setf got-here t)) + (:quit () + (gl:delete-vertex-arrays (list vao)) + t)))))))) + + + |