#:use-module ((sdl2 video) #:prefix sdl2:)
#:use-module (gl)
#:use-module (srfi srfi-11)
- #:export (run-game-loop))
+ #:export (play-game
+ %sdl-renderer))
;;; Based on Sly code. Thank you so much!!
(lambda (signum)
(stop-game-loop)))
(set! %root-scene scene)
- (init-window)
- (open-window)
(game-loop (sdl2:sdl-ticks) 0))
(lambda (cont callback)
(when (procedure? callback)
(abort-to-prompt 'game-loop-prompt #f))
(define %sdl-window #f)
+(define %sdl-renderer #f)
(define %gl-context #f)
(define (init-window)
(sdl2:sdl-init)
(set! %sdl-window (sdl2:make-window #:opengl? #t #:show? #t))
+ (set! %sdl-renderer (sdl2:make-renderer %sdl-window))
(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-window-size! %sdl-window resolution)
(sdl2:set-window-fullscreen! %sdl-window fullscreen?)
(sdl2:show-window! %sdl-window))
+
+(define (close-window)
+ (sdl2:hide-window! %sdl-window)
+ (sdl2:sdl-quit))
+
+(define (play-game scene)
+ (init-window)
+ (open-window)
+ (run-game-loop scene)
+ (close-window))
(define-module (gacela image)
#:use-module (gacela scene)
- #:use-module ((sdl2 surface) #:prefix sdl2:)
+ #:use-module (gacela game)
+ #:use-module ((sdl2 image) #:prefix sdl2:)
+ #:use-module ((sdl2 render) #:prefix sdl2:)
#:export (import-bitmap
move-xy))
(define-syntax-rule (import-bitmap filename)
(make-scene
"bitmap"
- (let ((surface (sdl2:load-bmp filename)))
+ (let ((image (sdl2:load-image filename))
+ (texture #f))
(let ((a 0))
(lambda ()
- (set! a (+ a 1))
- (format #t "Steps: ~a~%" a))))))
+ (if (not texture)
+ (set! texture (sdl2:surface->texture %sdl-renderer image)))
+ ;; (set! a (+ a 1))
+ ;; (format #t "~a steps with texture ~a~%" a texture))))))
+ (sdl2:clear-renderer %sdl-renderer)
+ (sdl2:render-copy %sdl-renderer texture)
+ (sdl2:present-renderer %sdl-renderer))))))
(define-syntax-rule (move-xy x y scene)
(make-scene
((scene-procedure scene)))
(define (run-scene scene)
- (run-game-loop
+ (play-game
(scene-procedure scene)))