(bind-func gui_init
(lambda (width height)
;; (if (not (null? EXTEMPORE_GUI))
;; (begin
;; (println "Extempore GUI is already initialised, and cannot be re-initialised.")
;; EXTEMPORE_GUI))
(let ((ww:i32* (alloc))
(wh:i32* (alloc))
(fbw:i32* (alloc))
(fbh:i32* (alloc))
(window null)
(vg null))
;; set up GLFW
(glfwSetErrorCallback (convert (get_native_fptr glfw_error_callback)))
(glfwInit)
(set! window (glfw_init_and_create_interaction_window width height))
(glfwSetWindowSizeCallback window (convert (get_native_fptr gui_window_size_callback)))
;; (glfwSetInputMode window GLFW_STICKY_KEYS 1)
;; (glfwSetInputMode window GLFW_STICKY_MOUSE_BUTTONS 1)
;; set up nanovg
(set! vg (nvg_create_context))
(glfwGetWindowSize window ww wh)
(glfwGetFramebufferSize window fbw fbh)
;; create the new GUI data type
(set! EXTEMPORE_GUI
(GUI_h
window
vg
null
(convert (pref ww 0) float)
(convert (pref wh 0) float)
(/ (convert (pref fbw 0) float) (convert (pref ww 0) float)))))))