From: Javier Sancho Date: Wed, 28 Sep 2016 15:36:18 +0000 (+0200) Subject: Images in development X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=f3487d80c29eb9a6ecc23686c5010bffb364af22;p=gacela.git Images in development --- diff --git a/gacela/game.scm b/gacela/game.scm index 0b0981d..dad0412 100644 --- a/gacela/game.scm +++ b/gacela/game.scm @@ -23,7 +23,8 @@ #: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!! @@ -117,8 +118,6 @@ milliseconds of the last iteration of the game loop." (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) @@ -129,11 +128,13 @@ milliseconds of the last iteration of the game loop." (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) @@ -146,3 +147,13 @@ milliseconds of the last iteration of the game loop." (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)) diff --git a/gacela/image.scm b/gacela/image.scm index 6a97101..1fdeaf6 100644 --- a/gacela/image.scm +++ b/gacela/image.scm @@ -17,18 +17,26 @@ (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 diff --git a/gacela/scene.scm b/gacela/scene.scm index 9145907..62b1a1e 100644 --- a/gacela/scene.scm +++ b/gacela/scene.scm @@ -43,5 +43,5 @@ ((scene-procedure scene))) (define (run-scene scene) - (run-game-loop + (play-game (scene-procedure scene)))