1 ; Copyright 2022 Frank Duncan (frank@consxy.com) under AGPL3. See distributed LICENSE.txt.
2 (in-package #:clnl-gltk)
9 ; This is a small hack for resource loading. It will do until number of resources grows
13 "resources/clnl-gltk/font.dat"
14 (asdf:system-relative-pathname 'clnl-gltk "resources/clnl-gltk/font.dat")
15 (asdf:system-relative-pathname 'clnl-gltk "../../resources/clnl-gltk/font.dat")))
18 (find-if (lambda (loc) (probe-file loc)) font-locs)
19 (error "Couldn't find font location!"))))
21 (str font-loc :element-type 'unsigned-byte)
23 ((seq (make-sequence 'vector (/ (* 4 (file-length str)) 3))))
26 :for r := (read-byte str nil)
27 :for g := (read-byte str nil)
28 :for b := (read-byte str nil)
32 (setf (aref seq (* idx 4)) r)
33 (setf (aref seq (+ (* idx 4) 1)) r)
34 (setf (aref seq (+ (* idx 4) 2)) r)
35 (setf (aref seq (+ (* idx 4) 3)) r)))
38 (defvar *font-width* 7
51 The width of the font used by CLNL-GLTK.
53 This can be used to calculate appropriate sizes of things
54 that may have fonts displayed in them.")
56 (defvar *font-height* 14
69 The height of the font used by CLNL-GLTK.
71 This can be used to calculate appropriate sizes of things
72 that may have fonts displayed in them.")
74 (defun font-print (str)
75 "FONT-PRINT STR => RESULT
79 STR: a string to be printed to screen
84 FONT-PRINT prints STR to the screen.
86 It affirms no assumptions that are required for it to run, in the
87 interest of speed. Those assumptions include that an opengl window
88 has been opened, that all matrices are correct, and that SETUP-FONT
93 (font-print #P\"Hello World\" t) => nil"
94 (gl:enable :texture-2d)
95 (gl:bind-texture :texture-2d *texture*)
97 (gl:call-lists (map 'vector (lambda (c) (- (char-code c) 32)) str))
98 (gl:disable :texture-2d))
101 (setf *texture* (first (gl:gen-textures 1)))
102 (gl:bind-texture :texture-2d *texture*)
103 (gl:tex-parameter :texture-2d :texture-mag-filter :linear)
104 (gl:tex-parameter :texture-2d :texture-min-filter :linear)
105 (gl:tex-image-2d :texture-2d 0 :rgba8 (* *font-width* 224) *font-height* 0 :rgba :unsigned-byte *font-data*)
106 (setf *base* (gl:gen-lists 224))
108 (gl:with-new-list ((+ *base* l) :compile)
110 (gl:tex-coord (/ l 224d0) 1d0)
112 (gl:tex-coord (/ (1+ l) 224d0) 1d0)
113 (gl:vertex *font-width* 0)
114 (gl:tex-coord (/ (1+ l) 224d0) 0d0)
115 (gl:vertex *font-width* *font-height*)
116 (gl:tex-coord (/ l 224d0) 0d0)
117 (gl:vertex 0 *font-height*)
119 (gl:translate *font-width* 0 0))))