aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/03-font-render.lisp
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-06-27 09:56:09 -0500
committerColin Okay <colin@cicadas.surf>2022-06-27 09:56:09 -0500
commitbb1baae5c6c9ba1f1bba26696920e272df6bee85 (patch)
treed4e4b8350733c5a65e7c6c7959b982ded19a9f7a /examples/03-font-render.lisp
parentdb7cc6c47dd9153ed3fc1bdecea7dde33ea9873e (diff)
[add] text and font classes; [modify] get-asset to pass more args
Diffstat (limited to 'examples/03-font-render.lisp')
-rw-r--r--examples/03-font-render.lisp83
1 files changed, 31 insertions, 52 deletions
diff --git a/examples/03-font-render.lisp b/examples/03-font-render.lisp
index f26f0d0..6e1637a 100644
--- a/examples/03-font-render.lisp
+++ b/examples/03-font-render.lisp
@@ -1,58 +1,37 @@
-(defun make-shader ()
- (wheelwork::create-shader
- '(:vertex
- ((vert :vec2) (col :vec2))
- ()
- ((values
- (vari:vec4
- (* 0.008 vert) 0.0 1.0)
- col)))
- '(:fragment
- ((tc :vec2))
- ((tex :sampler-2d))
- ((* (vari:vec4 1.0 1.0 1.0 1.0) (aref (vari:texture tex tc) 0))))))
+(defpackage #:ww.example/3
+ (:use :cl))
+
+(in-package #:ww.example/3)
+
+
+(defclass font-display (ww::application) ())
+
+(defmethod ww::boot ((app font-display))
+ (let ((hello
+ (make-instance
+ 'ww::text
+ :content "Hell! Oh World..."
+ :font (ww::get-asset "Ticketing.ttf" :asset-args '(:oversample 2)))))
+
+ (setf (ww::unit-width hello)
+ (* 5 (ww::unit-width hello))
+
+ (ww::unit-height hello)
+ (* 5 (ww::unit-height hello))
+
+ (ww::unit-x hello) 100
+
+ (ww::unit-y hello) 100)
+
+ (ww::add-unit app hello)))
+
(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"~/projects/INACTIVE/wwb-haxe/Assets/Ticketing.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.0 0.0 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))))))))
+ (ww::start (make-instance 'font-display
+ :title "Wheelwork Example: Font display"
+ :asset-root "~/projects/wheelwork/examples/")))
+