Gambit bindings to GLFW. an Open Source, multi-platform library for creating windows with OpenGL contexts and managing input and events.
To compile glfw you need to get the glfw binaries +:
OS X: Cocoa, OpenGL, IOKit and CoreVideo
Windows: opengl3
There are now also a schemified version! see glfwREADME.md or read glwf.scm ;) Do it!
To test, when compiled run:
No program compilation needed ;)
Copy paste the following into your gambit to test (or see example.scm
):
(load "glfw.o1")
(define main-window (glfw#make-window 100 100 "hello"))
(define should-quit? #f)
(glfw#window-on-key-press-set! main-window
(lambda (window in-key scancode action modifier)
(if (eq? in-key GLFW_KEY_0)
(set! should-quit? #t))
(let ((key (glfw-key->schmobj in-key))
(x-pos (glfw#window-position-x window))
(y-pos (glfw#window-position-y window)))
(print key)
(newline)
(case key
((key-left) (glfw#window-position-x-set! window (- x-pos 5)))
((key-right) (glfw#window-position-x-set! window (+ x-pos 5)))
((key-up) (glfw#window-position-y-set! window (- y-pos 5)))
((key-down) (glfw#window-position-y-set! window (+ y-pos 5)))))))
(let loop ()
(glfw-native#poll-events)
(glfw#window-swap-buffers main-window)
(if should-quit? #f (loop)))
You Should now have a 100 x 100 black window (might be flimmering due to non cleared buffers... And you can move it around the screen with your arrow keys!
press "0" to quit
(load "glfwNative.o1")
(if (not (glfw-native#init))
(print "glfw init error \n")
)
(define window (glfw-native#create-window 100 100 "test" #f #f))
This should give you a 100 x 100 black window.
To create functions compatible with the different event handlers you must make c-defines such as:
(c-define (glfw#error-callback-procedure error-code error-msg)(int nonnull-UTF-8-string) void "gambitErrorCallback" ""
(print "Glfw error-code: ")
(print error-code)
(newline)
(print "Glfw error-message: ")
(print error-msg)
(newline)
#f)
You should now be able to run the follwing:
(glfw#setErrorCallback glfw#error-callback-procedure)
If you have questions or remarks feel free to contact me on [email protected]