Multiple graphical windows with SDL2 and Lisp?

I am trying to use cl-sdl2 with Clozure Common Lisp (on MS-Windows, although I would think that it should work on other platforms and compilers) to draw up to two separate graphic windows. When I try the code below:

(ql:quickload "sdl2") (require :sdl2) (defun make-two-SDL-2-windows () (let* ((win1 (sdl2:create-window :title "Win 1" :w 400 :h 400)) (ren1 (sdl2:create-renderer win1)) (win2 (sdl2:create-window :title "Win 2" :w 300 :h 300)) (ren2 (sdl2:create-renderer win2))) (sdl2:with-event-loop (:method :poll) (:keyup (:keysym keysym) (when (sdl2:scancode= (sdl2:scancode-value keysym) :scancode-escape) (sdl2:push-event :quit))) (:idle () (progn (sdl2:render-present ren1) (sdl2:render-present ren2))) (:quit () (progn (sdl2:destroy-renderer ren1) (sdl2:destroy-renderer ren2) (sdl2:destroy-window win1) (sdl2:destroy-window win2) t))))) (defun main () (sdl2:init :everything) ;;;Clozure... (process-run-function "window" #'make-two-SDL-2-windows)) (main) 

... both new windows are created by "freezing" and do not respond / redraw to mouse clicks or movements. I tried to base this snippet on what I found in the SDL2 examples . I must not understand how to use the cl-sdl2 shell for an event loop or something like that. Has anyone had success using multiple windows and SDL2 with Common Lisp?


Here's the working version, thanks to Rei's help:

 (defun make-two-SDL-2-windows () (sdl2:with-init (:everything) (sdl2:with-window (win1 :title "Win1" :flags '(:shown)) (sdl2:with-window (win2 :title "Win2" :flags '(:shown)) (sdl2:with-renderer (ren1 win1 :flags '(:renderer-accelerated)) (sdl2:with-renderer (ren2 win2 :flags '(:renderer-accelerated)) (sdl2:with-event-loop (:method :poll) (:keyup (:keysym keysym) (when (sdl2:scancode= (sdl2:scancode-value keysym) :scancode-escape) (sdl2:push-event :quit))) (:idle () (progn (sdl2:set-render-draw-color ren1 0 0 255 255) (sdl2:set-render-draw-color ren2 0 255 0 255) (sdl2:render-draw-line ren1 150 20 100 300) (sdl2:render-draw-line ren2 20 20 150 150) (sdl2:render-present ren1) (sdl2:render-present ren2))) (:quit () t)))))))) 
+5
source share
1 answer

You defined two windows and visualization tools without actually using them in the event loop; use sdl2: with-renderer and sdl2: with a window to bind them.

+2
source

Source: https://habr.com/ru/post/1247571/


All Articles