]> git.jsancho.org Git - gacela.git/commitdiff
Keep SDL context open
authorJavier Sancho <jsf@jsancho.org>
Mon, 24 Apr 2017 18:11:11 +0000 (20:11 +0200)
committerJavier Sancho <jsf@jsancho.org>
Mon, 24 Apr 2017 18:11:11 +0000 (20:11 +0200)
gacela/game.scm

index 326db782c7651c0bd80cd71524d75db467e7b78b..fc0e135de1219f3326fc8b78bcc776d5ec919671 100644 (file)
@@ -137,15 +137,16 @@ milliseconds of the last iteration of the game loop."
 (define %gl-context #f)
 
 (define (init-window)
-  (sdl2:sdl-init)
-  (sdl2:set-gl-attribute! 'context-major-version 3)
-  (sdl2:set-gl-attribute! 'context-minor-version 2)
-  (sdl2:set-gl-attribute! 'double-buffer 1)
-  (sdl2:set-gl-attribute! 'depth-size 24)
-  (set! %sdl-window (sdl2:make-window #:opengl? #t #:show? #t))
-  (set! %sdl-renderer (sdl2:make-renderer %sdl-window))
-  (set! %gl-context (sdl2:make-gl-context %sdl-window))
-  (sdl2:set-gl-swap-interval! 'vsync)
+  (when (not %sdl-window)
+    (sdl2:sdl-init)
+    (sdl2:set-gl-attribute! 'context-major-version 3)
+    (sdl2:set-gl-attribute! 'context-minor-version 2)
+    (sdl2:set-gl-attribute! 'double-buffer 1)
+    (sdl2:set-gl-attribute! 'depth-size 24)
+    (set! %sdl-window (sdl2:make-window #:opengl? #t #:show? #t))
+    (set! %sdl-renderer (sdl2:make-renderer %sdl-window))
+    (set! %gl-context (sdl2:make-gl-context %sdl-window))
+    (sdl2:set-gl-swap-interval! 'vsync))
   (init-gl))
 
 (define (init-gl)
@@ -162,8 +163,7 @@ milliseconds of the last iteration of the game loop."
   (sdl2:show-window! %sdl-window))
 
 (define (close-window)
-  (sdl2:hide-window! %sdl-window)
-  (sdl2:sdl-quit))
+  (sdl2:hide-window! %sdl-window))
 
 (define (resize-window width height)
   (gl-viewport 0 0 width height)