Make a named block for do-window so you can return-from it.
[cl-glfw.git] / lib / glfw.lisp
blobae98f060ab6af7bd5b1bdfc35874ee0e938baf6a
1 (in-package #:cl-glfw)
3 (eval-when (:compile-toplevel :load-toplevel)
4 (defconstant +false+ 0)
5 (defconstant +true+ 1)
8 ;; Key and button state/action definitions
9 (defconstant +release+ 0)
10 (defconstant +press+ 1)
12 ;; Keyboard key definitions: 8-bit ISO-8859-1 (Latin 1) encoding is used
13 ;; for printable keys (such as A-Z, 0-9 etc), and values above 256
14 ;; represent special (non-printable) keys (e.g. F1, Page Up etc).
15 (defconstant +key-unknown+ -1)
16 (defconstant +key-space+ 32)
17 (defconstant +key-special+ 256)
18 (defconstant +key-esc+ (+ +key-special+ 1))
19 (defconstant +key-f1+ (+ +key-special+ 2))
20 (defconstant +key-f2+ (+ +key-special+ 3))
21 (defconstant +key-f3+ (+ +key-special+ 4))
22 (defconstant +key-f4+ (+ +key-special+ 5))
23 (defconstant +key-f5+ (+ +key-special+ 6))
24 (defconstant +key-f6+ (+ +key-special+ 7))
25 (defconstant +key-f7+ (+ +key-special+ 8))
26 (defconstant +key-f8+ (+ +key-special+ 9))
27 (defconstant +key-f9+ (+ +key-special+ 10))
28 (defconstant +key-f10+ (+ +key-special+ 11))
29 (defconstant +key-f11+ (+ +key-special+ 12))
30 (defconstant +key-f12+ (+ +key-special+ 13))
31 (defconstant +key-f13+ (+ +key-special+ 14))
32 (defconstant +key-f14+ (+ +key-special+ 15))
33 (defconstant +key-f15+ (+ +key-special+ 16))
34 (defconstant +key-f16+ (+ +key-special+ 17))
35 (defconstant +key-f17+ (+ +key-special+ 18))
36 (defconstant +key-f18+ (+ +key-special+ 19))
37 (defconstant +key-f19+ (+ +key-special+ 20))
38 (defconstant +key-f20+ (+ +key-special+ 21))
39 (defconstant +key-f21+ (+ +key-special+ 22))
40 (defconstant +key-f22+ (+ +key-special+ 23))
41 (defconstant +key-f23+ (+ +key-special+ 24))
42 (defconstant +key-f24+ (+ +key-special+ 25))
43 (defconstant +key-f25+ (+ +key-special+ 26))
44 (defconstant +key-up+ (+ +key-special+ 27))
45 (defconstant +key-down+ (+ +key-special+ 28))
46 (defconstant +key-left+ (+ +key-special+ 29))
47 (defconstant +key-right+ (+ +key-special+ 30))
48 (defconstant +key-lshift+ (+ +key-special+ 31))
49 (defconstant +key-rshift+ (+ +key-special+ 32))
50 (defconstant +key-lctrl+ (+ +key-special+ 33))
51 (defconstant +key-rctrl+ (+ +key-special+ 34))
52 (defconstant +key-lalt+ (+ +key-special+ 35))
53 (defconstant +key-ralt+ (+ +key-special+ 36))
54 (defconstant +key-tab+ (+ +key-special+ 37))
55 (defconstant +key-enter+ (+ +key-special+ 38))
56 (defconstant +key-backspace+ (+ +key-special+ 39))
57 (defconstant +key-insert+ (+ +key-special+ 40))
58 (defconstant +key-del+ (+ +key-special+ 41))
59 (defconstant +key-pageup+ (+ +key-special+ 42))
60 (defconstant +key-pagedown+ (+ +key-special+ 43))
61 (defconstant +key-home+ (+ +key-special+ 44))
62 (defconstant +key-end+ (+ +key-special+ 45))
63 (defconstant +key-kp-0+ (+ +key-special+ 46))
64 (defconstant +key-kp-1+ (+ +key-special+ 47))
65 (defconstant +key-kp-2+ (+ +key-special+ 48))
66 (defconstant +key-kp-3+ (+ +key-special+ 49))
67 (defconstant +key-kp-4+ (+ +key-special+ 50))
68 (defconstant +key-kp-5+ (+ +key-special+ 51))
69 (defconstant +key-kp-6+ (+ +key-special+ 52))
70 (defconstant +key-kp-7+ (+ +key-special+ 53))
71 (defconstant +key-kp-8+ (+ +key-special+ 54))
72 (defconstant +key-kp-9+ (+ +key-special+ 55))
73 (defconstant +key-kp-divide+ (+ +key-special+ 56))
74 (defconstant +key-kp-multiply+ (+ +key-special+ 57))
75 (defconstant +key-kp-subtract+ (+ +key-special+ 58))
76 (defconstant +key-kp-add+ (+ +key-special+ 59))
77 (defconstant +key-kp-decimal+ (+ +key-special+ 60))
78 (defconstant +key-kp-equal+ (+ +key-special+ 61))
79 (defconstant +key-kp-enter+ (+ +key-special+ 62))
80 (defconstant +key-kp-num-lock+ (+ +key-special+ 63))
81 (defconstant +key-caps-lock+ (+ +key-special+ 64))
82 (defconstant +key-scroll-lock+ (+ +key-special+ 65))
83 (defconstant +key-pause+ (+ +key-special+ 66))
84 (defconstant +key-lsuper+ (+ +key-special+ 67))
85 (defconstant +key-rsuper+ (+ +key-special+ 68))
86 (defconstant +key-menu+ (+ +key-special+ 69))
87 (defconstant +key-last+ +key-menu+)
89 ;; Mouse button definitions
90 (defconstant +mouse-button-1+ 0)
91 (defconstant +mouse-button-2+ 1)
92 (defconstant +mouse-button-3+ 2)
93 (defconstant +mouse-button-4+ 3)
94 (defconstant +mouse-button-5+ 4)
95 (defconstant +mouse-button-6+ 5)
96 (defconstant +mouse-button-7+ 6)
97 (defconstant +mouse-button-8+ 7)
98 (defconstant +mouse-button-last+ +mouse-button-8+)
100 ;; Mouse button aliases
101 (defconstant +mouse-button-left+ +mouse-button-1+)
102 (defconstant +mouse-button-right+ +mouse-button-2+)
103 (defconstant +mouse-button-middle+ +mouse-button-3+)
105 ;; Joystick identifiers
106 (defconstant +joystick-1+ 0)
107 (defconstant +joystick-2+ 1)
108 (defconstant +joystick-3+ 2)
109 (defconstant +joystick-4+ 3)
110 (defconstant +joystick-5+ 4)
111 (defconstant +joystick-6+ 5)
112 (defconstant +joystick-7+ 6)
113 (defconstant +joystick-8+ 7)
114 (defconstant +joystick-9+ 8)
115 (defconstant +joystick-10+ 9)
116 (defconstant +joystick-11+ 10)
117 (defconstant +joystick-12+ 11)
118 (defconstant +joystick-13+ 12)
119 (defconstant +joystick-14+ 13)
120 (defconstant +joystick-15+ 14)
121 (defconstant +joystick-16+ 15)
122 (defconstant +joystick-last+ +joystick-16+)
125 ;;========================================================================
126 ;; Other definitions
127 ;;========================================================================
129 ;; glfwOpenWindow modes
130 (defconstant +window+ #x00010001)
131 (defconstant +fullscreen+ #x00010002)
133 ;; glfwGetWindowParam tokens
134 (defconstant +opened+ #x00020001)
135 (defconstant +active+ #x00020002)
136 (defconstant +iconified+ #x00020003)
137 (defconstant +accelerated+ #x00020004)
138 (defconstant +red-bits+ #x00020005)
139 (defconstant +green-bits+ #x00020006)
140 (defconstant +blue-bits+ #x00020007)
141 (defconstant +alpha-bits+ #x00020008)
142 (defconstant +depth-bits+ #x00020009)
143 (defconstant +stencil-bits+ #x0002000a)
145 ;; The following constants are used for both glfwGetWindowParam
146 ;; and glfwOpenWindowHint
147 (defconstant +refresh-rate+ #x0002000b)
148 (defconstant +accum-red-bits+ #x0002000c)
149 (defconstant +accum-green-bits+ #x0002000d)
150 (defconstant +accum-blue-bits+ #x0002000e)
151 (defconstant +accum-alpha-bits+ #x0002000f)
152 (defconstant +aux-buffers+ #x00020010)
153 (defconstant +stereo+ #x00020011)
154 (defconstant +window-no-resize+ #x00020012)
155 (defconstant +fsaa-samples+ #x00020013)
156 (defconstant +opengl-version-major+ #x00020014)
157 (defconstant +opengl-version-minor+ #x00020015)
158 (defconstant +opengl-forward-compat+ #x00020016)
159 (defconstant +opengl-debug-context+ #x00020017)
160 (defconstant +opengl-profile+ #x00020018)
162 (defconstant +opengl-core-profile+ #x00050001)
163 (defconstant +opengl-compat-profile+ #x00050002)
165 ;; glfwEnable/glfwDisable tokens
166 (defconstant +mouse-cursor+ #x00030001)
167 (defconstant +sticky-keys+ #x00030002)
168 (defconstant +sticky-mouse-buttons+ #x00030003)
169 (defconstant +system-keys+ #x00030004)
170 (defconstant +key-repeat+ #x00030005)
171 (defconstant +auto-poll-events+ #x00030006)
173 ;; glfwWaitThread wait modes
174 (defconstant +wait+ #x00040001)
175 (defconstant +nowait+ #x00040002)
177 ;; glfwGetJoystickParam tokens
178 (defconstant +present+ #x00050001)
179 (defconstant +axes+ #x00050002)
180 (defconstant +buttons+ #x00050003)
182 ;; glfwReadImage/glfwLoadTexture2D flags
183 (defconstant +no-rescale-bit+ #x00000001) ; Only for glfwReadImage
184 (defconstant +origin-ul-bit+ #x00000002)
185 (defconstant +build-mipmaps-bit+ #x00000004) ; Only for glfwLoadTexture2D
186 (defconstant +alpha-map-bit+ #x00000008)
188 ;; Time spans longer than this (seconds) are considered to be infinity
189 (defconstant +infinity+ 100000d0))
191 (defparameter *was-init* nil
192 "True if we have already initialized.")
193 (declaim (type cl:boolean *was-init*))
195 (defparameter *init-hooks* nil
196 "A list of funcallable objects invoked just after initialization.")
197 (defparameter *terminate-hooks* nil
198 "A list of funcallable objects invoked just before termination.")
199 (declaim (type list *init-hooks* *terminate-hooks*))
201 (cffi:defcfun ("glfwInit" %init) boolean)
203 (defun init ()
204 "Return values
205 If the function succeeds, t is returned.
206 If the function fails, nil is returned.
208 The glfwInit function initializes GLFW. No other GLFW functions may be used before this function
209 has been called.
211 On successful initialization, the list of functions in *init-hooks* is called.
213 Notes
214 This function may take several seconds to complete on some systems, while on other systems it may
215 take only a fraction of a second to complete."
216 (when (%init)
217 (setf *was-init* t)
218 (mapc #'funcall *init-hooks*)
221 (cffi:defcfun ("glfwTerminate" %terminate) :void)
223 (defun terminate ()
224 "The function terminates GLFW. Among other things it closes the window, if it is opened, and kills any
225 running threads. This function must be called before a program exits.
227 Before termination, the list of functions in *terminate-hooks* is called.
229 (mapc #'funcall *terminate-hooks*)
230 (setf *was-init* nil)
231 (%terminate))
233 (defcfun+out+doc ("glfwGetVersion" get-version) :void ((:out major :int)
234 (:out minor :int)
235 (:out rev :int))
236 "Return values
237 The function returns the major and minor version numbers and the revision for the currently linked
238 GLFW library as a list (major minor rev).")
240 (defmacro with-init (&body forms)
241 "Call glfw:init, execute forms and clean-up with glfw:terminate once finished.
242 This makes a nice wrapper to an application higher-level form.
243 Signals an error on failure to initialize. Wrapped in a block named glfw:with-init."
244 `(if (glfw:init)
245 (unwind-protect
246 (block with-init ,@forms)
247 (glfw:terminate))
248 (error "Error initializing glfw.")))
250 (defcfun ("glfwOpenWindow" %open-window) boolean
251 (width :int) (height :int)
252 (redbits :int) (greenbits :int) (bluebits :int) (alphabits :int)
253 (depthbits :int) (stencilbits :int) (mode :int))
255 (declaim (inline open-window))
256 (defun open-window (&key (width 0) (height 0)
257 (redbits 0) (greenbits 0) (bluebits 0) (alphabits 0)
258 (depthbits 0) (stencilbits 0) (mode +window+)
259 title
260 ;;The hints
261 (refresh-rate 0 refresh-rate-p)
262 (accum-red-bits 0 accum-red-bits-p)
263 (accum-green-bits 0 accum-green-bits-p)
264 (accum-blue-bits 0 accum-blue-bits-p)
265 (accum-alpha-bits 0 accum-alpha-bits-p)
266 (aux-buffers 0 aux-buffers-p)
267 (stereo nil stereo-p)
268 (window-no-resize nil window-no-resize-p)
269 (fsaa-samples 0 fsaa-samples-p)
270 (opengl-version-major 1 opengl-version-major-p)
271 (opengl-version-minor 1 opengl-version-minor-p)
272 (opengl-forward-compat nil opengl-forward-compat-p)
273 (opengl-debug-context nil opengl-debug-context-p)
274 (opengl-profile 0 opengl-profile-p)
275 (opengl-core-profile 0 opengl-core-profile-p)
276 (opengl-compat-profile 0 opengl-compat-profile-p))
277 "width
278 The width of the window. If width is zero, it will be calculated as width = 4/3 height, if height is
279 not zero. If both width and height are zero, then width will be set to 640.
280 height
281 The height of the window. If height is zero, it will be calculated as height = 3/4 width, if width is
282 not zero. If both width and height are zero, then height will be set to 480.
283 redbits, greenbits, bluebits
284 The number of bits to use for each color component of the color buffer (0 means default color
285 depth). For instance, setting redbits=5, greenbits=6, and bluebits=5 will generate a 16-bit color
286 buffer, if possible.
287 alphabits
288 The number of bits to use for the alpha buffer (0 means no alpha buffer).
289 depthbits
290 The number of bits to use for the depth buffer (0 means no depth buffer).
291 stencilbits
292 The number of bits to use for the stencil buffer (0 means no stencil buffer).
293 mode
294 Selects which type of OpenGL window to use. mode can be either +WINDOW+, which
295 will generate a normal desktop window, or +FULLSCREEN+ which will generate a
296 window which covers the entire screen. When +FULLSCREEN+ is selected, the video
297 mode will be changed to the resolution that closest matches the width and height parameters.
299 Return values
300 If the function succeeds, t is returned.
301 If the function fails, nil is returned.
303 Description
305 The function opens a window that best matches the parameters given to
306 the function. How well the resulting window matches the desired window
307 depends mostly on the available hardware and OpenGL drivers. In
308 general, selecting a fullscreen mode has better chances of generating
309 a close match than does a normal desktop window, since GLFW can freely
310 select from all the available video modes. A desktop window is
311 normally restricted to the video mode of the desktop.
313 Notes
315 For additional control of window properties, see glfw::OpenWindowHint.
316 In fullscreen mode the mouse cursor is hidden by default, and any system screensavers are prohibited
317 from starting. In windowed mode the mouse cursor is visible, and screensavers are allowed to start. To
318 change the visibility of the mouse cursor, use glfwEnable or glfwDisable with the argument
319 +MOUSE_CURSOR+
320 In order to determine the actual properties of an opened window, use glfw::GetWindowParam and
321 glfw::GetWindowSize (or glfw::SetWindowSizeCallback).
323 (macrolet ((output-int-hints (&rest names)
324 `(progn
325 ,@(loop for name in names collect
326 `(when ,(intern (format nil "~a-P" name) '#:cl-glfw)
327 (open-window-hint ,(intern (format nil "+~A+" name) '#:cl-glfw)
328 ,name)))))
329 (output-boolean-hints (&rest names)
330 `(progn
331 ,@(loop for name in names collect
332 `(when ,(intern (format nil "~a-P" name) '#:cl-glfw)
333 (open-window-hint ,(intern (format nil "+~A+" name) '#:cl-glfw)
334 (if ,name +true+ +false+)))))))
335 (output-int-hints refresh-rate
336 accum-red-bits accum-green-bits accum-blue-bits
337 accum-alpha-bits
338 aux-buffers
339 fsaa-samples
340 opengl-version-major
341 opengl-version-minor
342 opengl-profile
343 opengl-core-profile
344 opengl-compat-profile)
345 (output-boolean-hints stereo
346 window-no-resize
347 opengl-forward-compat
348 opengl-debug-context))
349 (if (%open-window width height redbits greenbits bluebits alphabits depthbits stencilbits mode)
350 (when title (set-window-title title))
351 (error "Error initializing glfw window.")))
355 (defcfun+doc ("glfwOpenWindowHint" open-window-hint) :void ((target :int) (hint :int))
356 "target
357 Can be any of the constants in the table 3.1.
358 hint
359 An integer giving the value of the corresponding target (see table 3.1).
361 Description
362 The function sets additional properties for a window that is to be opened. For a hint to be registered, the
363 function must be called before calling glfw::OpenWindow. When the glfw::OpenWindow function is
364 called, any hints that were registered with the glfw::OpenWindowHint function are used for setting the
365 corresponding window properties, and then all hints are reset to their default values.
367 Notes
368 In order to determine the actual properties of an opened window, use glfw::GetWindowParam (after the
369 window has been opened).
370 +STEREO+ is a hard constraint. If stereo rendering is requested, but no stereo rendering capable
371 pixel formats / visuals are available, glfw::OpenWindow will fail.
372 The +REFRESH_RATE+ property should be used with caution. Most systems have default values
373 for monitor refresh rates that are optimal for the specific system. Specifying the refresh rate can
374 override these settings, which can result in suboptimal operation. The monitor may be unable to display
375 the resulting video signal, or in the worst case it may even be damaged!
378 (defcfun+doc ("glfwCloseWindow" close-window) :void ()
379 "The function closes an opened window and destroys the associated OpenGL context.")
381 (defmacro with-open-window ((&rest open-window-keys)
382 &body forms)
383 "Wraps forms such that there is an open window for them to execute in and cleans up the
384 window afterwards. An error is signalled if there was an error opening the window.
385 Takes the same parameters as open-window, with the addition of 'title' which will
386 set the window title after opening.
387 Wrapped in a block named glfw:with-open-window."
388 `(progn
389 (open-window ,@open-window-keys)
390 (unwind-protect
391 (block with-open-window ,@forms)
392 (when (= +true+ (glfw:get-window-param glfw:+opened+))
393 (close-window)))))
395 (defmacro with-init-window ((&rest open-window-keys)
396 &body forms)
397 "Wraps forms in with-init, with-open-window. Passes through the other arguments to open-window."
398 `(with-init
399 (with-open-window (,@open-window-keys)
400 ,@forms)))
402 (defmacro do-open-window ((&rest open-window-keys)
403 (&body setup-forms)
404 &body forms)
405 "High-level convenience macro for opening a window (given the optional window parameters),
406 setting the title given,
407 running setup-forms and then running forms in a loop, with calls to swap-buffers after each loop iteration.
408 The loop is in a block named do-open-window [so can be exited by a call to (return-from glfw:do-window)].
409 If the window is closed, the loop is also exited."
410 `(with-open-window (,@open-window-keys)
411 ,@setup-forms
412 (loop named do-open-window do
413 (progn
414 ,@forms
415 (glfw:swap-buffers)
416 (unless (= +true+ (glfw:get-window-param glfw:+opened+))
417 (return-from do-open-window))))))
419 (defmacro do-window ((&rest open-window-keys)
420 (&body setup-forms)
421 &body forms)
422 "High-level convenience macro for initializing glfw, opening a window (given the optional window parameters),
423 setting the title given,
424 running setup-forms and then running forms in a loop, with calls to swap-buffers after each loop iteration.
425 The loop is in a block named do-window [so can be exited by a call to (return-from glfw:do-window)].
426 If the window is closed, the loop is also exited."
427 `(block do-window
428 (with-init
429 (do-open-window (,@open-window-keys) (,@setup-forms) ,@forms))))
431 (defmacro define-callback-setter (c-name callback-prefix return-type (&body args) &key before-form after-form documentation)
432 (let* ((callback-name (intern (format nil "~A-CALLBACK" callback-prefix)))
433 (special-name (intern (format nil "*~S*" callback-name)))
434 (setter-name (intern (format nil "SET-~S" callback-name)))
435 (internal-setter-name (intern (format nil "%~S" setter-name))))
436 `(progn
437 (defparameter ,special-name nil)
438 (cffi:defcallback ,callback-name ,return-type ,args
439 (when ,special-name
440 (prog2
441 ,before-form
442 (funcall ,special-name ,@(mapcar #'car args))
443 ,after-form)))
444 (cffi:defcfun (,c-name ,internal-setter-name) :void (cbfun :pointer))
445 (defun ,setter-name (callback)
446 ,(format nil "GENERAL CL-GLFW CALLBACK NOTES
448 All callback setting functions can take either a pointer to a C function,
449 a function object, a function symbol, or nil to clear the callback function.
451 THIS CALLBACK FUNCTION
453 ~a" documentation)
454 (cl:cond
455 ((null callback)
456 (,internal-setter-name (cffi:null-pointer)))
457 ((symbolp callback)
458 (setf ,special-name callback)
459 (,internal-setter-name (cffi:callback ,callback-name)))
460 ((functionp callback)
461 (setf ,special-name callback)
462 (,internal-setter-name (cffi:callback ,callback-name)))
463 ((cffi:pointerp callback)
464 (,internal-setter-name callback))
465 (t (error "Not an acceptable callback. Must be foreign pointer, function object, function's symbol, or nil.")))))))
468 (define-callback-setter "glfwSetWindowCloseCallback" #:window-close :int ()
469 :documentation
471 Function that will be called when a user requests that the window should be
472 closed, typically by clicking the window close icon (e.g. the cross in the upper right corner of a
473 window under Microsoft Windows). The function should have the following type:
474 (function () integer)
476 The return value of the callback function indicates whether or not the window close action should continue. If the function returns
477 gl:+true+, the window will be closed. If the function returns gl:+false+, the window will not
478 be closed. If you give a CFFI callback returning glfw:boolean, you can use t and nil as return types.
480 Notes
481 Window close events are recorded continuously, but only reported when glfwPollEvents,
482 glfwWaitEvents or glfwSwapBuffers is called.
483 The OpenGL context is still valid when this function is called.
484 Note that the window close callback function is not called when glfwCloseWindow is called, but only
485 when the close request comes from the window manager.
486 Do not call glfwCloseWindow from a window close callback function. Close the window by returning
487 gl:+true+ from the function.
491 (defcfun+doc ("glfwSetWindowTitle" set-window-title) :void ((title :string))
492 "Parameters
493 title
494 Pointer to a null terminated ISO 8859-1 (8-bit Latin 1) string that holds the title of the window.
496 Description
497 The function changes the title of the opened window.
499 Notes
500 The title property of a window is often used in situations other
501 than for the window title, such as the title of an application icon
502 when it is in iconified state.")
504 (defcfun+doc ("glfwSetWindowSize" set-window-size) :void ((width :int) (height :int))
505 "Parameters
506 width
507 Width of the window.
508 height
509 Height of the window.
510 Return values
511 none
512 Description
514 The function changes the size of an opened window. The width and
515 height parameters denote the size of the client area of the
516 window (i.e. excluding any window borders and decorations). If the
517 window is in fullscreen mode, the video mode will be changed to a
518 resolution that closest matches the width and height parameters (the
519 number of color bits will not be changed).
521 Notes
523 The OpenGL context is guaranteed to be preserved after calling glfwSetWindowSize, even if the
524 video mode is changed.
527 (defcfun+doc ("glfwSetWindowPos" set-window-pos) :void ((x :int) (y :int))
528 "Parameters
530 Horizontal position of the window, relative to the upper left corner of the desktop.
532 Vertical position of the window, relative to the upper left corner of the desktop.
533 Return values
534 none
535 Description
536 The function changes the position of an opened window. It does not have any effect on a fullscreen
537 window.
540 (defcfun ("glfwGetWindowSize" %get-window-size) :void (width :pointer) (height :pointer))
541 (defun get-window-size ()
542 "The function is used for determining the size of an opened window. The returned values are dimensions
543 of the client area of the window (i.e. excluding any window borders and decorations).
544 (list width height)"
545 (cffi:with-foreign-objects ((width :int)
546 (height :int))
547 (%get-window-size width height)
548 (list (mem-ref width :int)
549 (mem-ref height :int))))
551 (define-callback-setter "glfwSetWindowSizeCallback" #:window-size :void ((width :int) (height :int))
552 :documentation
554 Function that will be called every time the window size changes. The
555 function should takes the arguments (width height) giving the new width and height of the window client area.
557 A window has to be opened for this function to have any effect.
558 Notes
559 Window size changes are recorded continuously, but only reported when glfwPollEvents,
560 glfwWaitEvents or glfwSwapBuffers is called. ")
562 (defcfun+doc ("glfwIconifyWindow" iconify-window) :void ()
563 "Iconify a window. If the window is in fullscreen mode, then the desktop video mode will be restored.")
565 (defcfun+doc ("glfwRestoreWindow" restore-window) :void ()
566 "Restore an iconified window. If the window that is restored is in fullscreen mode, then the fullscreen
567 video mode will be restored.")
569 (defcfun+doc ("glfwGetWindowParam" get-window-param) :int ((param :int))
570 "Parameters
571 param
572 A token selecting which parameter the function should return (see table 3.2).
574 Return values
576 The function returns different parameters depending on the value of
577 param. Table 3.2 lists valid param values, and their corresponding
578 return values.
580 Description
581 The function is used for acquiring various properties of an opened window.
583 Notes: GLFW_ACCELERATED is only supported under Windows. Other systems
584 will always return GL_TRUE. Under Windows, GLFW_ACCELERATED means that
585 the OpenGL renderer is a 3rd party renderer, rather than the fallback
586 Microsoft software OpenGL renderer. In other words, it is not a real
587 guarantee that the OpenGL renderer is actually hardware accelerated.
590 (defcfun+doc ("glfwSwapBuffers" swap-buffers) :void ()
591 "The function swaps the back and front color buffers of the window. If +AUTO_POLL_EVENTS+
592 is enabled (which is the default), glfwPollEvents is called before swapping the front and back buffers.")
595 (defcfun+doc ("glfwSwapInterval" swap-interval) :void ((interval :int))
596 "Parameters
597 interval
598 Minimum number of monitor vertical retraces between each buffer swap performed by
599 glfwSwapBuffers. If interval is zero, buffer swaps will not be synchronized to the vertical
600 refresh of the monitor (also known as VSync off).
602 Description
604 The function selects the minimum number of monitor vertical retraces
605 that should occur between two buffer swaps. If the selected swap
606 interval is one, the rate of buffer swaps will never be higher than
607 the vertical refresh rate of the monitor. If the selected swap
608 interval is zero, the rate of buffer swaps is only limited by the
609 speed of the software and the hardware.
611 Notes
613 This function will only have an effect on hardware and drivers that
614 support user selection of the swap interval. ")
617 (define-callback-setter "glfwSetWindowRefreshCallback" #:window-refresh :void ()
618 :documentation
620 Function that will be called when the window client area needs to be
621 refreshed. The function takes no arguments and returns nothing (void).
623 Description
625 The function selects which function to be called upon a window refresh
626 event, which occurs when any part of the window client area has been
627 damaged, and needs to be repainted (for instance, if a part of the
628 window that was previously occluded by another window has become
629 visible). A window has to be opened for this function to have any
630 effect.
632 Notes
633 Window refresh events are recorded continuously, but only reported when glfwPollEvents,
634 glfwWaitEvents or glfwSwapBuffers is called.
637 (defcstruct vidmode
638 (width :int)
639 (height :int)
640 (redbits :int)
641 (bluebits :int)
642 (greenbits :int))
644 (defcfun ("glfwGetVideoModes" %get-video-modes) :int (list :pointer) (maxcount :int))
646 (defun get-video-modes (maxcount)
647 "Parameters
648 maxcount
649 Maximum number of video modes that list vector can hold.
651 Return values
652 The function returns the number of detected video modes (this number will never exceed maxcount).
653 The list vector is filled out with the video modes that are supported by the system.
655 Description
656 The function returns a list of supported video modes. Each video mode is represented by a
657 list of the form:
658 (width height redbits greenbits bluebits)
660 Notes
661 The returned list is sorted, first by color depth (RedBits + GreenBits + BlueBits), and then by
662 resolution (Width * Height), with the lowest resolution, fewest bits per pixel mode first. "
663 (declare (optimize (debug 3)))
664 (with-foreign-object (list 'vidmode maxcount)
665 (let ((count (%get-video-modes list maxcount)))
666 (loop for i below count
667 collecting
668 (let ((mode (cffi:mem-aref list 'vidmode i)))
669 (list (foreign-slot-value mode 'vidmode 'width)
670 (foreign-slot-value mode 'vidmode 'height)
671 (foreign-slot-value mode 'vidmode 'redbits)
672 (foreign-slot-value mode 'vidmode 'greenbits)
673 (foreign-slot-value mode 'vidmode 'bluebits)))))))
675 (defcfun ("glfwGetDesktopMode" %get-desktop-mode) :void (mode :pointer))
676 (defun get-desktop-mode ()
677 "Parameters
678 mode
679 Pointer to a GLFWvidmode structure, which will be filled out by the function.
680 Return values
681 The GLFWvidmode structure pointed to by mode is filled out with the desktop video mode.
682 Description
683 The function returns the desktop video mode in a GLFWvidmode structure. See glfwGetVideoModes
684 for a definition of the GLFWvidmode structure.
685 Notes
686 The color depth of the desktop display is always reported as the number of bits for each individual color
687 component (red, green and blue), even if the desktop is not using an RGB or RGBA color format. For
688 instance, an indexed 256 color display may report RedBits = 3, GreenBits = 3 and BlueBits = 2, which
689 adds up to 8 bits in total.
690 The desktop video mode is the video mode used by the desktop, not the current video mode (which may
691 differ from the desktop video mode if the GLFW window is a fullscreen window).
693 (with-foreign-object (mode 'vidmode)
694 (%get-desktop-mode mode)
695 (list (foreign-slot-value mode 'vidmode 'width)
696 (foreign-slot-value mode 'vidmode 'height)
697 (foreign-slot-value mode 'vidmode 'redbits)
698 (foreign-slot-value mode 'vidmode 'greenbits)
699 (foreign-slot-value mode 'vidmode 'bluebits))))
701 (defcfun+doc ("glfwPollEvents" poll-events) :void ()
702 "Description
703 The function is used for polling for events, such as user input and window resize events. Upon calling
704 this function, all window states, keyboard states and mouse states are updated. If any related callback
705 functions are registered, these are called during the call to glfwPollEvents.
707 Notes
708 glfwPollEvents is called implicitly from glfwSwapBuffers if +AUTO_POLL_EVENTS+ is
709 enabled (default). Thus, if glfwSwapBuffers is called frequently, which is normally the case, there is
710 no need to call glfwPollEvents.
713 (defcfun+doc ("glfwWaitEvents" wait-events) :void ()
714 "Description
715 The function is used for waiting for events, such as user input and window resize events. Upon calling
716 this function, the calling thread will be put to sleep until any event appears in the event queue. When
717 events are ready, the events will be processed just as they are processed by glfwPollEvents.
718 If there are any events in the queue when the function is called, the function will behave exactly like
719 glfwPollEvents (i.e. process all messages and then return, without blocking the calling thread).
721 Notes
722 It is guaranteed that glfwWaitEvents will wake up on any event that can be processed by
723 glfw::PollEvents. However, glfwWaitEvents may wake up on events that are not processed or reported
724 by glfw::PollEvents too, and the function may behave differently on different systems. Do no make any
725 assumptions about when or why glfw::WaitEvents will return.
728 (defmacro key-int-to-symbol (key-form)
729 `(case ,key-form
730 ,@(sort
731 (loop for special-key in '("backspace" "del" "down" "end" "enter" "esc" "f1" "f10" "f11" "f12" "f13"
732 "f14" "f15" "f16" "f17" "f18" "f19" "f2" "f20" "f21" "f22" "f23" "f24" "f25"
733 "f3" "f4" "f5" "f6" "f7" "f8" "f9" "home" "insert" "kp-0" "kp-1" "kp-2" "kp-3"
734 "kp-4" "kp-5" "kp-6" "kp-7" "kp-8" "kp-9" "kp-add" "kp-decimal" "kp-divide"
735 "kp-enter" "kp-equal" "kp-multiply" "kp-subtract" "lalt" "lctrl" "left"
736 "lshift" "pagedown" "pageup" "ralt" "rctrl" "right" "rshift"
737 "special" "tab" "unknown" "up"
738 "kp-num-lock" "caps-lock" "scroll-lock" "pause" "lsuper" "rsuper" "menu")
739 collect
740 `(,(symbol-value (find-symbol (string-upcase (format nil "+key-~a+" special-key)) (find-package '#:glfw)))
741 ,(intern (string-upcase special-key) (find-package '#:keyword))))
742 #'(lambda (a b) (< (car a) (car b))))))
745 (defun lispify-key (key-int)
746 "Convert key-int from GLFW's integer representation to lisp characters if from 0 to 255, or keywords, if not within 0-255 inclusive."
747 (if (and (>= key-int 0) (< key-int 256))
748 (code-char key-int)
749 (key-int-to-symbol key-int)))
752 (defcfun+doc ("glfwGetKey" get-key) :int ((key :int))
753 "Parameters
755 A keyboard key identifier, which can be either an uppercase printable ISO 8859-1 (Latin 1)
756 character (e.g. 'A', '3' or '.'), or a special key identifier. Table 3.3 lists valid special key
757 identifiers.
758 Return values
759 The function returns +PRESS+ if the key is held down, or +RELEASE+ if the key is not
760 held down.
762 Description
763 The function queries the current state of a specific keyboard key. The physical location of each key
764 depends on the system keyboard layout setting.
766 Notes
767 The constant +KEY_SPACE+ is equal to 32, which is the ISO 8859-1 code for space.
768 Not all key codes are supported on all systems. Also, while some keys are available on some keyboard
769 layouts, they may not be available on other keyboard layouts.
770 For systems that do not distinguish between left and right versions of modifier keys (shift, alt and
771 control), the left version is used (e.g. +KEY_LSHIFT+)
772 A window must be opened for the function to have any effect, and glfw::PollEvents, glfw::WaitEvents or
773 glfw::SwapBuffers must be called before any keyboard events are recorded and reported by
774 glfw::GetKey.
778 (defun lispify-mouse-button (button-int)
779 "Convert button-int from GLFW's integer representation to a lisp keyword."
780 (case button-int
781 (#.glfw:+mouse-button-left+ :left)
782 (#.glfw:+mouse-button-middle+ :middle)
783 (#.glfw:+mouse-button-right+ :right)
784 (#.glfw:+mouse-button-4+ :button-4)
785 (#.glfw:+mouse-button-5+ :button-5)
786 (#.glfw:+mouse-button-6+ :button-6)
787 (#.glfw:+mouse-button-7+ :button-7)
788 (#.glfw:+mouse-button-8+ :button-8)))
791 (defcfun+doc ("glfwGetMouseButton" get-mouse-button) :int ((button :int))
792 "Parameters
793 button
794 A mouse button identifier, which can be one of the mouse button identifiers listed in table 3.4.
795 Return values
796 The function returns +PRESS+ if the mouse button is held down, or +RELEASE+ if the
797 mouse button is not held down.
798 Description
799 The function queries the current state of a specific mouse button.
800 Notes
801 A window must be opened for the function to have any effect, and glfw::PollEvents, glfw::WaitEvents or
802 glfw::SwapBuffers must be called before any mouse button events are recorded and reported by
803 glfw::GetMouseButton.
804 +MOUSE_BUTTON_LEFT+ is equal to +MOUSE_BUTTON_1+
805 +MOUSE_BUTTON_RIGHT+ is equal to +MOUSE_BUTTON_2+
806 +MOUSE_BUTTON_MIDDLE+ is equal to +MOUSE_BUTTON_3+
810 (defcfun+out+doc ("glfwGetMousePos" get-mouse-pos) :void ((:out xpos :int) (:out ypos :int))
811 "Return values
812 The function returns the current mouse position in xpos and ypos.
814 Description
815 The function returns the current mouse position. If the cursor is not hidden, the mouse position is the
816 cursor position, relative to the upper left corner of the window and limited to the client area of the
817 window. If the cursor is hidden, the mouse position is a virtual absolute position, not limited to any
818 boundaries except to those implied by the maximum number that can be represented by a signed integer
819 (normally -2147483648 to +2147483647).
821 Notes
822 A window must be opened for the function to have any effect, and glfw::PollEvents, glfw::WaitEvents or
823 glfw::SwapBuffers must be called before any mouse movements are recorded and reported by
824 glfw::GetMousePos.
828 (defcfun+doc ("glfwSetMousePos" set-mouse-pos) :void ((xpos :int) (ypos :int))
829 "Parameters
830 xpos
831 Horizontal position of the mouse.
832 ypos
833 Vertical position of the mouse.
835 Description
836 The function changes the position of the mouse. If the cursor is visible (not disabled), the cursor will be
837 moved to the specified position, relative to the upper left corner of the window client area. If the cursor
838 is hidden (disabled), only the mouse position that is reported by GLFW is changed.
841 (defcfun+doc ("glfwGetMouseWheel" get-mouse-wheel) :int ()
842 "Return values
843 The function returns the current mouse wheel position.
844 Description
845 The function returns the current mouse wheel position. The mouse wheel can be thought of as a third
846 mouse axis, which is available as a separate wheel or up/down stick on some mice.
847 Notes
848 A window must be opened for the function to have any effect, and glfw::PollEvents, glfw::WaitEvents or
849 glfw::SwapBuffers must be called before any mouse wheel movements are recorded and reported by
850 glfw::GetMouseWheel.
853 (defcfun+doc ("glfwSetMouseWheel" set-mouse-wheel) :void ((pos :int))
854 "Parameters
856 Position of the mouse wheel.
857 Description
858 The function changes the position of the mouse wheel.
862 (define-callback-setter "glfwSetKeyCallback" #:key :void ((key :int) (action :int))
863 :before-form (setf key (lispify-key key))
864 :documentation
866 Function that will be called every time a key is pressed or released.
867 Function should take the arguments (key action), where key is either a character,
868 if the key pressed was a member of iso-8859-1, or a keyword representing the key pressed if not.
869 See the GLFW manual, table 3.3 for special key identifiers. Action is either glfw:+press+ or
870 glfw:+release+. Use set-char-callback instead if you want to read just characters.
872 Description
873 The function selects which function to be called upon a keyboard key event. The callback function is
874 called every time the state of a single key is changed (from released to pressed or vice versa). The
875 reported keys are unaffected by any modifiers (such as shift or alt).
876 A window has to be opened for this function to have any effect.
878 Notes
879 Keyboard events are recorded continuously, but only reported when glfw::PollEvents, glfw::WaitEvents
880 or glfw::SwapBuffers is called.
882 (define-callback-setter "glfwSetCharCallback" #:char :void ((character :int) (action :int))
883 :before-form (setf character (code-char character))
884 :documentation
886 Function that will be called every time a printable character is generated by
887 the keyboard. The function should take the arguments (character action)
888 where character is a lisp character and action is either glfw:+press+ or glfw:+release+.
890 NB this makes the presumption that your lisp implementation will use Unicode for code-char.
892 Description
893 The function selects which function to be called upon a keyboard character event. The callback function
894 is called every time a key that results in a printable Unicode character is pressed or released. Characters
895 are affected by modifiers (such as shift or alt).
896 A window has to be opened for this function to have any effect.
898 Notes
899 Character events are recorded continuously, but only reported when glfw::PollEvents, glfw::WaitEvents
900 or glfw::SwapBuffers is called.
901 Control characters, such as tab and carriage return, are not reported to the character callback function,
902 since they are not part of the Unicode character set. Use the key callback function for such events (see
903 glfw::SetKeyCallback).
904 The Unicode character set supports character codes above 255, so never cast a Unicode character to an
905 eight bit data type (e.g. the C language char type) without first checking that the character code is less
906 than 256. Also note that Unicode character codes 0 to 255 are equal to ISO 8859-1 (Latin 1).
909 (define-callback-setter "glfwSetMouseButtonCallback" #:mouse-button :void ((button :int) (action :int))
910 :before-form (setf button (lispify-mouse-button button))
911 :documentation
913 Function that will be called every time a mouse button is pressed or released.
914 The function takes the arguments (button action), where button is a keyword symbol as returned by
915 lispify-mouse-button and action is either glfw:+press+ or glfw:+release+.
917 Description
918 The function selects which function to be called upon a mouse button event.
919 A window has to be opened for this function to have any effect.
921 Notes
922 Mouse button events are recorded continuously, but only reported when glfw::PollEvents,
923 glfw::WaitEvents or glfw::SwapBuffers is called.
924 +MOUSE_BUTTON_LEFT+ is equal to +MOUSE_BUTTON_1+
925 +MOUSE_BUTTON_RIGHT+ is equal to +MOUSE_BUTTON_2+
926 +MOUSE_BUTTON_MIDDLE+ is equal to +MOUSE_BUTTON_3+
928 (define-callback-setter "glfwSetMousePosCallback" #:mouse-pos :void ((x :int) (y :int))
929 :documentation
931 Function that will be called every time the mouse is moved.
932 The function takes the arguments (x y), where x and y are the current position of the mouse.
934 Description
935 The function selects which function to be called upon a mouse motion event.
936 A window has to be opened for this function to have any effect.
938 Notes
939 Mouse motion events are recorded continuously, but only reported when glfw::PollEvents,
940 glfw::WaitEvents or glfw::SwapBuffers is called.
943 (defparameter *mouse-wheel-cumulative* nil)
944 (define-callback-setter "glfwSetMouseWheelCallback" #:mouse-wheel :void ((pos :int))
945 :after-form (unless *mouse-wheel-cumulative* (glfw:set-mouse-wheel 0))
946 :documentation
948 Function that will be called every time the mouse wheel is moved.
949 The function takes one argument: the position of the mouse wheel.
950 This DIFFERS FROM GLFW's DEFAULT behaviour in that the position is
951 reset after every call to this function, effectively giving the delta.
952 As most programs are only interested in the delta anyway, this is thought
953 to save others recording the state of it again.
954 If you wish to have the original GLFW behaviour, set cl-glfw:*mouse-wheel-cumulative* to t.
956 Description
957 The function selects which function to be called upon a mouse wheel event.
958 A window has to be opened for this function to have any effect.
959 Notes
960 Mouse wheel events are recorded continuously, but only reported when glfw::PollEvents,
961 glfw::WaitEvents or glfw::SwapBuffers is called.
964 (defcfun+doc ("glfwGetJoystickParam" get-joystick-param) :int ((joy :int) (param :int))
965 "Parameters
967 A joystick identifier, which should be +JOYSTICK_n+ where n is in the range 1 to 16.
968 param
969 A token selecting which parameter the function should return (see table 3.5).
970 Return values
971 The function returns different parameters depending on the value of param. Table 3.5 lists valid param
972 values, and their corresponding return values.
973 Description
974 The function is used for acquiring various properties of a joystick.
975 Notes
976 The joystick information is updated every time the function is called.
977 No window has to be opened for joystick information to be valid.
980 (defcfun ("glfwGetJoystickPos" %get-joystick-pos) :int (joy :int) (pos :pointer) (numaxes :int))
982 (defun get-joystick-pos (joy numaxes)
983 "Parameters
985 A joystick identifier, which should be +JOYSTICK_n+ where n is in the range 1 to 16.
986 numaxes
987 Specifies how many axes should be returned.
988 Return values
989 An list that will hold the positional values for all requested axes.
990 If the joystick is not supported or connected, the function will
991 return nil.
993 Description
994 The function queries the current position of one or more axes of a joystick. The positional values are
995 returned in an array, where the first element represents the first axis of the joystick (normally the X
996 axis). Each position is in the range -1.0 to 1.0. Where applicable, the positive direction of an axis is
997 right, forward or up, and the negative direction is left, back or down.
998 If numaxes exceeds the number of axes supported by the joystick, or if the joystick is not available, the
999 unused elements in the pos array will be set to 0.0 (zero).
1001 Notes
1002 The joystick state is updated every time the function is called, so there is no need to call glfw::PollEvents
1003 or glfw::WaitEvents for joystick state to be updated.
1004 Use glfw::GetJoystickParam to retrieve joystick capabilities, such as joystick availability and number of
1005 supported axes.
1006 No window has to be opened for joystick input to be valid.
1008 (with-foreign-object (pos :float numaxes)
1009 (let ((numaxes (%get-joystick-pos joy pos numaxes)))
1010 (loop for i below numaxes collecting (mem-aref pos :float i)))))
1013 (defcfun ("glfwGetJoystickButtons" %get-joystick-buttons) :int (joy :int) (buttons :pointer) (numbuttons :int))
1014 (defun get-joystick-buttons (joy numbuttons)
1015 "Parameters
1017 A joystick identifier, which should be +JOYSTICK_n+ where n is in the range 1 to 16.
1018 numbuttons
1019 Specifies how many buttons should be returned.
1020 Return values
1021 A list that will hold the button states for all requested buttons.
1022 The function returns the number of actually returned buttons. This is the minimum of numbuttons and
1023 the number of buttons supported by the joystick. If the joystick is not supported or connected, the
1024 function will return 0 (zero).
1026 Description
1027 The function queries the current state of one or more buttons of a joystick. The button states are
1028 returned in an array, where the first element represents the first button of the joystick. Each state can be
1029 either +PRESS+ or +RELEASE+
1030 If numbuttons exceeds the number of buttons supported by the joystick, or if the joystick is not
1031 available, the unused elements in the buttons array will be set to +RELEASE+
1033 Notes
1034 The joystick state is updated every time the function is called, so there is no need to call glfw::PollEvents
1035 or glfw::WaitEvents for joystick state to be updated.
1036 Use glfw::GetJoystickParam to retrieve joystick capabilities, such as joystick availability and number of
1037 supported buttons.
1038 No window has to be opened for joystick input to be valid.
1040 (with-foreign-object (buttons :unsigned-char numbuttons)
1041 (let ((numbuttons (%get-joystick-buttons joy buttons numbuttons)))
1042 (loop for i below numbuttons collecting (mem-aref buttons :unsigned-char i)))))
1045 (defcfun+doc ("glfwGetTime" get-time) :double ()
1046 "Return values
1047 The function returns the value of the high precision timer. The time is measured in seconds, and is
1048 returned as a double precision floating point value.
1050 Description
1051 The function returns the state of a high precision timer. Unless the timer has been set by the
1052 glfw::SetTime function, the time is measured as the number of seconds that have passed since glfw::Init
1053 was called.
1055 Notes
1056 The resolution of the timer depends on which system the program is running on. The worst case
1057 resolution is somewhere in the order of 10 ms, while for most systems the resolution should be better
1058 than 1us.
1061 (defcfun+doc ("glfwSetTime" set-time) :void ((time :double))
1062 "Parameters
1063 time
1064 Time (in seconds) that the timer should be set to.
1066 Description
1067 The function sets the current time of the high precision timer to the specified time. Subsequent calls to
1068 glfw::GetTime will be relative to this time. The time is given in seconds.
1071 (defcfun+doc ("glfwSleep" sleep) :void ((time :double))
1072 "Parameters
1073 time
1074 Time, in seconds, to sleep.
1076 Description
1077 The function puts the calling thread to sleep for the requested period of time. Only the calling thread is
1078 put to sleep. Other threads within the same process can still execute.
1080 Notes
1081 There is usually a system dependent minimum time for which it is possible to sleep. This time is
1082 generally in the range 1 ms to 20 ms, depending on thread sheduling time slot intervals etc. Using a
1083 shorter time as a parameter to glfw::Sleep can give one of two results: either the thread will sleep for the
1084 minimum possible sleep time, or the thread will not sleep at all (glfw::Sleep returns immediately). The
1085 latter should only happen when very short sleep times are specified, if at all. ")
1087 (defcstruct image
1088 (width :int)
1089 (height :int)
1090 (format :int)
1091 (bytes-per-pixel :int)
1092 (data :pointer))
1094 (defcfun+doc ("glfwReadImage" read-image) boolean
1095 ((name :string) (img image) (flags :int))
1096 "Parameters
1097 name
1098 A null terminated ISO 8859-1 string holding the name of the file that should be read.
1100 Pointer to a GLFWimage struct, which will hold the information about the loaded image (if the
1101 read was successful).
1102 flags
1103 Flags for controlling the image reading process. Valid flags are listed in table 3.6
1104 Return values
1105 The function returns t if the image was loaded successfully. Otherwise nil is
1106 returned.
1107 Description
1108 The function reads an image from the file specified by the parameter name and returns the image
1109 information and data in a GLFWimage structure, which has the following definition:
1111 typedef struct {
1112 int Width, Height; // Image dimensions
1113 int Format; // OpenGL pixel format
1114 int BytesPerPixel; // Number of bytes per pixel
1115 unsigned char *Data; // Pointer to pixel data
1116 } GLFWimage;
1118 Width and Height give the dimensions of the image. Format specifies an OpenGL pixel format,
1119 which can be GL_LUMINANCE or GL_ALPHA (for gray scale images), GL_RGB or GL_RGBA.
1120 BytesPerPixel specifies the number of bytes per pixel. Data is a pointer to the actual pixel data.
1122 By default the read image is rescaled to the nearest larger 2m ? 2n resolution using bilinear
1123 interpolation, if necessary, which is useful if the image is to be used as an OpenGL texture. This
1124 behavior can be disabled by setting the GLFW_NO_RESCALE_BIT flag.
1125 Unless the flag GLFW_ORIGIN_UL_BIT is set, the first pixel in img->Data is the lower left corner of
1126 the image. If the flag GLFW_ORIGIN_UL_BIT is set, however, the first pixel is the upper left corner.
1127 For single component images (i.e. gray scale), Format is set to GL_ALPHA if the flag
1129 +ALPHA_MAP_BIT+ flag is set, otherwise Format is set to GL_LUMINANCE.
1130 Notes
1131 glfw::ReadImage supports the Truevision Targa version 1 file format (.TGA). Supported pixel formats
1132 are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color + alpha.
1133 Paletted images are translated into true color or true color + alpha pixel formats.
1134 Please note that OpenGL 1.0 does not support single component alpha maps, so do not use images
1135 with Format = GL_ALPHA directly as textures under OpenGL 1.0.
1138 (defcfun+doc ("glfwReadMemoryImage" read-memory-image) boolean
1139 ((data :pointer) (size :long) (img image) (flags :int))
1140 "Parameters
1141 data
1142 The memory buffer holding the contents of the file that should be read.
1143 size
1144 The size, in bytes, of the memory buffer.
1146 Pointer to a GLFWimage struct, which will hold the information about the loaded image (if the
1147 read was successful).
1148 flags
1149 Flags for controlling the image reading process. Valid flags are listed in table 3.6
1150 Return values
1151 The function returns t if the image was loaded successfully. Otherwise nil is
1152 returned.
1153 Description
1154 The function reads an image from the memory buffer specified by the parameter data and returns the
1155 image information and data in a GLFWimage structure, which has the following definition:
1157 typedef struct {
1158 int Width, Height; // Image dimensions
1159 int Format; // OpenGL pixel format
1160 int BytesPerPixel; // Number of bytes per pixel
1161 unsigned char *Data; // Pointer to pixel data
1162 } GLFWimage;
1164 Width and Height give the dimensions of the image. Format specifies an OpenGL pixel format,
1165 which can be GL_LUMINANCE or GL_ALPHA (for gray scale images), GL_RGB or GL_RGBA.
1166 BytesPerPixel specifies the number of bytes per pixel. Data is a pointer to the actual pixel data.
1168 By default the read image is rescaled to the nearest larger 2m ? 2n resolution using bilinear
1169 interpolation, if necessary, which is useful if the image is to be used as an OpenGL texture. This
1170 behavior can be disabled by setting the GLFW_NO_RESCALE_BIT flag.
1171 Unless the flag GLFW_ORIGIN_UL_BIT is set, the first pixel in img->Data is the lower left corner of
1172 the image. If the flag GLFW_ORIGIN_UL_BIT is set, however, the first pixel is the upper left corner.
1173 For single component images (i.e. gray scale), Format is set to GL_ALPHA if the flag
1174 +ALPHA_MAP_BIT+ flag is set, otherwise Format is set to GL_LUMINANCE.
1175 Notes
1176 glfw::ReadMemoryImage supports the Truevision Targa version 1 file format (.TGA). Supported pixel
1177 formats are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color +
1178 alpha.
1179 Paletted images are translated into true color or true color + alpha pixel formats.
1180 Please note that OpenGL 1.0 does not support single component alpha maps, so do not use images
1181 with Format = GL_ALPHA directly as textures under OpenGL 1.0.
1184 (defcfun+doc ("glfwFreeImage" free-image) :void ((img image))
1185 "Parameters
1187 Pointer to a GLFWimage struct.
1188 Description
1189 The function frees any memory occupied by a loaded image, and clears all the fields of the GLFWimage
1190 struct. Any image that has been loaded by the glfw::ReadImage function should be deallocated using
1191 this function, once the image is not needed anymore. ")
1193 (defcfun+doc ("glfwLoadTexture2D" load-texture-2d) boolean ((name :string) (flags :int))
1194 "Parameters
1195 name
1196 An ISO 8859-1 string holding the name of the file that should be loaded.
1197 flags
1198 Flags for controlling the texture loading process. Valid flags are listed in table 3.7.
1199 Return values
1200 The function returns t if the texture was loaded successfully. Otherwise nil is
1201 returned.
1203 Description
1205 The function reads an image from the file specified by the parameter
1206 name and uploads the image to OpenGL texture memory (using the
1207 glTexImage2D function). If the GLFW_BUILD_MIPMAPS_BIT flag is set,
1208 all mipmap levels for the loaded texture are generated and uploaded to
1209 texture memory. Unless the flag +ORIGIN_UL_BIT+ is set, the origin of
1210 the texture is the lower left corner of the loaded image. If the flag
1211 +ORIGIN_UL_BIT+ is set, however, the first pixel is the upper left
1212 corner. For single component images (i.e. gray scale), the texture is
1213 uploaded as an alpha mask if the flag +ALPHA_MAP_BIT+ flag is set,
1214 otherwise it is uploaded as a luminance texture.
1216 Notes
1217 glfw::LoadTexture2D supports the Truevision Targa version 1 file format (.TGA). Supported pixel
1218 formats are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color +
1219 alpha.
1220 Paletted images are translated into true color or true color + alpha pixel formats.
1221 The read texture is always rescaled to the nearest larger 2m ? 2n resolution using bilinear interpolation,
1222 if necessary, since OpenGL requires textures to have a 2m ? 2n resolution.
1223 If the GL_SGIS_generate_mipmap extension, which is usually hardware accelerated, is supported by
1224 the OpenGL implementation it will be used for mipmap generation. Otherwise the mipmaps will be
1225 generated by GLFW in software.
1227 Since OpenGL 1.0 does not support single component alpha maps, alpha map textures are converted
1228 to RGBA format under OpenGL 1.0 when the GLFW_ALPHA_MAP_BIT flag is set and the loaded
1229 texture is a single component texture. The red, green and blue components are set to 1.0.
1232 (defcfun+doc ("glfwLoadMemoryTexture2D" load-memory-texture-2d) boolean
1233 ((data :pointer) (size :long) (flags :int))
1234 "Parameters
1235 data
1236 The memory buffer holding the contents of the file that should be loaded.
1237 size
1238 The size, in bytes, of the memory buffer.
1239 flags
1240 Flags for controlling the texture loading process. Valid flags are listed in table 3.7.
1241 Return values
1242 The function returns t if the texture was loaded successfully. Otherwise nil is
1243 returned.
1245 Description
1246 The function reads an image from the memory buffer specified by the parameter data and uploads the
1247 image to OpenGL texture memory (using the glTexImage2D function).
1248 If the GLFW_BUILD_MIPMAPS_BIT flag is set, all mipmap levels for the loaded texture are
1249 generated and uploaded to texture memory.
1250 Unless the flag +ORIGIN_UL_BIT+ is set, the origin of the texture is the lower left corner of the
1251 loaded image. If the flag +ORIGIN_UL_BIT+ is set, however, the first pixel is the upper left
1252 corner.
1253 For single component images (i.e. gray scale), the texture is uploaded as an alpha mask if the flag
1254 +ALPHA_MAP_BIT+ flag is set, otherwise it is uploaded as a luminance texture.
1256 Notes
1257 glfw::LoadMemoryTexture2D supports the Truevision Targa version 1 file format (.TGA). Supported
1258 pixel formats are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color
1259 + alpha.
1260 Paletted images are translated into true color or true color + alpha pixel formats.
1261 The read texture is always rescaled to the nearest larger 2m ? 2n resolution using bilinear interpolation,
1262 if necessary, since OpenGL requires textures to have a 2m ? 2n resolution.
1263 If the GL_SGIS_generate_mipmap extension, which is usually hardware accelerated, is supported by
1264 the OpenGL implementation it will be used for mipmap generation. Otherwise the mipmaps will be
1265 generated by GLFW in software.
1267 Since OpenGL 1.0 does not support single component alpha maps, alpha map textures are converted
1268 to RGBA format under OpenGL 1.0 when the GLFW_ALPHA_MAP_BIT flag is set and the loaded
1269 texture is a single component texture. The red, green and blue components are set to 1.0.
1273 (defcfun+doc ("glfwLoadTextureImage2D" load-texture-image-2d) boolean ((img image)
1274 (flags :int))
1275 "Parameters
1277 Pointer to a GLFWimage struct holding the information about the image to be loaded.
1278 flags
1279 Flags for controlling the texture loading process. Valid flags are listed in table 3.7.
1280 Return values
1281 The function returns t if the texture was loaded successfully. Otherwise nil is
1282 returned.
1284 Description
1285 The function uploads the image specified by the parameter img to OpenGL texture memory (using
1286 the glTexImage2D function).
1287 If the +BUILD_MIPMAPS_BIT+ flag is set, all mipmap levels for the loaded texture are
1288 generated and uploaded to texture memory.
1289 Unless the flag +ORIGIN_UL_BIT+ is set, the origin of the texture is the lower left corner of the
1290 loaded image. If the flag +ORIGIN_UL_BIT+ is set, however, the first pixel is the upper left
1291 corner.
1292 For single component images (i.e. gray scale), the texture is uploaded as an alpha mask if the flag
1293 +ALPHA_MAP_BIT+ flag is set, otherwise it is uploaded as a luminance texture.
1295 Notes
1296 glfw::LoadTextureImage2D supports the Truevision Targa version 1 file format (.TGA). Supported
1297 pixel formats are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color
1298 + alpha.
1299 Paletted images are translated into true color or true color + alpha pixel formats.
1300 The read texture is always rescaled to the nearest larger 2m ? 2n resolution using bilinear interpolation,
1301 if necessary, since OpenGL requires textures to have a 2m ? 2n resolution.
1302 If the GL_SGIS_generate_mipmap extension, which is usually hardware accelerated, is supported by
1303 the OpenGL implementation it will be used for mipmap generation. Otherwise the mipmaps will be
1304 generated by GLFW in software.
1306 Since OpenGL 1.0 does not support single component alpha maps, alpha map textures are converted
1307 to RGBA format under OpenGL 1.0 when the GLFW_ALPHA_MAP_BIT flag is set and the loaded
1308 texture is a single component texture. The red, green and blue components are set to 1.0. ")
1311 (defcfun+doc ("glfwExtensionSupported" extension-supported) boolean ((extension :string))
1312 "Parameters
1313 extension
1314 A null terminated ISO 8859-1 string containing the name of an OpenGL extension.
1315 Return values
1316 The function returns t if the extension is supported. Otherwise it returns nil.
1317 Description
1318 The function does a string search in the list of supported OpenGL extensions to find if the specified
1319 extension is listed.
1320 Notes
1322 An OpenGL context must be created before this function can be called (i.e. an OpenGL window
1323 must have been opened with glfwOpenWindow).
1324 In addition to checking for OpenGL extensions, GLFW also checks for extensions in the operating
1325 system ?glue API?, such as WGL extensions under Windows and glX extensions under the X Window
1326 System.
1329 (defcfun+doc ("glfwGetProcAddress" get-proc-address) :pointer ((procname :string))
1330 "Parameters
1331 procname
1332 A null terminated ISO 8859-1 string containing the name of an OpenGL extension function.
1333 Return values
1334 The function returns the pointer to the specified OpenGL function if it is supported, otherwise
1335 NULL is returned.
1336 Description
1337 The function acquires the pointer to an OpenGL extension function. Some (but not all) OpenGL
1338 extensions define new API functions, which are usually not available through normal linking. It is
1339 therefore necessary to get access to those API functions at runtime.
1340 Notes
1342 An OpenGL context must be created before this function can be called (i.e. an OpenGL window
1343 must have been opened with glfwOpenWindow).
1344 Some systems do not support dynamic function pointer retrieval, in which case glfwGetProcAddress
1345 will always return NULL.
1348 (defcfun+out+doc ("glfwGetGLVersion" get-gl-version) :void ((:out major :int)
1349 (:out minor :int)
1350 (:out rev :int))
1351 "Return values
1352 The function returns the major and minor version numbers and the revision for the currently used
1353 OpenGL implementation as a list (major minor rev).
1355 Description
1356 The function returns the OpenGL implementation version. This is a convenient function that parses
1357 the version number information from the string returned by calling
1358 glGetString( GL_VERSION ). The OpenGL version information can be used to determine
1359 what functionality is supported by the used OpenGL implementation.
1361 Notes
1362 An OpenGL context must be created before this function can be called (i.e. an OpenGL window
1363 must have been opened with glfwOpenWindow). ")
1365 (defctype thread :int)
1366 (defctype threadfun :pointer)
1367 (defctype mutex :pointer)
1368 (defctype cond :pointer)
1370 (defcfun+doc ("glfwCreateThread" create-thread) thread ((fun threadfun) (arg :pointer) )
1371 "Parameters
1373 A pointer to a function that acts as the entry point for the new thread. The function should have
1374 the following C language prototype:
1375 void GLFWCALL functionname( void *arg );
1376 Where functionname is the name of the thread function, and arg is the user supplied argument
1377 (see below).
1379 An arbitrary argument for the thread. arg will be passed as the argument to the thread function
1380 pointed to by fun. For instance, arg can point to data that is to be processed by the thread.
1381 Return values
1382 The function returns a thread identification number if the thread was created successfully. This number
1383 is always positive. If the function fails, a negative number is returned.
1384 Description
1385 The function creates a new thread, which executes within the same address space as the calling process.
1386 The thread entry point is specified with the fun argument.
1387 Once the thread function fun returns, the thread dies.
1388 Notes
1389 Even if the function returns a positive thread ID, indicating that the thread was created successfully, the
1390 thread may be unable to execute, for instance if the thread start address is not a valid thread entry point.
1392 (defcfun+doc ("glfwDestroyThread" destroy-thread) :void ((id thread))
1393 "Parameters
1395 A thread identification handle, which is returned by glfw::CreateThread or glfw::GetThreadID.
1396 Description
1397 The function kills a running thread and removes it from the thread list.
1398 Notes
1399 This function is a very dangerous operation, which may interrupt a thread in the middle of an important
1400 operation, and its use is discouraged. You should always try to end a thread in a graceful way using
1401 thread communication, and use glfw::WaitThread in order to wait for the thread to die.
1403 (defcfun+doc ("glfwWaitThread" wait-thread) boolean ((id thread) (waitmode :int) )
1404 "Parameters
1406 A thread identification handle, which is returned by glfw::CreateThread or glfw::GetThreadID.
1407 waitmode
1408 Can be either +WAIT+ or +NOWAIT+
1409 Return values
1410 The function returns t if the specified thread died after the function was called, or the thread
1411 did not exist, in which case glfw::WaitThread will return immediately regardless of waitmode. The
1412 function returns nil if waitmode is +NOWAIT+ and the specified thread exists and is still
1413 running.
1415 (defcfun+doc ("glfwGetThreadID" get-thread-id) thread ()
1416 "Return values
1417 The function returns a thread identification handle for the calling thread.
1418 Description
1419 The function determines the thread ID for the calling thread. The ID is the same value as was returned
1420 by glfw::CreateThread when the thread was created.
1423 (defcfun+doc ("glfwCreateMutex" create-mutex) mutex ()
1424 "Return values
1425 The function returns a mutex handle, or NULL if the mutex could not be created.
1426 Description
1427 The function creates a mutex object, which can be used to control access to data that is shared between
1428 threads.
1430 (defcfun+doc ("glfwDestroyMutex" destroy-mutex) :void ((mutex mutex))
1431 "Parameters
1432 mutex
1433 A mutex object handle.
1434 Description
1435 The function destroys a mutex object. After a mutex object has been destroyed, it may no longer be
1436 used by any thread.
1438 (defcfun+doc ("glfwLockMutex" lock-mutex) :void ((mutex mutex))
1439 "Parameters
1440 mutex
1441 A mutex object handle.
1442 Description
1443 The function will acquire a lock on the selected mutex object. If the mutex is already locked by another
1444 thread, the function will block the calling thread until it is released by the locking thread. Once the
1445 function returns, the calling thread has an exclusive lock on the mutex. To release the mutex, call
1446 glfw::UnlockMutex.
1448 (defcfun+doc ("glfwUnlockMutex" unlock-mutex) :void ((mutex mutex))
1449 "Parameters
1450 mutex
1451 A mutex object handle.
1452 Description
1453 The function releases the lock of a locked mutex object.
1456 (defmacro with-lock-mutex (mutex &body forms)
1457 "Parameters
1458 mutex
1459 A mutex object handle.
1460 forms
1461 Body of code to execute
1462 Description
1463 This macro will acquire a lock on the selected mutex object using glfw::LockMutex and release it afterwards
1464 using glfw::UnlockMutex.
1465 So, forms will not execute until an exclusive lock is held.
1466 The lock is then released when the stack is unwound."
1467 (let ((smutex (gensym "MUTEX-")))
1468 `(let ((,smutex ,mutex))
1469 (glfw:lock-mutex ,smutex)
1470 (unwind-protect (progn ,@forms)
1471 (glfw:unlock-mutex ,smutex)))))
1473 (defcfun+doc ("glfwCreateCond" create-cond) cond ()
1474 "Return values
1475 The function returns a condition variable handle, or NULL if the condition variable could not be
1476 created.
1477 Description
1478 The function creates a condition variable object, which can be used to synchronize threads.
1480 (defcfun+doc ("glfwDestroyCond" destroy-cond) :void ((cond cond))
1481 "Parameters
1482 cond
1483 A condition variable object handle.
1484 Description
1485 The function destroys a condition variable object. After a condition variable object has been destroyed,
1486 it may no longer be used by any thread.
1488 (defcfun+doc ("glfwWaitCond" wait-cond) :void ((cond cond) (mutex mutex) (timeout :double))
1489 " arameters
1490 cond
1491 A condition variable object handle.
1492 mutex
1493 A mutex object handle.
1494 timeout
1495 Maximum time to wait for the condition variable. The parameter can either be a positive time (in
1496 seconds), or +INFINITY+
1497 Description
1498 The function atomically unlocks the mutex specified by mutex, and waits for the condition variable cond
1499 to be signaled. The thread execution is suspended and does not consume any CPU time until the
1500 condition variable is signaled or the amount of time specified by timeout has passed. If timeout is
1501 +INFINITY+ glfw::WaitCond will wait forever for cond to be signaled. Before returning to the
1502 calling thread, glfw::WaitCond automatically re-acquires the mutex.
1503 Notes
1504 The mutex specified by mutex must be locked by the calling thread before entrance to glfw::WaitCond.
1505 A condition variable must always be associated with a mutex, to avoid the race condition where a thread
1506 prepares to wait on a condition variable and another thread signals the condition just before the first
1507 thread actually waits on it.
1509 (defcfun+doc ("glfwSignalCond" signal-cond) :void ((cond cond))
1510 "Parameters
1511 cond
1512 A condition variable object handle.
1513 Description
1514 The function restarts one of the threads that are waiting on the condition variable cond. If no threads are
1515 waiting on cond, nothing happens. If several threads are waiting on cond, exactly one is restarted, but it
1516 is not specified which.
1517 Notes
1518 When several threads are waiting for the condition variable, which thread is started depends on
1519 operating system scheduling rules, and may vary from system to system and from time to time.
1521 (defcfun+doc ("glfwBroadcastCond" broadcast-cond) :void ((cond cond))
1522 "Parameters
1523 cond
1524 A condition variable object handle.
1525 Description
1526 The function restarts all the threads that are waiting on the condition variable cond. If no threads are
1527 waiting on cond, nothing happens.
1528 Notes
1529 When several threads are waiting for the condition variable, the order in which threads are started
1530 depends on operating system scheduling rules, and may vary from system to system and from time to
1531 time.
1534 (defcfun+doc ("glfwGetNumberOfProcessors" get-number-of-processors) :int ()
1535 "Return values
1536 The function returns the number of active processors in the system.
1537 Description
1538 The function determines the number of active processors in the system.
1539 Notes
1540 Systems with several logical processors per physical processor, also known as SMT (Symmetric Multi
1541 Threading) processors, will report the number of logical processors.
1543 (defcfun+doc ("glfwEnable" enable) :void ((token :int))
1544 "Parameters
1545 token
1546 A value specifying a feature to enable or disable. Valid tokens are listed in table 3.8.
1547 Return values
1548 none
1549 Description
1550 glfw::Enable is used to enable a certain feature, while glfw::Disable is used to disable it. Below follows a
1551 description of each feature.
1552 +AUTO_POLL_EVENTS+
1553 When +AUTO_POLL_EVENTS+ is enabled, glfw::PollEvents is automatically called each time
1554 that glfw::SwapBuffers is called.
1555 When +AUTO_POLL_EVENTS+ is disabled, calling glfw::SwapBuffers will not result in a call to
1556 glfw::PollEvents. This can be useful if glfw::SwapBuffers needs to be called from within a callback
1557 function, since calling glfw::PollEvents from a callback function is not allowed.
1558 +KEY_REPEAT+
1559 When +KEY_REPEAT+ is enabled, the key and character callback functions are called repeatedly
1560 when a key is held down long enough (according to the system key repeat configuration).
1561 When +KEY_REPEAT+ is disabled, the key and character callback functions are only called once
1562 when a key is pressed (and once when it is released).
1563 +MOUSE_CURSOR+
1564 When +MOUSE_CURSOR+ is enabled, the mouse cursor is visible, and mouse coordinates are
1565 relative to the upper left corner of the client area of the GLFW window. The coordinates are limited to
1566 the client area of the window.
1567 When +MOUSE_CURSOR+ is disabled, the mouse cursor is invisible, and mouse coordinates are
1568 not limited to the drawing area of the window. It is as if the mouse coordinates are recieved directly
1569 from the mouse, without being restricted or manipulated by the windowing system.
1570 +STICKY_KEYS+
1571 When +STICKY_KEYS+ is enabled, keys which are pressed will not be released until they are
1572 physically released and checked with glfw::GetKey. This behavior makes it possible to catch keys that
1573 were pressed and then released again between two calls to glfw::PollEvents, glfw::WaitEvents or
1574 glfw::SwapBuffers, which would otherwise have been reported as released. Care should be taken when
1575 using this mode, since keys that are not checked with glfw::GetKey will never be released. Note also that
1576 enabling +STICKY_KEYS+ does not affect the behavior of the keyboard callback functionality.
1577 When +STICKY_KEYS+ is disabled, the status of a key that is reported by glfw::GetKey is always
1578 the physical state of the key. Disabling +STICKY_KEYS+ also clears the sticky information for
1579 all keys.
1580 +STICKY_MOUSE_BUTTONS+
1581 When +STICKY_MOUSE_BUTTONS+ is enabled, mouse buttons that are pressed will not be
1582 released until they are physically released and checked with glfw::GetMouseButton. This behavior
1583 makes it possible to catch mouse buttons which were pressed and then released again between two calls
1584 to glfw::PollEvents, glfw::WaitEvents or glfw::SwapBuffers, which would otherwise have been reported
1585 as released. Care should be taken when using this mode, since mouse buttons that are not checked with
1586 glfw::GetMouseButton will never be released. Note also that enabling
1587 +STICKY_MOUSE_BUTTONS+ does not affect the behavior of the mouse button callback
1588 functionality.
1589 When +STICKY_MOUSE_BUTTONS+ is disabled, the status of a mouse button that is reported
1590 by glfw::GetMouseButton is always the physical state of the mouse button. Disabling
1591 +STICKY_MOUSE_BUTTONS+ also clears the sticky information for all mouse buttons.
1592 +SYSTEM_KEYS+
1593 When +SYSTEM_KEYS+ is enabled, pressing standard system key combinations, such as
1594 ALT+TAB under Windows, will give the normal behavior. Note that when ALT+TAB is issued under
1595 Windows in this mode so that the GLFW application is deselected when GLFW is operating in
1596 fullscreen mode, the GLFW application window will be minimized and the video mode will be set to
1597 the original desktop mode. When the GLFW application is re-selected, the video mode will be set to
1598 the GLFW video mode again.
1599 When +SYSTEM_KEYS+ is disabled, pressing standard system key combinations will have no
1600 effect, since those key combinations are blocked by GLFW. This mode can be useful in situations when
1601 the GLFW program must not be interrupted (normally for games in fullscreen mode).
1603 (defcfun+doc ("glfwDisable" disable) :void ((token :int))
1604 "Parameters
1605 token
1606 A value specifying a feature to enable or disable. Valid tokens are listed in table 3.8.
1607 Return values
1608 none
1609 Description
1610 glfw::Enable is used to enable a certain feature, while glfw::Disable is used to disable it. Below follows a
1611 description of each feature.
1612 +AUTO_POLL_EVENTS+
1613 When +AUTO_POLL_EVENTS+ is enabled, glfw::PollEvents is automatically called each time
1614 that glfw::SwapBuffers is called.
1615 When +AUTO_POLL_EVENTS+ is disabled, calling glfw::SwapBuffers will not result in a call to
1616 glfw::PollEvents. This can be useful if glfw::SwapBuffers needs to be called from within a callback
1617 function, since calling glfw::PollEvents from a callback function is not allowed.
1618 +KEY_REPEAT+
1619 When +KEY_REPEAT+ is enabled, the key and character callback functions are called repeatedly
1620 when a key is held down long enough (according to the system key repeat configuration).
1621 When +KEY_REPEAT+ is disabled, the key and character callback functions are only called once
1622 when a key is pressed (and once when it is released).
1623 +MOUSE_CURSOR+
1624 When +MOUSE_CURSOR+ is enabled, the mouse cursor is visible, and mouse coordinates are
1625 relative to the upper left corner of the client area of the GLFW window. The coordinates are limited to
1626 the client area of the window.
1627 When +MOUSE_CURSOR+ is disabled, the mouse cursor is invisible, and mouse coordinates are
1628 not limited to the drawing area of the window. It is as if the mouse coordinates are recieved directly
1629 from the mouse, without being restricted or manipulated by the windowing system.
1630 +STICKY_KEYS+
1631 When +STICKY_KEYS+ is enabled, keys which are pressed will not be released until they are
1632 physically released and checked with glfw::GetKey. This behavior makes it possible to catch keys that
1633 were pressed and then released again between two calls to glfw::PollEvents, glfw::WaitEvents or
1634 glfw::SwapBuffers, which would otherwise have been reported as released. Care should be taken when
1635 using this mode, since keys that are not checked with glfw::GetKey will never be released. Note also that
1636 enabling +STICKY_KEYS+ does not affect the behavior of the keyboard callback functionality.
1637 When +STICKY_KEYS+ is disabled, the status of a key that is reported by glfwGetKey is always
1638 the physical state of the key. Disabling +STICKY_KEYS+ also clears the sticky information for
1639 all keys.
1640 +STICKY_MOUSE_BUTTONS+
1641 When +STICKY_MOUSE_BUTTONS+ is enabled, mouse buttons that are pressed will not be
1642 released until they are physically released and checked with glfw::GetMouseButton. This behavior
1643 makes it possible to catch mouse buttons which were pressed and then released again between two calls
1644 to glfw::PollEvents, glfw::WaitEvents or glfw::SwapBuffers, which would otherwise have been reported
1645 as released. Care should be taken when using this mode, since mouse buttons that are not checked with
1646 glfw::GetMouseButton will never be released. Note also that enabling
1647 +STICKY_MOUSE_BUTTONS+ does not affect the behavior of the mouse button callback
1648 functionality.
1649 When +STICKY_MOUSE_BUTTONS+ is disabled, the status of a mouse button that is reported
1650 by glfwGetMouseButton is always the physical state of the mouse button. Disabling
1651 +STICKY_MOUSE_BUTTONS+ also clears the sticky information for all mouse buttons.
1652 +SYSTEM_KEYS+
1653 When +SYSTEM_KEYS+ is enabled, pressing standard system key combinations, such as
1654 ALT+TAB under Windows, will give the normal behavior. Note that when ALT+TAB is issued under
1655 Windows in this mode so that the GLFW application is deselected when GLFW is operating in
1656 fullscreen mode, the GLFW application window will be minimized and the video mode will be set to
1657 the original desktop mode. When the GLFW application is re-selected, the video mode will be set to
1658 the GLFW video mode again.
1659 When +SYSTEM_KEYS+ is disabled, pressing standard system key combinations will have no
1660 effect, since those key combinations are blocked by GLFW. This mode can be useful in situations when
1661 the GLFW program must not be interrupted (normally for games in fullscreen mode).