Removed unused functions
[cl-glfw.git] / lib / glfw.lisp
blob5b22c1aedf4a6dfa12c8386fb51de9dd5a961477
1 (in-package #:cl-glfw)
3 (defconstant +false+ 0)
4 (defconstant +true+ 1)
6 (defmacro defcfun+doc ((c-name lisp-name) return-type (&body args) docstring)
7 `(progn
8 (defcfun (,c-name ,lisp-name) ,return-type ,@args)
9 (setf (documentation #',lisp-name 'function) ,docstring)))
11 (defmacro defcfun+out+doc ((c-name lisp-name) return-type (&body args) docstring)
12 (let ((internal-name (intern (format nil "%~a" lisp-name)))
13 (in-arg-names (mapcar #'second (remove-if-not #'(lambda (arg)
14 (eql (car arg) :in))
15 args)))
16 (out-args (mapcar #'cdr (remove-if-not #'(lambda (arg)
17 (eql (car arg) :out))
18 args))))
19 `(progn
20 (defcfun (,c-name ,internal-name) ,return-type
21 ,@(mapcar #'(lambda (arg)
22 (if (eql (car arg) :out)
23 (list (second arg) :pointer)
24 (cdr arg)))
25 args))
26 (defun ,lisp-name ,in-arg-names
27 ,docstring
28 (with-foreign-objects ,out-args
29 (,internal-name ,@(mapcar #'second args))
30 (list ,@(mapcar #'(lambda (arg)
31 `(mem-ref ,(first arg) ',(second arg)))
32 out-args)))))))
34 ;; ECL's DFFI seems to have issues if you don't put the full path in
35 #+(and unix ecl)
36 (setf cffi:*foreign-library-directories*
37 (list "/usr/local/lib/" "/usr/lib/"))
39 (cffi:load-foreign-library '(:or
40 #+darwin (:framework "GLFW")
41 (:default "glfw")
42 (:default "libglfw")))
44 ;; Key and button state/action definitions
45 (defconstant +release+ 0)
46 (defconstant +press+ 1)
48 ;; Keyboard key definitions: 8-bit ISO-8859-1 (Latin 1) encoding is used
49 ;; for printable keys (such as A-Z, 0-9 etc), and values above 256
50 ;; represent special (non-printable) keys (e.g. F1, Page Up etc).
51 (defconstant +key-unknown+ -1)
52 (defconstant +key-space+ 32)
53 (defconstant +key-special+ 256)
54 (defconstant +key-esc+ (+ +key-special+ 1))
55 (defconstant +key-f1+ (+ +key-special+ 2))
56 (defconstant +key-f2+ (+ +key-special+ 3))
57 (defconstant +key-f3+ (+ +key-special+ 4))
58 (defconstant +key-f4+ (+ +key-special+ 5))
59 (defconstant +key-f5+ (+ +key-special+ 6))
60 (defconstant +key-f6+ (+ +key-special+ 7))
61 (defconstant +key-f7+ (+ +key-special+ 8))
62 (defconstant +key-f8+ (+ +key-special+ 9))
63 (defconstant +key-f9+ (+ +key-special+ 10))
64 (defconstant +key-f10+ (+ +key-special+ 11))
65 (defconstant +key-f11+ (+ +key-special+ 12))
66 (defconstant +key-f12+ (+ +key-special+ 13))
67 (defconstant +key-f13+ (+ +key-special+ 14))
68 (defconstant +key-f14+ (+ +key-special+ 15))
69 (defconstant +key-f15+ (+ +key-special+ 16))
70 (defconstant +key-f16+ (+ +key-special+ 17))
71 (defconstant +key-f17+ (+ +key-special+ 18))
72 (defconstant +key-f18+ (+ +key-special+ 19))
73 (defconstant +key-f19+ (+ +key-special+ 20))
74 (defconstant +key-f20+ (+ +key-special+ 21))
75 (defconstant +key-f21+ (+ +key-special+ 22))
76 (defconstant +key-f22+ (+ +key-special+ 23))
77 (defconstant +key-f23+ (+ +key-special+ 24))
78 (defconstant +key-f24+ (+ +key-special+ 25))
79 (defconstant +key-f25+ (+ +key-special+ 26))
80 (defconstant +key-up+ (+ +key-special+ 27))
81 (defconstant +key-down+ (+ +key-special+ 28))
82 (defconstant +key-left+ (+ +key-special+ 29))
83 (defconstant +key-right+ (+ +key-special+ 30))
84 (defconstant +key-lshift+ (+ +key-special+ 31))
85 (defconstant +key-rshift+ (+ +key-special+ 32))
86 (defconstant +key-lctrl+ (+ +key-special+ 33))
87 (defconstant +key-rctrl+ (+ +key-special+ 34))
88 (defconstant +key-lalt+ (+ +key-special+ 35))
89 (defconstant +key-ralt+ (+ +key-special+ 36))
90 (defconstant +key-tab+ (+ +key-special+ 37))
91 (defconstant +key-enter+ (+ +key-special+ 38))
92 (defconstant +key-backspace+ (+ +key-special+ 39))
93 (defconstant +key-insert+ (+ +key-special+ 40))
94 (defconstant +key-del+ (+ +key-special+ 41))
95 (defconstant +key-pageup+ (+ +key-special+ 42))
96 (defconstant +key-pagedown+ (+ +key-special+ 43))
97 (defconstant +key-home+ (+ +key-special+ 44))
98 (defconstant +key-end+ (+ +key-special+ 45))
99 (defconstant +key-kp-0+ (+ +key-special+ 46))
100 (defconstant +key-kp-1+ (+ +key-special+ 47))
101 (defconstant +key-kp-2+ (+ +key-special+ 48))
102 (defconstant +key-kp-3+ (+ +key-special+ 49))
103 (defconstant +key-kp-4+ (+ +key-special+ 50))
104 (defconstant +key-kp-5+ (+ +key-special+ 51))
105 (defconstant +key-kp-6+ (+ +key-special+ 52))
106 (defconstant +key-kp-7+ (+ +key-special+ 53))
107 (defconstant +key-kp-8+ (+ +key-special+ 54))
108 (defconstant +key-kp-9+ (+ +key-special+ 55))
109 (defconstant +key-kp-divide+ (+ +key-special+ 56))
110 (defconstant +key-kp-multiply+ (+ +key-special+ 57))
111 (defconstant +key-kp-subtract+ (+ +key-special+ 58))
112 (defconstant +key-kp-add+ (+ +key-special+ 59))
113 (defconstant +key-kp-decimal+ (+ +key-special+ 60))
114 (defconstant +key-kp-equal+ (+ +key-special+ 61))
115 (defconstant +key-kp-enter+ (+ +key-special+ 62))
116 (defconstant +key-last+ +key-kp-enter+)
118 ;; Mouse button definitions
119 (defconstant +mouse-button-1+ 0)
120 (defconstant +mouse-button-2+ 1)
121 (defconstant +mouse-button-3+ 2)
122 (defconstant +mouse-button-4+ 3)
123 (defconstant +mouse-button-5+ 4)
124 (defconstant +mouse-button-6+ 5)
125 (defconstant +mouse-button-7+ 6)
126 (defconstant +mouse-button-8+ 7)
127 (defconstant +mouse-button-last+ +mouse-button-8+)
129 ;; Mouse button aliases
130 (defconstant +mouse-button-left+ +mouse-button-1+)
131 (defconstant +mouse-button-right+ +mouse-button-2+)
132 (defconstant +mouse-button-middle+ +mouse-button-3+)
134 ;; Joystick identifiers
135 (defconstant +joystick-1+ 0)
136 (defconstant +joystick-2+ 1)
137 (defconstant +joystick-3+ 2)
138 (defconstant +joystick-4+ 3)
139 (defconstant +joystick-5+ 4)
140 (defconstant +joystick-6+ 5)
141 (defconstant +joystick-7+ 6)
142 (defconstant +joystick-8+ 7)
143 (defconstant +joystick-9+ 8)
144 (defconstant +joystick-10+ 9)
145 (defconstant +joystick-11+ 10)
146 (defconstant +joystick-12+ 11)
147 (defconstant +joystick-13+ 12)
148 (defconstant +joystick-14+ 13)
149 (defconstant +joystick-15+ 14)
150 (defconstant +joystick-16+ 15)
151 (defconstant +joystick-last+ +joystick-16+)
154 ;;========================================================================
155 ;; Other definitions
156 ;;========================================================================
158 ;; glfwOpenWindow modes
159 (defconstant +window+ #x00010001)
160 (defconstant +fullscreen+ #x00010002)
162 ;; glfwGetWindowParam tokens
163 (defconstant +opened+ #x00020001)
164 (defconstant +active+ #x00020002)
165 (defconstant +iconified+ #x00020003)
166 (defconstant +accelerated+ #x00020004)
167 (defconstant +red-bits+ #x00020005)
168 (defconstant +green-bits+ #x00020006)
169 (defconstant +blue-bits+ #x00020007)
170 (defconstant +alpha-bits+ #x00020008)
171 (defconstant +depth-bits+ #x00020009)
172 (defconstant +stencil-bits+ #x0002000a)
174 ;; The following constants are used for both glfwGetWindowParam
175 ;; and glfwOpenWindowHint
176 (defconstant +refresh-rate+ #x0002000b)
177 (defconstant +accum-red-bits+ #x0002000c)
178 (defconstant +accum-green-bits+ #x0002000d)
179 (defconstant +accum-blue-bits+ #x0002000e)
180 (defconstant +accum-alpha-bits+ #x0002000f)
181 (defconstant +aux-buffers+ #x00020010)
182 (defconstant +stereo+ #x00020011)
183 (defconstant +window-no-resize+ #x00020012)
184 (defconstant +fsaa-samples+ #x00020013)
186 ;; glfwEnable/glfwDisable tokens
187 (defconstant +mouse-cursor+ #x00030001)
188 (defconstant +sticky-keys+ #x00030002)
189 (defconstant +sticky-mouse-buttons+ #x00030003)
190 (defconstant +system-keys+ #x00030004)
191 (defconstant +key-repeat+ #x00030005)
192 (defconstant +auto-poll-events+ #x00030006)
194 ;; glfwWaitThread wait modes
195 (defconstant +wait+ #x00040001)
196 (defconstant +nowait+ #x00040002)
198 ;; glfwGetJoystickParam tokens
199 (defconstant +present+ #x00050001)
200 (defconstant +axes+ #x00050002)
201 (defconstant +buttons+ #x00050003)
203 ;; glfwReadImage/glfwLoadTexture2D flags
204 (defconstant +no-rescale-bit+ #x00000001) ; Only for glfwReadImage
205 (defconstant +origin-ul-bit+ #x00000002)
206 (defconstant +build-mipmaps-bit+ #x00000004) ; Only for glfwLoadTexture2D
207 (defconstant +alpha-map-bit+ #x00000008)
209 ;; Time spans longer than this (seconds) are considered to be infinity
210 (defconstant +infinity+ 100000d0)
212 (defcfun+doc ("glfwInit" init) boolean ()
213 "Return values
214 If the function succeeds, t is returned.
215 If the function fails, nil is returned.
217 The glfwInit function initializes GLFW. No other GLFW functions may be used before this function
218 has been called.
220 Notes
221 This function may take several seconds to complete on some systems, while on other systems it may
222 take only a fraction of a second to complete.")
224 (defcfun+doc ("glfwTerminate" terminate) :void ()
225 "The function terminates GLFW. Among other things it closes the window, if it is opened, and kills any
226 running threads. This function must be called before a program exits.")
228 (defcfun+out+doc ("glfwGetVersion" get-version) :void ((:out major :int)
229 (:out minor :int)
230 (:out rev :int))
231 "Return values
232 The function returns the major and minor version numbers and the revision for the currently linked
233 GLFW library as a list (major minor rev).")
235 (defmacro with-init (&body forms)
236 "Call glfw:init, execute forms and clean-up with glfw:terminate once finished.
237 This makes a nice wrapper to an application higher-level form.
238 Signals an error on failure to initialize. Wrapped in a block named glfw:with-init."
239 `(if (glfw:init)
240 (unwind-protect
241 (block with-init ,@forms)
242 (glfw:terminate))
243 (error "Error initializing glfw.")))
245 (defcfun ("glfwOpenWindow" %open-window) boolean
246 (width :int) (height :int)
247 (redbits :int) (greenbits :int) (bluebits :int) (alphabits :int)
248 (depthbits :int) (stencilbits :int) (mode :int))
250 (declaim (inline open-window))
251 (defun open-window (&optional (width 0) (height 0)
252 (redbits 0) (greenbits 0) (bluebits 0) (alphabits 0)
253 (depthbits 0) (stencilbits 0) (mode +window+))
254 "width
255 The width of the window. If width is zero, it will be calculated as width = 4/3 height, if height is
256 not zero. If both width and height are zero, then width will be set to 640.
257 height
258 The height of the window. If height is zero, it will be calculated as height = 3/4 width, if width is
259 not zero. If both width and height are zero, then height will be set to 480.
260 redbits, greenbits, bluebits
261 The number of bits to use for each color component of the color buffer (0 means default color
262 depth). For instance, setting redbits=5, greenbits=6, and bluebits=5 will generate a 16-bit color
263 buffer, if possible.
264 alphabits
265 The number of bits to use for the alpha buffer (0 means no alpha buffer).
266 depthbits
267 The number of bits to use for the depth buffer (0 means no depth buffer).
268 stencilbits
269 The number of bits to use for the stencil buffer (0 means no stencil buffer).
270 mode
271 Selects which type of OpenGL™ window to use. mode can be either GLFW_WINDOW, which
272 will generate a normal desktop window, or GLFW_FULLSCREEN, which will generate a
273 window which covers the entire screen. When GLFW_FULLSCREEN is selected, the video
274 mode will be changed to the resolution that closest matches the width and height parameters.
276 Return values
277 If the function succeeds, t is returned.
278 If the function fails, nil is returned.
280 Description
281 The function opens a window that best matches the parameters given to the function. How well the
282 resulting window matches the desired window depends mostly on the available hardware and
283 OpenGL™ drivers. In general, selecting a fullscreen mode has better chances of generating a close
284 match than does a normal desktop window, since GLFW can freely select from all the available video
285 modes. A desktop window is normally restricted to the video mode of the desktop.
287 Notes
288 For additional control of window properties, see glfwOpenWindowHint.
289 In fullscreen mode the mouse cursor is hidden by default, and any system screensavers are prohibited
290 from starting. In windowed mode the mouse cursor is visible, and screensavers are allowed to start. To
291 change the visibility of the mouse cursor, use glfwEnable or glfwDisable with the argument
292 GLFW_MOUSE-CURSOR.
293 In order to determine the actual properties of an opened window, use glfwGetWindowParam and
294 glfwGetWindowSize (or glfwSetWindowSizeCallback).
296 (%open-window width height redbits greenbits bluebits alphabits depthbits stencilbits mode))
299 (defcfun+doc ("glfwOpenWindowHint" open-window-hint) :void ((target :int) (hint :int))
300 "target
301 Can be any of the constants in the table 3.1.
302 hint
303 An integer giving the value of the corresponding target (see table 3.1).
305 Description
306 The function sets additional properties for a window that is to be opened. For a hint to be registered, the
307 function must be called before calling glfwOpenWindow. When the glfwOpenWindow function is
308 called, any hints that were registered with the glfwOpenWindowHint function are used for setting the
309 corresponding window properties, and then all hints are reset to their default values.
311 Notes
312 In order to determine the actual properties of an opened window, use glfwGetWindowParam (after the
313 window has been opened).
314 GLFW_STEREO is a hard constraint. If stereo rendering is requested, but no stereo rendering capable
315 pixel formats / visuals are available, glfwOpenWindow will fail.
316 The GLFW_REFRESH-RATE property should be used with caution. Most systems have default values
317 for monitor refresh rates that are optimal for the specific system. Specifying the refresh rate can
318 override these settings, which can result in suboptimal operation. The monitor may be unable to display
319 the resulting video signal, or in the worst case it may even be damaged!
322 (defcfun+doc ("glfwCloseWindow" close-window) :void ()
323 "The function closes an opened window and destroys the associated OpenGL™ context.")
325 (defmacro with-open-window ((&optional (title "cl-glfw window") (width 0) (height 0)
326 (redbits 0) (greenbits 0) (bluebits 0) (alphabits 0)
327 (depthbits 0) (stencilbits 0) (mode +window+))
328 &body forms)
329 "Wraps forms such that there is an open window for them to execute in and cleans up the
330 window afterwards. An error is signalled if there was an error opening the window.
331 Takes the same parameters as open-window, with the addition of 'title' which will
332 set the window title after opening.
333 Wrapped in a block named glfw:with-open-window."
334 `(if (%open-window ,width ,height ,redbits ,greenbits ,bluebits ,alphabits ,depthbits ,stencilbits ,mode)
335 (unwind-protect
336 (block with-open-window
337 (glfw:set-window-title ,title)
338 ,@forms)
339 (when (= +true+ (glfw:get-window-param glfw:+opened+))
340 (close-window)))
341 (error "Error initializing glfw window.")))
343 (defmacro with-init-window ((&optional (title "cl-glfw window") (width 0) (height 0)
344 (redbits 0) (greenbits 0) (bluebits 0) (alphabits 0)
345 (depthbits 0) (stencilbits 0) (mode +window+))
346 &body forms)
347 "Wraps forms in with-init, with-open-window. Passes through the other arguments to open-window."
348 `(with-init
349 (with-open-window (,title ,width ,height ,redbits ,greenbits ,bluebits ,alphabits ,depthbits ,stencilbits ,mode)
350 ,@forms)))
352 (defmacro do-window ((&optional (title "cl-glfw window") (width 0) (height 0)
353 (redbits 0) (greenbits 0) (bluebits 0) (alphabits 0)
354 (depthbits 0) (stencilbits 0) (mode +window+))
355 (&body setup-forms)
356 &body forms)
357 "High-level convenience macro for initializing glfw, opening a window (given the optional window parameters),
358 setting the title given,
359 running setup-forms and then running forms in a loop, with calls to swap-buffers after each loop iteration.
360 The loop is in a block named do-window [so can be exited by a call to (return-from glfw:do-window)].
361 If the window is closed, the loop is also exited."
362 `(with-init-window (,title ,width ,height ,redbits ,greenbits ,bluebits ,alphabits ,depthbits ,stencilbits ,mode)
363 ,@setup-forms
364 (loop named do-window do
365 ,@forms
366 (glfw:swap-buffers)
367 (unless (= +true+ (glfw:get-window-param glfw:+opened+))
368 (return-from do-window)))))
370 (defcfun+doc ("glfwSetWindowCloseCallback" set-window-close-callback) :void ((cbfun :pointer))
371 "Parameters
372 cbfun
373 Pointer to a callback function that will be called when a user requests that the window should be
374 closed, typically by clicking the window close icon (e.g. the cross in the upper right corner of a
375 window under Microsoft Windows). The function should have the following C language
376 prototype:
377 int GLFWCALL functionname( void );
378 Where functionname is the name of the callback function. The return value of the callback
379 function indicates wether or not the window close action should continue. If the function returns
380 GL_TRUE, the window will be closed. If the function returns GL_FALSE, the window will not
381 be closed.
382 If cbfun is NULL, any previously selected callback function will be deselected.
384 If you declare your callback as returning glfw:boolean, you can use t and nil as return types.
386 Description
387 The function selects which function to be called upon a window close event.
388 A window has to be opened for this function to have any effect.
390 Notes
391 Window close events are recorded continuously, but only reported when glfwPollEvents,
392 glfwWaitEvents or glfwSwapBuffers is called.
393 The OpenGL™ context is still valid when this function is called.
394 Note that the window close callback function is not called when glfwCloseWindow is called, but only
395 when the close request comes from the window manager.
396 Do not call glfwCloseWindow from a window close callback function. Close the window by returning
397 GL_TRUE from the function.
400 (defcfun+doc ("glfwSetWindowTitle" set-window-title) :void ((title :string))
401 "Parameters
402 title
403 Pointer to a null terminated ISO 8859-1 (8-bit Latin 1) string that holds the title of the window.
405 Description
406 The function changes the title of the opened window.
408 Notes
409 The title property of a window is often used in situations other than for the window title, such as the title
410 of an application icon when it is in iconified state.")
412 (defcfun+doc ("glfwSetWindowSize" set-window-size) :void ((width :int) (height :int))
413 "Parameters
414 width
415 Width of the window.
416 height
417 Height of the window.
418 Return values
419 none
420 Description
421 The function changes the size of an opened window. The width and height parameters denote the size of
422 the client area of the window (i.e. excluding any window borders and decorations).
423 If the window is in fullscreen mode, the video mode will be changed to a resolution that closest matches
424 the width and height parameters (the number of color bits will not be changed).
425 Notes
426 The OpenGL™ context is guaranteed to be preserved after calling glfwSetWindowSize, even if the
427 video mode is changed.
430 (defcfun+doc ("glfwSetWindowPos" set-window-pos) :void ((x :int) (y :int))
431 "Parameters
433 Horizontal position of the window, relative to the upper left corner of the desktop.
435 Vertical position of the window, relative to the upper left corner of the desktop.
436 Return values
437 none
438 Description
439 The function changes the position of an opened window. It does not have any effect on a fullscreen
440 window.
443 (defcfun ("glfwGetWindowSize" %get-window-size) :void (width :pointer) (height :pointer))
444 (defun get-window-size ()
445 "The function is used for determining the size of an opened window. The returned values are dimensions
446 of the client area of the window (i.e. excluding any window borders and decorations).
447 (list width height)"
448 (cffi:with-foreign-objects ((width :int)
449 (height :int))
450 (%get-window-size width height)
451 (list (mem-ref width :int)
452 (mem-ref height :int))))
454 (defcfun+doc ("glfwSetWindowSizeCallback" set-window-size-callback) :void ((cbfun :pointer))
455 "Parameters
456 cbfun
457 Pointer to a callback function that will be called every time the window size changes. The
458 function should have the following C language prototype:
459 void GLFWCALL functionname( int width, int height );
460 Where functionname is the name of the callback function, and width and height are the
461 dimensions of the window client area.
462 If cbfun is NULL, any previously selected callback function will be deselected.
463 Return values
464 none
465 Description
466 The function selects which function to be called upon a window size change event.
467 A window has to be opened for this function to have any effect.
468 Notes
469 Window size changes are recorded continuously, but only reported when glfwPollEvents,
470 glfwWaitEvents or glfwSwapBuffers is called. ")
472 (defcfun+doc ("glfwIconifyWindow" iconify-window) :void ()
473 "Iconify a window. If the window is in fullscreen mode, then the desktop video mode will be restored.")
475 (defcfun+doc ("glfwRestoreWindow" restore-window) :void ()
476 "Restore an iconified window. If the window that is restored is in fullscreen mode, then the fullscreen
477 video mode will be restored.")
479 (defcfun+doc ("glfwGetWindowParam" get-window-param) :int ((param :int))
480 "Parameters
481 param
482 A token selecting which parameter the function should return (see table 3.2).
484 Return values
485 The function returns different parameters depending on the value of param. Table 3.2 lists valid param
486 values, and their corresponding return values.
488 Description
489 The function is used for acquiring various properties of an opened window.
491 Notes
492 GLFW_ACCELERATED is only supported under Windows. Other systems will always return
493 GL_TRUE. Under Windows, GLFW_ACCELERATED means that the OpenGL™ renderer is a 3rd
494 party renderer, rather than the fallback Microsoft software OpenGL™ renderer. In other words, it is
495 not a real guarantee that the OpenGL™ renderer is actually hardware accelerated.
498 (defcfun+doc ("glfwSwapBuffers" swap-buffers) :void ()
499 "The function swaps the back and front color buffers of the window. If GLFW_AUTO-POLL-EVENTS
500 is enabled (which is the default), glfwPollEvents is called before swapping the front and back buffers.")
503 (defcfun+doc ("glfwSwapInterval" swap-interval) :void ((interval :int))
504 "Parameters
505 interval
506 Minimum number of monitor vertical retraces between each buffer swap performed by
507 glfwSwapBuffers. If interval is zero, buffer swaps will not be synchronized to the vertical
508 refresh of the monitor (also known as ’VSync off’).
510 Description
511 The function selects the minimum number of monitor vertical retraces that should occur between two
512 buffer swaps. If the selected swap interval is one, the rate of buffer swaps will never be higher than the
513 vertical refresh rate of the monitor. If the selected swap interval is zero, the rate of buffer swaps is only
514 limited by the speed of the software and the hardware.
516 Notes
517 This function will only have an effect on hardware and drivers that support user selection of the swap
518 interval. ")
521 (defcfun+doc ("glfwSetWindowRefreshCallback" set-window-refresh-callback) :void ((cbfun :pointer))
522 "Parameters
523 cbfun
524 Pointer to a callback function that will be called when the window client area needs to be
525 refreshed. The function should have the following C language prototype:
526 void GLFWCALL functionname( void );
527 Where functionname is the name of the callback function.
528 If cbfun is NULL, any previously selected callback function will be deselected.
530 Description
531 The function selects which function to be called upon a window refresh event, which occurs when any
532 part of the window client area has been damaged, and needs to be repainted (for instance, if a part of the
533 window that was previously occluded by another window has become visible).
534 A window has to be opened for this function to have any effect.
536 Notes
537 Window refresh events are recorded continuously, but only reported when glfwPollEvents,
538 glfwWaitEvents or glfwSwapBuffers is called.
541 (defcstruct vidmode
542 (width :int)
543 (height :int)
544 (redbits :int)
545 (bluebits :int)
546 (greenbits :int))
548 (defcfun ("glfwGetVideoModes" %get-video-modes) :int (list :pointer) (maxcount :int))
550 (defun get-video-modes (maxcount)
551 "Parameters
552 maxcount
553 Maximum number of video modes that list vector can hold.
555 Return values
556 The function returns the number of detected video modes (this number will never exceed maxcount).
557 The list vector is filled out with the video modes that are supported by the system.
559 Description
560 The function returns a list of supported video modes. Each video mode is represented by a
561 list of the form:
562 (width height redbits greenbits bluebits)
564 Notes
565 The returned list is sorted, first by color depth (RedBits + GreenBits + BlueBits), and then by
566 resolution (Width × Height), with the lowest resolution, fewest bits per pixel mode first. "
567 (declare (optimize (debug 3)))
568 (with-foreign-object (list 'vidmode maxcount)
569 (let ((count (%get-video-modes list maxcount)))
570 (loop for i below count
571 collecting
572 (let ((mode (cffi:mem-aref list 'vidmode i)))
573 (list (foreign-slot-value mode 'vidmode 'width)
574 (foreign-slot-value mode 'vidmode 'height)
575 (foreign-slot-value mode 'vidmode 'redbits)
576 (foreign-slot-value mode 'vidmode 'greenbits)
577 (foreign-slot-value mode 'vidmode 'bluebits)))))))
579 (defcfun ("glfwGetDesktopMode" %get-desktop-mode) :void (mode :pointer))
580 (defun get-desktop-mode ()
581 "Parameters
582 mode
583 Pointer to a GLFWvidmode structure, which will be filled out by the function.
584 Return values
585 The GLFWvidmode structure pointed to by mode is filled out with the desktop video mode.
586 Description
587 The function returns the desktop video mode in a GLFWvidmode structure. See glfwGetVideoModes
588 for a definition of the GLFWvidmode structure.
589 Notes
590 The color depth of the desktop display is always reported as the number of bits for each individual color
591 component (red, green and blue), even if the desktop is not using an RGB or RGBA color format. For
592 instance, an indexed 256 color display may report RedBits = 3, GreenBits = 3 and BlueBits = 2, which
593 adds up to 8 bits in total.
594 The desktop video mode is the video mode used by the desktop, not the current video mode (which may
595 differ from the desktop video mode if the GLFW window is a fullscreen window).
597 (with-foreign-object (mode 'vidmode)
598 (%get-desktop-mode mode)
599 (list (foreign-slot-value mode 'vidmode 'width)
600 (foreign-slot-value mode 'vidmode 'height)
601 (foreign-slot-value mode 'vidmode 'redbits)
602 (foreign-slot-value mode 'vidmode 'greenbits)
603 (foreign-slot-value mode 'vidmode 'bluebits))))
605 (defcfun+doc ("glfwPollEvents" poll-events) :void ()
606 "Description
607 The function is used for polling for events, such as user input and window resize events. Upon calling
608 this function, all window states, keyboard states and mouse states are updated. If any related callback
609 functions are registered, these are called during the call to glfwPollEvents.
611 Notes
612 glfwPollEvents is called implicitly from glfwSwapBuffers if GLFW_AUTO_POLL_EVENTS is
613 enabled (default). Thus, if glfwSwapBuffers is called frequently, which is normally the case, there is
614 no need to call glfwPollEvents.
617 (defcfun+doc ("glfwWaitEvents" wait-events) :void ()
618 "Description
619 The function is used for waiting for events, such as user input and window resize events. Upon calling
620 this function, the calling thread will be put to sleep until any event appears in the event queue. When
621 events are ready, the events will be processed just as they are processed by glfwPollEvents.
622 If there are any events in the queue when the function is called, the function will behave exactly like
623 glfwPollEvents (i.e. process all messages and then return, without blocking the calling thread).
625 Notes
626 It is guaranteed that glfwWaitEvents will wake up on any event that can be processed by
627 glfwPollEvents. However, glfwWaitEvents may wake up on events that are not processed or reported
628 by glfwPollEvents too, and the function may behave differently on different systems. Do no make any
629 assumptions about when or why glfwWaitEvents will return.
632 (defcfun+doc ("glfwGetKey" get-key) :int ((key :int))
633 "Parameters
635 A keyboard key identifier, which can be either an uppercase printable ISO 8859-1 (Latin 1)
636 character (e.g. 'A', '3' or '.'), or a special key identifier. Table 3.3 lists valid special key
637 identifiers.
638 Return values
639 The function returns GLFW_PRESS if the key is held down, or GLFW_RELEASE if the key is not
640 held down.
642 Description
643 The function queries the current state of a specific keyboard key. The physical location of each key
644 depends on the system keyboard layout setting.
646 Notes
647 The constant GLFW_KEY_SPACE is equal to 32, which is the ISO 8859-1 code for space.
648 Not all key codes are supported on all systems. Also, while some keys are available on some keyboard
649 layouts, they may not be available on other keyboard layouts.
650 For systems that do not distinguish between left and right versions of modifier keys (shift, alt and
651 control), the left version is used (e.g. GLFW_KEY_LSHIFT).
652 A window must be opened for the function to have any effect, and glfwPollEvents, glfwWaitEvents or
653 glfwSwapBuffers must be called before any keyboard events are recorded and reported by
654 glfwGetKey.
657 (defcfun+doc ("glfwGetMouseButton" get-mouse-button) :int ((button :int))
658 "Parameters
659 button
660 A mouse button identifier, which can be one of the mouse button identifiers listed in table 3.4.
661 Return values
662 The function returns GLFW_PRESS if the mouse button is held down, or GLFW_RELEASE if the
663 mouse button is not held down.
664 Description
665 The function queries the current state of a specific mouse button.
666 Notes
667 A window must be opened for the function to have any effect, and glfwPollEvents, glfwWaitEvents or
668 glfwSwapBuffers must be called before any mouse button events are recorded and reported by
669 glfwGetMouseButton.
670 GLFW_MOUSE_BUTTON_LEFT is equal to GLFW_MOUSE_BUTTON_1.
671 GLFW_MOUSE_BUTTON_RIGHT is equal to GLFW_MOUSE_BUTTON_2.
672 GLFW_MOUSE_BUTTON_MIDDLE is equal to GLFW_MOUSE_BUTTON_3.
676 (defcfun+out+doc ("glfwGetMousePos" get-mouse-pos) :void ((:out xpos :int) (:out ypos :int))
677 "Return values
678 The function returns the current mouse position in xpos and ypos.
680 Description
681 The function returns the current mouse position. If the cursor is not hidden, the mouse position is the
682 cursor position, relative to the upper left corner of the window and limited to the client area of the
683 window. If the cursor is hidden, the mouse position is a virtual absolute position, not limited to any
684 boundaries except to those implied by the maximum number that can be represented by a signed integer
685 (normally -2147483648 to +2147483647).
687 Notes
688 A window must be opened for the function to have any effect, and glfwPollEvents, glfwWaitEvents or
689 glfwSwapBuffers must be called before any mouse movements are recorded and reported by
690 glfwGetMousePos.
694 (defcfun+doc ("glfwSetMousePos" set-mouse-pos) :void ((xpos :int) (ypos :int))
695 "Parameters
696 xpos
697 Horizontal position of the mouse.
698 ypos
699 Vertical position of the mouse.
701 Description
702 The function changes the position of the mouse. If the cursor is visible (not disabled), the cursor will be
703 moved to the specified position, relative to the upper left corner of the window client area. If the cursor
704 is hidden (disabled), only the mouse position that is reported by GLFW is changed.
707 (defcfun+doc ("glfwGetMouseWheel" get-mouse-wheel) :int ()
708 "Return values
709 The function returns the current mouse wheel position.
710 Description
711 The function returns the current mouse wheel position. The mouse wheel can be thought of as a third
712 mouse axis, which is available as a separate wheel or up/down stick on some mice.
713 Notes
714 A window must be opened for the function to have any effect, and glfwPollEvents, glfwWaitEvents or
715 glfwSwapBuffers must be called before any mouse wheel movements are recorded and reported by
716 glfwGetMouseWheel.
719 (defcfun+doc ("glfwSetMouseWheel" set-mouse-wheel) :void ((pos :int))
720 "Parameters
722 Position of the mouse wheel.
723 Description
724 The function changes the position of the mouse wheel.
728 (defcfun+doc ("glfwSetKeyCallback" set-key-callback) :void ((cbfun :pointer))
729 "Parameters
730 cbfun
731 Pointer to a callback function that will be called every time a key is pressed or released. The
732 function should have the following C language prototype:
733 void GLFWCALL functionname( int key, int action );
734 Where functionname is the name of the callback function, key is a key identifier, which is an
735 uppercase printable ISO 8859-1 character or a special key identifier (see table 3.3), and action is
736 either GLFW_PRESS or GLFW_RELEASE.
737 If cbfun is NULL, any previously selected callback function will be deselected.
738 Return values
739 none
740 Description
741 The function selects which function to be called upon a keyboard key event. The callback function is
742 called every time the state of a single key is changed (from released to pressed or vice versa). The
743 reported keys are unaffected by any modifiers (such as shift or alt).
744 A window has to be opened for this function to have any effect.
745 Notes
746 Keyboard events are recorded continuously, but only reported when glfwPollEvents, glfwWaitEvents
747 or glfwSwapBuffers is called.
749 (defcfun+doc ("glfwSetCharCallback" set-char-callback) :void ((cbfun :pointer))
750 "Parameters
751 cbfun
752 Pointer to a callback function that will be called every time a printable character is generated by
753 the keyboard. The function should have the following C language prototype:
754 void GLFWCALL functionname( int character, int action );
755 Where functionname is the name of the callback function, character is a Unicode (ISO 10646)
756 character, and action is either GLFW_PRESS or GLFW_RELEASE.
757 If cbfun is NULL, any previously selected callback function will be deselected.
758 Return values
759 none
760 Description
761 The function selects which function to be called upon a keyboard character event. The callback function
762 is called every time a key that results in a printable Unicode character is pressed or released. Characters
763 are affected by modifiers (such as shift or alt).
764 A window has to be opened for this function to have any effect.
765 Notes
766 Character events are recorded continuously, but only reported when glfwPollEvents, glfwWaitEvents
767 or glfwSwapBuffers is called.
768 Control characters, such as tab and carriage return, are not reported to the character callback function,
769 since they are not part of the Unicode character set. Use the key callback function for such events (see
770 glfwSetKeyCallback).
771 The Unicode character set supports character codes above 255, so never cast a Unicode character to an
772 eight bit data type (e.g. the C language ’char’ type) without first checking that the character code is less
773 than 256. Also note that Unicode character codes 0 to 255 are equal to ISO 8859-1 (Latin 1).
775 (defcfun+doc ("glfwSetMouseButtonCallback" set-mouse-button-callback) :void ((cbfun :pointer))
776 "Parameters
777 cbfun
778 Pointer to a callback function that will be called every time a mouse button is pressed or released.
779 The function should have the following C language prototype:
780 void GLFWCALL functionname( int button, int action );
781 Where functionname is the name of the callback function, button is a mouse button identifier (see
782 table 3.4 on page 56), and action is either GLFW_PRESS or GLFW_RELEASE.
783 If cbfun is NULL, any previously selected callback function will be deselected.
784 Return values
785 none
786 Description
787 The function selects which function to be called upon a mouse button event.
788 A window has to be opened for this function to have any effect.
789 Notes
790 Mouse button events are recorded continuously, but only reported when glfwPollEvents,
791 glfwWaitEvents or glfwSwapBuffers is called.
792 GLFW_MOUSE_BUTTON_LEFT is equal to GLFW_MOUSE_BUTTON_1.
793 GLFW_MOUSE_BUTTON_RIGHT is equal to GLFW_MOUSE_BUTTON_2.
794 GLFW_MOUSE_BUTTON_MIDDLE is equal to GLFW_MOUSE_BUTTON_3.
796 (defcfun+doc ("glfwSetMousePosCallback" set-mouse-pos-callback) :void ((cbfun :pointer))
797 "Parameters
798 cbfun
799 Pointer to a callback function that will be called every time the mouse is moved. The function
800 should have the following C language prototype:
801 void GLFWCALL functionname( int x, int y );
802 Where functionname is the name of the callback function, and x and y are the mouse coordinates
803 (see glfwGetMousePos for more information on mouse coordinates).
804 If cbfun is NULL, any previously selected callback function will be deselected.
805 Return values
806 none
807 Description
808 The function selects which function to be called upon a mouse motion event.
809 A window has to be opened for this function to have any effect.
810 Notes
811 Mouse motion events are recorded continuously, but only reported when glfwPollEvents,
812 glfwWaitEvents or glfwSwapBuffers is called.
814 (defcfun+doc ("glfwSetMouseWheelCallback" set-mouse-wheel-callback) :void ((cbfun :pointer))
815 "Parameters
816 cbfun
817 Pointer to a callback function that will be called every time the mouse wheel is moved. The
818 function should have the following C language prototype:
819 void GLFWCALL functionname( int pos );
820 Where functionname is the name of the callback function, and pos is the mouse wheel position.
821 If cbfun is NULL, any previously selected callback function will be deselected.
822 Return values
823 none
824 Description
825 The function selects which function to be called upon a mouse wheel event.
826 A window has to be opened for this function to have any effect.
827 Notes
828 Mouse wheel events are recorded continuously, but only reported when glfwPollEvents,
829 glfwWaitEvents or glfwSwapBuffers is called.
832 (defcfun+doc ("glfwGetJoystickParam" get-joystick-param) :int ((joy :int) (param :int))
833 "Parameters
835 A joystick identifier, which should be GLFW_JOYSTICK_n, where n is in the range 1 to 16.
836 param
837 A token selecting which parameter the function should return (see table 3.5).
838 Return values
839 The function returns different parameters depending on the value of param. Table 3.5 lists valid param
840 values, and their corresponding return values.
841 Description
842 The function is used for acquiring various properties of a joystick.
843 Notes
844 The joystick information is updated every time the function is called.
845 No window has to be opened for joystick information to be valid.
848 (defcfun ("glfwGetJoystickPos" %get-joystick-pos) :int (joy :int) (pos :pointer) (numaxes :int))
850 (defun get-joystick-pos (joy numaxes)
851 "Parameters
853 A joystick identifier, which should be GLFW_JOYSTICK_n, where n is in the range 1 to 16.
854 numaxes
855 Specifies how many axes should be returned.
856 Return values
857 An list that will hold the positional values for all requested axes.
858 If the joystick is not supported or connected, the function will
859 return nil.
861 Description
862 The function queries the current position of one or more axes of a joystick. The positional values are
863 returned in an array, where the first element represents the first axis of the joystick (normally the X
864 axis). Each position is in the range -1.0 to 1.0. Where applicable, the positive direction of an axis is
865 right, forward or up, and the negative direction is left, back or down.
866 If numaxes exceeds the number of axes supported by the joystick, or if the joystick is not available, the
867 unused elements in the pos array will be set to 0.0 (zero).
869 Notes
870 The joystick state is updated every time the function is called, so there is no need to call glfwPollEvents
871 or glfwWaitEvents for joystick state to be updated.
872 Use glfwGetJoystickParam to retrieve joystick capabilities, such as joystick availability and number of
873 supported axes.
874 No window has to be opened for joystick input to be valid.
876 (with-foreign-object (pos :float numaxes)
877 (let ((numaxes (%get-joystick-pos joy pos numaxes)))
878 (loop for i below numaxes collecting (mem-aref pos :float i)))))
881 (defcfun ("glfwGetJoystickButtons" %get-joystick-buttons) :int (joy :int) (buttons :pointer) (numbuttons :int))
882 (defun get-joystick-buttons (joy numbuttons)
883 "Parameters
885 A joystick identifier, which should be GLFW_JOYSTICK_n, where n is in the range 1 to 16.
886 numbuttons
887 Specifies how many buttons should be returned.
888 Return values
889 A list that will hold the button states for all requested buttons.
890 The function returns the number of actually returned buttons. This is the minimum of numbuttons and
891 the number of buttons supported by the joystick. If the joystick is not supported or connected, the
892 function will return 0 (zero).
894 Description
895 The function queries the current state of one or more buttons of a joystick. The button states are
896 returned in an array, where the first element represents the first button of the joystick. Each state can be
897 either GLFW_PRESS or GLFW_RELEASE.
898 If numbuttons exceeds the number of buttons supported by the joystick, or if the joystick is not
899 available, the unused elements in the buttons array will be set to GLFW_RELEASE.
901 Notes
902 The joystick state is updated every time the function is called, so there is no need to call glfwPollEvents
903 or glfwWaitEvents for joystick state to be updated.
904 Use glfwGetJoystickParam to retrieve joystick capabilities, such as joystick availability and number of
905 supported buttons.
906 No window has to be opened for joystick input to be valid.
908 (with-foreign-object (buttons :unsigned-char numbuttons)
909 (let ((numbuttons (%get-joystick-buttons joy buttons numbuttons)))
910 (loop for i below numbuttons collecting (mem-aref buttons :unsigned-char i)))))
913 (defcfun+doc ("glfwGetTime" get-time) :double ()
914 "Return values
915 The function returns the value of the high precision timer. The time is measured in seconds, and is
916 returned as a double precision floating point value.
918 Description
919 The function returns the state of a high precision timer. Unless the timer has been set by the
920 glfwSetTime function, the time is measured as the number of seconds that have passed since glfwInit
921 was called.
923 Notes
924 The resolution of the timer depends on which system the program is running on. The worst case
925 resolution is somewhere in the order of 10 ms, while for most systems the resolution should be better
926 than 1 μs.
929 (defcfun+doc ("glfwSetTime" set-time) :void ((time :double))
930 "Parameters
931 time
932 Time (in seconds) that the timer should be set to.
934 Description
935 The function sets the current time of the high precision timer to the specified time. Subsequent calls to
936 glfwGetTime will be relative to this time. The time is given in seconds.
939 (defcfun+doc ("glfwSleep" sleep) :void ((time :double))
940 "Parameters
941 time
942 Time, in seconds, to sleep.
944 Description
945 The function puts the calling thread to sleep for the requested period of time. Only the calling thread is
946 put to sleep. Other threads within the same process can still execute.
948 Notes
949 There is usually a system dependent minimum time for which it is possible to sleep. This time is
950 generally in the range 1 ms to 20 ms, depending on thread sheduling time slot intervals etc. Using a
951 shorter time as a parameter to glfwSleep can give one of two results: either the thread will sleep for the
952 minimum possible sleep time, or the thread will not sleep at all (glfwSleep returns immediately). The
953 latter should only happen when very short sleep times are specified, if at all. ")
955 (defcstruct image
956 (width :int)
957 (height :int)
958 (format :int)
959 (bytes-per-pixel :int)
960 (data :pointer))
962 (defcfun+doc ("glfwReadImage" read-image) boolean
963 ((name :string) (img image) (flags :int))
964 "Parameters
965 name
966 A null terminated ISO 8859-1 string holding the name of the file that should be read.
968 Pointer to a GLFWimage struct, which will hold the information about the loaded image (if the
969 read was successful).
970 flags
971 Flags for controlling the image reading process. Valid flags are listed in table 3.6
972 Return values
973 The function returns t if the image was loaded successfully. Otherwise nil is
974 returned.
975 Description
976 The function reads an image from the file specified by the parameter name and returns the image
977 information and data in a GLFWimage structure, which has the following definition:
978 § ¤
979 typedef struct {
980 int Width, Height; // Image dimensions
981 int Format; // OpenGL pixel format
982 int BytesPerPixel; // Number of bytes per pixel
983 unsigned char *Data; // Pointer to pixel data
984 } GLFWimage;
985 ¦ ¥
986 Width and Height give the dimensions of the image. Format specifies an OpenGL™ pixel format,
987 which can be GL_LUMINANCE or GL_ALPHA (for gray scale images), GL_RGB or GL_RGBA.
988 BytesPerPixel specifies the number of bytes per pixel. Data is a pointer to the actual pixel data.
989 By default the read image is rescaled to the nearest larger 2m × 2n resolution using bilinear
990 interpolation, if necessary, which is useful if the image is to be used as an OpenGL™ texture. This
991 behavior can be disabled by setting the GLFW_NO_RESCALE_BIT flag.
992 Unless the flag GLFW_ORIGIN_UL_BIT is set, the first pixel in img->Data is the lower left corner of
993 the image. If the flag GLFW_ORIGIN_UL_BIT is set, however, the first pixel is the upper left corner.
994 For single component images (i.e. gray scale), Format is set to GL_ALPHA if the flag
995 GLFW_ALPHA_MAP_BIT flag is set, otherwise Format is set to GL_LUMINANCE.
996 Notes
997 glfwReadImage supports the Truevision Targa version 1 file format (.TGA). Supported pixel formats
998 are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color + alpha.
999 Paletted images are translated into true color or true color + alpha pixel formats.
1000 Please note that OpenGL™ 1.0 does not support single component alpha maps, so do not use images
1001 with Format = GL_ALPHA directly as textures under OpenGL™ 1.0.
1004 (defcfun+doc ("glfwReadMemoryImage" read-memory-image) boolean
1005 ((data :pointer) (size :long) (img image) (flags :int))
1006 "Parameters
1007 data
1008 The memory buffer holding the contents of the file that should be read.
1009 size
1010 The size, in bytes, of the memory buffer.
1012 Pointer to a GLFWimage struct, which will hold the information about the loaded image (if the
1013 read was successful).
1014 flags
1015 Flags for controlling the image reading process. Valid flags are listed in table 3.6
1016 Return values
1017 The function returns t if the image was loaded successfully. Otherwise nil is
1018 returned.
1019 Description
1020 The function reads an image from the memory buffer specified by the parameter data and returns the
1021 image information and data in a GLFWimage structure, which has the following definition:
1022 § ¤
1023 typedef struct {
1024 int Width, Height; // Image dimensions
1025 int Format; // OpenGL pixel format
1026 int BytesPerPixel; // Number of bytes per pixel
1027 unsigned char *Data; // Pointer to pixel data
1028 } GLFWimage;
1029 ¦ ¥
1030 Width and Height give the dimensions of the image. Format specifies an OpenGL™ pixel format,
1031 which can be GL_LUMINANCE or GL_ALPHA (for gray scale images), GL_RGB or GL_RGBA.
1032 BytesPerPixel specifies the number of bytes per pixel. Data is a pointer to the actual pixel data.
1033 By default the read image is rescaled to the nearest larger 2m × 2n resolution using bilinear
1034 interpolation, if necessary, which is useful if the image is to be used as an OpenGL™ texture. This
1035 behavior can be disabled by setting the GLFW_NO_RESCALE_BIT flag.
1036 Unless the flag GLFW_ORIGIN_UL_BIT is set, the first pixel in img->Data is the lower left corner of
1037 the image. If the flag GLFW_ORIGIN_UL_BIT is set, however, the first pixel is the upper left corner.
1038 For single component images (i.e. gray scale), Format is set to GL_ALPHA if the flag
1039 GLFW_ALPHA_MAP_BIT flag is set, otherwise Format is set to GL_LUMINANCE.
1040 Notes
1041 glfwReadMemoryImage supports the Truevision Targa version 1 file format (.TGA). Supported pixel
1042 formats are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color +
1043 alpha.
1044 Paletted images are translated into true color or true color + alpha pixel formats.
1045 Please note that OpenGL™ 1.0 does not support single component alpha maps, so do not use images
1046 with Format = GL_ALPHA directly as textures under OpenGL™ 1.0.
1049 (defcfun+doc ("glfwFreeImage" free-image) :void ((img image))
1050 "Parameters
1052 Pointer to a GLFWimage struct.
1053 Description
1054 The function frees any memory occupied by a loaded image, and clears all the fields of the GLFWimage
1055 struct. Any image that has been loaded by the glfwReadImage function should be deallocated using
1056 this function, once the image is not needed anymore. ")
1058 (defcfun+doc ("glfwLoadTexture2D" load-texture-2d) boolean ((name :string) (flags :int))
1059 "Parameters
1060 name
1061 An ISO 8859-1 string holding the name of the file that should be loaded.
1062 flags
1063 Flags for controlling the texture loading process. Valid flags are listed in table 3.7.
1064 Return values
1065 The function returns t if the texture was loaded successfully. Otherwise nil is
1066 returned.
1068 Description
1069 The function reads an image from the file specified by the parameter name and uploads the image to
1070 OpenGL™ texture memory (using the glTexImage2D function).
1071 If the GLFW_BUILD_MIPMAPS_BIT flag is set, all mipmap levels for the loaded texture are
1072 generated and uploaded to texture memory.
1073 Unless the flag GLFW_ORIGIN_UL_BIT is set, the origin of the texture is the lower left corner of the
1074 loaded image. If the flag GLFW_ORIGIN_UL_BIT is set, however, the first pixel is the upper left
1075 corner.
1076 For single component images (i.e. gray scale), the texture is uploaded as an alpha mask if the flag
1077 GLFW_ALPHA_MAP_BIT flag is set, otherwise it is uploaded as a luminance texture.
1079 Notes
1080 glfwLoadTexture2D supports the Truevision Targa version 1 file format (.TGA). Supported pixel
1081 formats are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color +
1082 alpha.
1083 Paletted images are translated into true color or true color + alpha pixel formats.
1084 The read texture is always rescaled to the nearest larger 2m × 2n resolution using bilinear interpolation,
1085 if necessary, since OpenGL™ requires textures to have a 2m × 2n resolution.
1086 If the GL_SGIS_generate_mipmap extension, which is usually hardware accelerated, is supported by
1087 the OpenGL™ implementation it will be used for mipmap generation. Otherwise the mipmaps will be
1088 generated by GLFW in software.
1089 Since OpenGL™ 1.0 does not support single component alpha maps, alpha map textures are converted
1090 to RGBA format under OpenGL™ 1.0 when the GLFW_ALPHA_MAP_BIT flag is set and the loaded
1091 texture is a single component texture. The red, green and blue components are set to 1.0.
1094 (defcfun+doc ("glfwLoadMemoryTexture2D" load-memory-texture-2d) boolean
1095 ((data :pointer) (size :long) (flags :int))
1096 "Parameters
1097 data
1098 The memory buffer holding the contents of the file that should be loaded.
1099 size
1100 The size, in bytes, of the memory buffer.
1101 flags
1102 Flags for controlling the texture loading process. Valid flags are listed in table 3.7.
1103 Return values
1104 The function returns t if the texture was loaded successfully. Otherwise nil is
1105 returned.
1107 Description
1108 The function reads an image from the memory buffer specified by the parameter data and uploads the
1109 image to OpenGL™ texture memory (using the glTexImage2D function).
1110 If the GLFW_BUILD_MIPMAPS_BIT flag is set, all mipmap levels for the loaded texture are
1111 generated and uploaded to texture memory.
1112 Unless the flag GLFW_ORIGIN_UL_BIT is set, the origin of the texture is the lower left corner of the
1113 loaded image. If the flag GLFW_ORIGIN_UL_BIT is set, however, the first pixel is the upper left
1114 corner.
1115 For single component images (i.e. gray scale), the texture is uploaded as an alpha mask if the flag
1116 GLFW_ALPHA_MAP_BIT flag is set, otherwise it is uploaded as a luminance texture.
1118 Notes
1119 glfwLoadMemoryTexture2D supports the Truevision Targa version 1 file format (.TGA). Supported
1120 pixel formats are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color
1121 + alpha.
1122 Paletted images are translated into true color or true color + alpha pixel formats.
1123 The read texture is always rescaled to the nearest larger 2m × 2n resolution using bilinear interpolation,
1124 if necessary, since OpenGL™ requires textures to have a 2m × 2n resolution.
1125 If the GL_SGIS_generate_mipmap extension, which is usually hardware accelerated, is supported by
1126 the OpenGL™ implementation it will be used for mipmap generation. Otherwise the mipmaps will be
1127 generated by GLFW in software.
1128 Since OpenGL™ 1.0 does not support single component alpha maps, alpha map textures are converted
1129 to RGBA format under OpenGL™ 1.0 when the GLFW_ALPHA_MAP_BIT flag is set and the loaded
1130 texture is a single component texture. The red, green and blue components are set to 1.0.
1134 (defcfun+doc ("glfwLoadTextureImage2D" load-texture-image-2d) boolean ((img image)
1135 (flags :int))
1136 "Parameters
1138 Pointer to a GLFWimage struct holding the information about the image to be loaded.
1139 flags
1140 Flags for controlling the texture loading process. Valid flags are listed in table 3.7.
1141 Return values
1142 The function returns t if the texture was loaded successfully. Otherwise nil is
1143 returned.
1145 Description
1146 The function uploads the image specified by the parameter img to OpenGL™ texture memory (using
1147 the glTexImage2D function).
1148 If the GLFW_BUILD_MIPMAPS_BIT flag is set, all mipmap levels for the loaded texture are
1149 generated and uploaded to texture memory.
1150 Unless the flag GLFW_ORIGIN_UL_BIT is set, the origin of the texture is the lower left corner of the
1151 loaded image. If the flag GLFW_ORIGIN_UL_BIT is set, however, the first pixel is the upper left
1152 corner.
1153 For single component images (i.e. gray scale), the texture is uploaded as an alpha mask if the flag
1154 GLFW_ALPHA_MAP_BIT flag is set, otherwise it is uploaded as a luminance texture.
1156 Notes
1157 glfwLoadTextureImage2D supports the Truevision Targa version 1 file format (.TGA). Supported
1158 pixel formats are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color
1159 + alpha.
1160 Paletted images are translated into true color or true color + alpha pixel formats.
1161 The read texture is always rescaled to the nearest larger 2m × 2n resolution using bilinear interpolation,
1162 if necessary, since OpenGL™ requires textures to have a 2m × 2n resolution.
1163 If the GL_SGIS_generate_mipmap extension, which is usually hardware accelerated, is supported by
1164 the OpenGL™ implementation it will be used for mipmap generation. Otherwise the mipmaps will be
1165 generated by GLFW in software.
1166 Since OpenGL™ 1.0 does not support single component alpha maps, alpha map textures are converted
1167 to RGBA format under OpenGL™ 1.0 when the GLFW_ALPHA_MAP_BIT flag is set and the loaded
1168 texture is a single component texture. The red, green and blue components are set to 1.0. ")
1171 (defcfun+doc ("glfwExtensionSupported" extension-supported) boolean ((extension :string))
1172 "Parameters
1173 extension
1174 A null terminated ISO 8859-1 string containing the name of an OpenGL™ extension.
1175 Return values
1176 The function returns t if the extension is supported. Otherwise it returns nil.
1177 Description
1178 The function does a string search in the list of supported OpenGL™ extensions to find if the specified
1179 extension is listed.
1180 Notes
1181 An OpenGL™ context must be created before this function can be called (i.e. an OpenGL™ window
1182 must have been opened with glfwOpenWindow).
1183 In addition to checking for OpenGL™ extensions, GLFW also checks for extensions in the operating
1184 system “glue API”, such as WGL extensions under Windows and glX extensions under the X Window
1185 System.
1188 (defcfun+doc ("glfwGetProcAddress" get-proc-address) :pointer ((procname :string))
1189 "Parameters
1190 procname
1191 A null terminated ISO 8859-1 string containing the name of an OpenGL™ extension function.
1192 Return values
1193 The function returns the pointer to the specified OpenGL™ function if it is supported, otherwise
1194 NULL is returned.
1195 Description
1196 The function acquires the pointer to an OpenGL™ extension function. Some (but not all) OpenGL™
1197 extensions define new API functions, which are usually not available through normal linking. It is
1198 therefore necessary to get access to those API functions at runtime.
1199 Notes
1200 An OpenGL™ context must be created before this function can be called (i.e. an OpenGL™ window
1201 must have been opened with glfwOpenWindow).
1202 Some systems do not support dynamic function pointer retrieval, in which case glfwGetProcAddress
1203 will always return NULL.
1206 (defcfun+out+doc ("glfwGetGLVersion" get-gl-version) :void ((:out major :int)
1207 (:out minor :int)
1208 (:out rev :int))
1209 "Return values
1210 The function returns the major and minor version numbers and the revision for the currently used
1211 OpenGL™ implementation as a list (major minor rev).
1213 Description
1214 The function returns the OpenGL™ implementation version. This is a convenient function that parses
1215 the version number information from the string returned by calling
1216 glGetString( GL_VERSION ). The OpenGL™ version information can be used to determine
1217 what functionality is supported by the used OpenGL™ implementation.
1219 Notes
1220 An OpenGL™ context must be created before this function can be called (i.e. an OpenGL™ window
1221 must have been opened with glfwOpenWindow). ")
1223 (defctype thread :int)
1224 (defctype threadfun :pointer)
1225 (defctype mutex :pointer)
1226 (defctype cond :pointer)
1228 (defcfun+doc ("glfwCreateThread" create-thread) thread ((fun threadfun) (arg :pointer) )
1229 "Parameters
1231 A pointer to a function that acts as the entry point for the new thread. The function should have
1232 the following C language prototype:
1233 void GLFWCALL functionname( void *arg );
1234 Where functionname is the name of the thread function, and arg is the user supplied argument
1235 (see below).
1237 An arbitrary argument for the thread. arg will be passed as the argument to the thread function
1238 pointed to by fun. For instance, arg can point to data that is to be processed by the thread.
1239 Return values
1240 The function returns a thread identification number if the thread was created successfully. This number
1241 is always positive. If the function fails, a negative number is returned.
1242 Description
1243 The function creates a new thread, which executes within the same address space as the calling process.
1244 The thread entry point is specified with the fun argument.
1245 Once the thread function fun returns, the thread dies.
1246 Notes
1247 Even if the function returns a positive thread ID, indicating that the thread was created successfully, the
1248 thread may be unable to execute, for instance if the thread start address is not a valid thread entry point.
1250 (defcfun+doc ("glfwDestroyThread" destroy-thread) :void ((id thread))
1251 "Parameters
1253 A thread identification handle, which is returned by glfwCreateThread or glfwGetThreadID.
1254 Description
1255 The function kills a running thread and removes it from the thread list.
1256 Notes
1257 This function is a very dangerous operation, which may interrupt a thread in the middle of an important
1258 operation, and its use is discouraged. You should always try to end a thread in a graceful way using
1259 thread communication, and use glfwWaitThread in order to wait for the thread to die.
1261 (defcfun+doc ("glfwWaitThread" wait-thread) boolean ((id thread) (waitmode :int) )
1262 "Parameters
1264 A thread identification handle, which is returned by glfwCreateThread or glfwGetThreadID.
1265 waitmode
1266 Can be either GLFW_WAIT or GLFW_NOWAIT.
1267 Return values
1268 The function returns t if the specified thread died after the function was called, or the thread
1269 did not exist, in which case glfwWaitThread will return immediately regardless of waitmode. The
1270 function returns nil if waitmode is GLFW_NOWAIT, and the specified thread exists and is still
1271 running.
1273 (defcfun+doc ("glfwGetThreadID" get-thread-id) thread ()
1274 "Return values
1275 The function returns a thread identification handle for the calling thread.
1276 Description
1277 The function determines the thread ID for the calling thread. The ID is the same value as was returned
1278 by glfwCreateThread when the thread was created.
1281 (defcfun+doc ("glfwCreateMutex" create-mutex) mutex ()
1282 "Return values
1283 The function returns a mutex handle, or NULL if the mutex could not be created.
1284 Description
1285 The function creates a mutex object, which can be used to control access to data that is shared between
1286 threads.
1288 (defcfun+doc ("glfwDestroyMutex" destroy-mutex) :void ((mutex mutex))
1289 "Parameters
1290 mutex
1291 A mutex object handle.
1292 Description
1293 The function destroys a mutex object. After a mutex object has been destroyed, it may no longer be
1294 used by any thread.
1296 (defcfun+doc ("glfwLockMutex" lock-mutex) :void ((mutex mutex))
1297 "Parameters
1298 mutex
1299 A mutex object handle.
1300 Description
1301 The function will acquire a lock on the selected mutex object. If the mutex is already locked by another
1302 thread, the function will block the calling thread until it is released by the locking thread. Once the
1303 function returns, the calling thread has an exclusive lock on the mutex. To release the mutex, call
1304 glfwUnlockMutex.
1306 (defcfun+doc ("glfwUnlockMutex" unlock-mutex) :void ((mutex mutex))
1307 "Parameters
1308 mutex
1309 A mutex object handle.
1310 Description
1311 The function releases the lock of a locked mutex object.
1314 (defmacro with-lock-mutex (mutex &body forms)
1315 "Parameters
1316 mutex
1317 A mutex object handle.
1318 forms
1319 Body of code to execute
1320 Description
1321 This macro will acquire a lock on the selected mutex object using glfwLockMutex and release it afterwards
1322 using glfwUnlockMutex.
1323 So, forms will not execute until an exclusive lock is held.
1324 The lock is then released when the stack is unwound."
1325 (let ((smutex (gensym "MUTEX-")))
1326 `(let ((,smutex ,mutex))
1327 (glfw:lock-mutex ,smutex)
1328 (unwind-protect (progn ,@forms)
1329 (glfw:unlock-mutex ,smutex)))))
1331 (defcfun+doc ("glfwCreateCond" create-cond) cond ()
1332 "Return values
1333 The function returns a condition variable handle, or NULL if the condition variable could not be
1334 created.
1335 Description
1336 The function creates a condition variable object, which can be used to synchronize threads.
1338 (defcfun+doc ("glfwDestroyCond" destroy-cond) :void ((cond cond))
1339 "Parameters
1340 cond
1341 A condition variable object handle.
1342 Description
1343 The function destroys a condition variable object. After a condition variable object has been destroyed,
1344 it may no longer be used by any thread.
1346 (defcfun+doc ("glfwWaitCond" wait-cond) :void ((cond cond) (mutex mutex) (timeout :double))
1347 " arameters
1348 cond
1349 A condition variable object handle.
1350 mutex
1351 A mutex object handle.
1352 timeout
1353 Maximum time to wait for the condition variable. The parameter can either be a positive time (in
1354 seconds), or GLFW_INFINITY.
1355 Description
1356 The function atomically unlocks the mutex specified by mutex, and waits for the condition variable cond
1357 to be signaled. The thread execution is suspended and does not consume any CPU time until the
1358 condition variable is signaled or the amount of time specified by timeout has passed. If timeout is
1359 GLFW_INFINITY, glfwWaitCond will wait forever for cond to be signaled. Before returning to the
1360 calling thread, glfwWaitCond automatically re-acquires the mutex.
1361 Notes
1362 The mutex specified by mutex must be locked by the calling thread before entrance to glfwWaitCond.
1363 A condition variable must always be associated with a mutex, to avoid the race condition where a thread
1364 prepares to wait on a condition variable and another thread signals the condition just before the first
1365 thread actually waits on it.
1367 (defcfun+doc ("glfwSignalCond" signal-cond) :void ((cond cond))
1368 "Parameters
1369 cond
1370 A condition variable object handle.
1371 Description
1372 The function restarts one of the threads that are waiting on the condition variable cond. If no threads are
1373 waiting on cond, nothing happens. If several threads are waiting on cond, exactly one is restarted, but it
1374 is not specified which.
1375 Notes
1376 When several threads are waiting for the condition variable, which thread is started depends on
1377 operating system scheduling rules, and may vary from system to system and from time to time.
1379 (defcfun+doc ("glfwBroadcastCond" broadcast-cond) :void ((cond cond))
1380 "Parameters
1381 cond
1382 A condition variable object handle.
1383 Description
1384 The function restarts all the threads that are waiting on the condition variable cond. If no threads are
1385 waiting on cond, nothing happens.
1386 Notes
1387 When several threads are waiting for the condition variable, the order in which threads are started
1388 depends on operating system scheduling rules, and may vary from system to system and from time to
1389 time.
1392 (defcfun+doc ("glfwGetNumberOfProcessors" get-number-of-processors) :int ()
1393 "Return values
1394 The function returns the number of active processors in the system.
1395 Description
1396 The function determines the number of active processors in the system.
1397 Notes
1398 Systems with several logical processors per physical processor, also known as SMT (Symmetric Multi
1399 Threading) processors, will report the number of logical processors.
1401 (defcfun+doc ("glfwEnable" enable) :void ((token :int))
1402 "Parameters
1403 token
1404 A value specifying a feature to enable or disable. Valid tokens are listed in table 3.8.
1405 Return values
1406 none
1407 Description
1408 glfwEnable is used to enable a certain feature, while glfwDisable is used to disable it. Below follows a
1409 description of each feature.
1410 GLFW_AUTO_POLL_EVENTS
1411 When GLFW_AUTO_POLL_EVENTS is enabled, glfwPollEvents is automatically called each time
1412 that glfwSwapBuffers is called.
1413 When GLFW_AUTO_POLL_EVENTS is disabled, calling glfwSwapBuffers will not result in a call to
1414 glfwPollEvents. This can be useful if glfwSwapBuffers needs to be called from within a callback
1415 function, since calling glfwPollEvents from a callback function is not allowed.
1416 GLFW_KEY_REPEAT
1417 When GLFW_KEY_REPEAT is enabled, the key and character callback functions are called repeatedly
1418 when a key is held down long enough (according to the system key repeat configuration).
1419 When GLFW_KEY_REPEAT is disabled, the key and character callback functions are only called once
1420 when a key is pressed (and once when it is released).
1421 GLFW_MOUSE_CURSOR
1422 When GLFW_MOUSE_CURSOR is enabled, the mouse cursor is visible, and mouse coordinates are
1423 relative to the upper left corner of the client area of the GLFW window. The coordinates are limited to
1424 the client area of the window.
1425 When GLFW_MOUSE_CURSOR is disabled, the mouse cursor is invisible, and mouse coordinates are
1426 not limited to the drawing area of the window. It is as if the mouse coordinates are recieved directly
1427 from the mouse, without being restricted or manipulated by the windowing system.
1428 GLFW_STICKY_KEYS
1429 When GLFW_STICKY_KEYS is enabled, keys which are pressed will not be released until they are
1430 physically released and checked with glfwGetKey. This behavior makes it possible to catch keys that
1431 were pressed and then released again between two calls to glfwPollEvents, glfwWaitEvents or
1432 glfwSwapBuffers, which would otherwise have been reported as released. Care should be taken when
1433 using this mode, since keys that are not checked with glfwGetKey will never be released. Note also that
1434 enabling GLFW_STICKY_KEYS does not affect the behavior of the keyboard callback functionality.
1435 When GLFW_STICKY_KEYS is disabled, the status of a key that is reported by glfwGetKey is always
1436 the physical state of the key. Disabling GLFW_STICKY_KEYS also clears the sticky information for
1437 all keys.
1438 GLFW_STICKY_MOUSE_BUTTONS
1439 When GLFW_STICKY_MOUSE_BUTTONS is enabled, mouse buttons that are pressed will not be
1440 released until they are physically released and checked with glfwGetMouseButton. This behavior
1441 makes it possible to catch mouse buttons which were pressed and then released again between two calls
1442 to glfwPollEvents, glfwWaitEvents or glfwSwapBuffers, which would otherwise have been reported
1443 as released. Care should be taken when using this mode, since mouse buttons that are not checked with
1444 glfwGetMouseButton will never be released. Note also that enabling
1445 GLFW_STICKY_MOUSE_BUTTONS does not affect the behavior of the mouse button callback
1446 functionality.
1447 When GLFW_STICKY_MOUSE_BUTTONS is disabled, the status of a mouse button that is reported
1448 by glfwGetMouseButton is always the physical state of the mouse button. Disabling
1449 GLFW_STICKY_MOUSE_BUTTONS also clears the sticky information for all mouse buttons.
1450 GLFW_SYSTEM_KEYS
1451 When GLFW_SYSTEM_KEYS is enabled, pressing standard system key combinations, such as
1452 ALT+TAB under Windows, will give the normal behavior. Note that when ALT+TAB is issued under
1453 Windows in this mode so that the GLFW application is deselected when GLFW is operating in
1454 fullscreen mode, the GLFW application window will be minimized and the video mode will be set to
1455 the original desktop mode. When the GLFW application is re-selected, the video mode will be set to
1456 the GLFW video mode again.
1457 When GLFW_SYSTEM_KEYS is disabled, pressing standard system key combinations will have no
1458 effect, since those key combinations are blocked by GLFW. This mode can be useful in situations when
1459 the GLFW program must not be interrupted (normally for games in fullscreen mode).
1461 (defcfun+doc ("glfwDisable" disable) :void ((token :int))
1462 "Parameters
1463 token
1464 A value specifying a feature to enable or disable. Valid tokens are listed in table 3.8.
1465 Return values
1466 none
1467 Description
1468 glfwEnable is used to enable a certain feature, while glfwDisable is used to disable it. Below follows a
1469 description of each feature.
1470 GLFW_AUTO_POLL_EVENTS
1471 When GLFW_AUTO_POLL_EVENTS is enabled, glfwPollEvents is automatically called each time
1472 that glfwSwapBuffers is called.
1473 When GLFW_AUTO_POLL_EVENTS is disabled, calling glfwSwapBuffers will not result in a call to
1474 glfwPollEvents. This can be useful if glfwSwapBuffers needs to be called from within a callback
1475 function, since calling glfwPollEvents from a callback function is not allowed.
1476 GLFW_KEY_REPEAT
1477 When GLFW_KEY_REPEAT is enabled, the key and character callback functions are called repeatedly
1478 when a key is held down long enough (according to the system key repeat configuration).
1479 When GLFW_KEY_REPEAT is disabled, the key and character callback functions are only called once
1480 when a key is pressed (and once when it is released).
1481 GLFW_MOUSE_CURSOR
1482 When GLFW_MOUSE_CURSOR is enabled, the mouse cursor is visible, and mouse coordinates are
1483 relative to the upper left corner of the client area of the GLFW window. The coordinates are limited to
1484 the client area of the window.
1485 When GLFW_MOUSE_CURSOR is disabled, the mouse cursor is invisible, and mouse coordinates are
1486 not limited to the drawing area of the window. It is as if the mouse coordinates are recieved directly
1487 from the mouse, without being restricted or manipulated by the windowing system.
1488 GLFW_STICKY_KEYS
1489 When GLFW_STICKY_KEYS is enabled, keys which are pressed will not be released until they are
1490 physically released and checked with glfwGetKey. This behavior makes it possible to catch keys that
1491 were pressed and then released again between two calls to glfwPollEvents, glfwWaitEvents or
1492 glfwSwapBuffers, which would otherwise have been reported as released. Care should be taken when
1493 using this mode, since keys that are not checked with glfwGetKey will never be released. Note also that
1494 enabling GLFW_STICKY_KEYS does not affect the behavior of the keyboard callback functionality.
1495 When GLFW_STICKY_KEYS is disabled, the status of a key that is reported by glfwGetKey is always
1496 the physical state of the key. Disabling GLFW_STICKY_KEYS also clears the sticky information for
1497 all keys.
1498 GLFW_STICKY_MOUSE_BUTTONS
1499 When GLFW_STICKY_MOUSE_BUTTONS is enabled, mouse buttons that are pressed will not be
1500 released until they are physically released and checked with glfwGetMouseButton. This behavior
1501 makes it possible to catch mouse buttons which were pressed and then released again between two calls
1502 to glfwPollEvents, glfwWaitEvents or glfwSwapBuffers, which would otherwise have been reported
1503 as released. Care should be taken when using this mode, since mouse buttons that are not checked with
1504 glfwGetMouseButton will never be released. Note also that enabling
1505 GLFW_STICKY_MOUSE_BUTTONS does not affect the behavior of the mouse button callback
1506 functionality.
1507 When GLFW_STICKY_MOUSE_BUTTONS is disabled, the status of a mouse button that is reported
1508 by glfwGetMouseButton is always the physical state of the mouse button. Disabling
1509 GLFW_STICKY_MOUSE_BUTTONS also clears the sticky information for all mouse buttons.
1510 GLFW_SYSTEM_KEYS
1511 When GLFW_SYSTEM_KEYS is enabled, pressing standard system key combinations, such as
1512 ALT+TAB under Windows, will give the normal behavior. Note that when ALT+TAB is issued under
1513 Windows in this mode so that the GLFW application is deselected when GLFW is operating in
1514 fullscreen mode, the GLFW application window will be minimized and the video mode will be set to
1515 the original desktop mode. When the GLFW application is re-selected, the video mode will be set to
1516 the GLFW video mode again.
1517 When GLFW_SYSTEM_KEYS is disabled, pressing standard system key combinations will have no
1518 effect, since those key combinations are blocked by GLFW. This mode can be useful in situations when
1519 the GLFW program must not be interrupted (normally for games in fullscreen mode).