2 (defpackage :glrepl-tests
3 (:use
:cl
:iterate
:glrepl
:alexandria
))
5 (in-package :glrepl-tests
)
7 (defparameter *win-height
* 768)
8 (defparameter *win-width
* 1024)
11 (defparameter *texture-width
* (/ 2.0 80.0))
12 (defparameter *texture-height
* (/ 2.0 25.0))
14 (defvar *esc-pressed
* nil
)
16 (cffi:defcallback key-callback
:void
((key :int
) (action :int
))
17 (when (= action glfw
:+press
+)
18 (format t
"Keypress ~A " key
)
20 ((= key glfw
:+key-esc
+) (setf *esc-pressed
* t
)))))
22 (cffi:defcallback window-size-callback
:void
((width :int
) (height :int
))
23 (setf *win-width
* width
)
24 (setf *win-height
* height
)
25 (gl:viewport
0 0 *win-width
* *win-height
*))
29 ;; Disable stuff that's likely to slow down glRenderPixels.
30 ;; (Omit as much of this as possible, when you know in advance
31 ;; that the OpenGL state will already be set correctly.)
32 (gl:enable gl
:+texture-2d
+)
33 (gl:matrix-mode gl
:+projection
+)
36 (gl:matrix-mode gl
:+modelview
+)
39 (gl:viewport
0 0 *win-width
* *win-height
*))
44 (defun callback-set ()
45 (setf *esc-pressed
* nil
)
46 (glfw:set-key-callback
(cffi:callback key-callback
)))
48 (defun callback-clear ()
49 (glfw:set-key-callback
(cffi:null-pointer
)))
51 (defun render-char (c x y
)
52 (when (graphic-char-p c
)
53 (let ((image (aref *font-images
* (char-code c
))))
54 (when (typep image
'rgba-image
)
56 (gl:bind-texture gl
:+texture-2d
+
57 (cffi::mem-ref
(name-of image
) :uint32
))
58 (gl:tex-env-f gl
:+texture-env
+ gl
:+texture-env-mode
+ gl
:+decal
+)
59 (gl:color-4f
0.0 0.0 0.0 1.0)
60 (gl:enable gl
:+texture-2d
+)
61 (gl:enable gl
:+blend
+)
62 (gl:blend-func gl
:+src-alpha
+ gl
:+one-minus-src-alpha
+)
63 (gl:with-begin gl
:+quads
+
65 (gl:vertex-2f x y
) ;; top lhs
67 (gl:vertex-2f
(+ x
*texture-width
*) y
) ;; top rhs
69 (gl:vertex-2f
(+ x
*texture-width
*) (+ y
*texture-height
*)) ;; bot rhs
71 (gl:vertex-2f x
(+ y
*texture-height
*)))))))) ;; bot lhs
74 (defun render-world ()
75 ;; (glrepl::render (aref *font-images* 65)))
76 (render-char #\A
0.5 0.5))
78 (defun update-world (dt))
81 (let ((t0 (glfw:get-time
))
83 (test-image (make-instance 'glrepl
::rgba-image
:width
64 :height
64)))
85 (for i from
0 below
(* 64 64))
86 (setf (glrepl::pixel test-image i
) #X000000FF
))
87 (glrepl::update-image test-image
)
89 (gl:clear-color
0.0 0.0 0.0 1.0)
91 (while (= (glfw::get-window-param glfw
:+opened
+) glfw
:+true
+))
92 (gl:clear gl
:+color-buffer-bit
+)
93 (setf dt
(- (glfw:get-time
) t0
))
94 (setf t0
(glfw:get-time
))
97 ;;(glrepl::render test-image)
99 ;; check for time available if time is avaliable render
100 ;; surrender any cpu time..
103 (glfw:close-window
)))))
105 (defun test-glrepl ()
109 (if (glfw:open-window
*win-width
* *win-height
* 16 16 16 16 16)
112 (format t
"Making font..")
115 (glfw:swap-interval
1)
116 (glfw:enable glfw
:+key-repeat
+)
118 ;; (glrepl::dump (aref *font-images* 65))
123 (error "Failed to open window"))
126 (format T
"Boom ~A " ohbum
)
130 (error "Failed to init glfw")))
132 ;; (defun test-glrepl ()
133 ;; (glfw:with-init-window ("Glrepl" *win-width* *win-height*)
134 ;; (glfw:set-window-size-callback (cffi:callback window-size-callback))
135 ;; (glfw:set-key-callback (cffi:callback key-callback))
136 ;; (glfw:swap-interval 1)
139 ;; (while (and (not *esc-pressed*)
140 ;; (eql (glfw:get-window-param glfw:+opened+) gl:+true+)))
141 ;; (gl:clear gl:+color-buffer-bit+)
143 ;; (glfw:swap-buffers)
145 ;; (if (eql (glfw:get-window-param glfw:+opened+) gl:+true+)
146 ;; (glfw:close-window))
147 ;; (glfw:terminate))))