(bind-func gl_draw_loop
(let ((layout:nk_panel* null)
(combo:nk_panel* null)
(easy:i32 0)
(hard:i32 1) (op easy)
(property:i32 20)
(bg:|4,float|* (alloc)))
(lambda (time:i64 delta_t:double)
(if (= (glfwWindowShouldClose window) 1)
(begin (nk_glfw3_shutdown)
(glfwTerminate)
(println "Window closed, stopping draw loop."))
(begin
(glClear GL_COLOR_BUFFER_BIT)
(glfwPollEvents)
(nk_glfw3_new_frame)
(if (= (nk_begin ctx layout "Demo" (pref (nk_rect 50. 50. 230. 250.) 0)
(+ NK_WINDOW_BORDER NK_WINDOW_MOVABLE NK_WINDOW_SCALABLE
NK_WINDOW_MINIMIZABLE NK_WINDOW_TITLE))
nk_true)
(begin
(nk_layout_row_static ctx 30. 80 1)
(if (= (nk_button_label ctx "button" NK_BUTTON_DEFAULT) nk_true)
(println "button pressed"))
(nk_layout_row_dynamic ctx 30. 2)
(if (= (nk_option_label ctx "easy" (convert (= op easy))) nk_true)
(set! op easy))
(if (= (nk_option_label ctx "hard" (convert (= op hard))) nk_true)
(set! op hard))
(nk_layout_row_dynamic ctx 20. 1)
(nk_label ctx "background:" NK_TEXT_LEFT)
(nk_layout_row_dynamic ctx 25. 1)
(if (= (nk_combo_begin_color ctx combo (nk_rgb 28 48 62) 400) nk_true)
(begin (nk_layout_row_dynamic ctx 120. 1)
(set! background (nk_color_picker ctx (nk_rgb 28 48 62) NK_RGBA))
(nk_layout_row_dynamic ctx 25. 1)
(tset! background 0
(convert (nk_propertyi ctx "#R:" 0 (convert (tref background 0)) 255 1 1)))
(tset! background 1
(convert (nk_propertyi ctx "#G:" 0 (convert (tref background 1)) 255 1 1)))
(tset! background 2
(convert (nk_propertyi ctx "#B:" 0 (convert (tref background 2)) 255 1 1)))
(tset! background 3
(convert (nk_propertyi ctx "#A:" 0 (convert (tref background 3)) 255 1 1)))
(nk_combo_end ctx)))
(nk_end ctx)))
;; draw
(nk_color_fv (aref-ptr bg 0) (nk_rgb 28 48 62))
;; (glfwGetWindowSize win &width &height)
;; (glViewport 0 0 width height)
(glClear GL_COLOR_BUFFER_BIT)
(glClearColor (aref bg 0) (aref bg 1) (aref bg 2) (aref bg 3))
;; /* IMPORTANT: `nk_glfw_render` modifies some global OpenGL state
;; * with blending, scissor, face culling, depth test and viewport and
;; * defaults everything back into a default state.
;; * Make sure to either a.) save and restore or b.) reset your own state after
;; * rendering the UI. */
(nk_glfw3_render NK_ANTI_ALIASING_ON MAX_VERTEX_BUFFER MAX_ELEMENT_BUFFER)
(glfwSwapBuffers window)
(let ((next_time (+ time (convert (* 44100. delta_t)))))
(callback next_time gl_draw_loop next_time delta_t)))))))