From b0a806a285013bc932ec86014bbdcc9f0b11235d Mon Sep 17 00:00:00 2001 From: Pieter Slabbert Date: Fri, 23 Aug 2013 06:54:04 +0200 Subject: add wildcards to makefile for sources Makefile.am didn't change as modules were added added wildcards so that all the files in 2d/ are used as sources --- Makefile.am | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Makefile.am b/Makefile.am index 19f9992..031ffd6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,17 +3,6 @@ include guile.am moddir=$(prefix)/share/guile/site/2.0 godir=$(libdir)/guile/2.0/ccache -SOURCES = \ - 2d/agenda.scm\ - 2d/animation.scm\ - 2d/coroutine.scm\ - 2d/game-loop.scm\ - 2d/gl.scm\ - 2d/helpers.scm\ - 2d/math.scm\ - 2d/sprite.scm\ - 2d/texture.scm\ - 2d/vector.scm\ - 2d/window.scm +SOURCES = $(wildcard 2d/*.scm 2d/*/*.scm) EXTRA_DIST += env.in -- cgit v1.2.3 From 7af9207daa872c8a0a1c71c4a81a91fc0ee1c025 Mon Sep 17 00:00:00 2001 From: Pieter Slabbert Date: Fri, 23 Aug 2013 17:49:52 +0200 Subject: Add (ice-9 format) module to imports for freeimage and ftgl freeimage.scm and ftgl.scm were throwing warnings when running make about a unsupported format option GEN 2d/wrappers/freeimage.go 2d/wrappers/freeimage.scm:120:6: warning: "": unsupported format option ~x, use (ice-9 format) instead wrote `2d/wrappers/freeimage.go' GEN 2d/wrappers/ftgl.go 2d/wrappers/ftgl.scm:62:6: warning: "": unsupported format option ~x, use (ice-9 format) instead 2d/wrappers/ftgl.scm:100:6: warning: "": unsupported format option ~x, use (ice-9 format) instead wrote `2d/wrappers/ftgl.go' GEN 2d/wrappers/gl.go wrote `2d/wrappers/gl.go' adding the modules to the module definition of each file fixes it --- 2d/wrappers/freeimage.scm | 3 ++- 2d/wrappers/ftgl.scm | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/2d/wrappers/freeimage.scm b/2d/wrappers/freeimage.scm index 3192dbb..b29e950 100644 --- a/2d/wrappers/freeimage.scm +++ b/2d/wrappers/freeimage.scm @@ -23,7 +23,8 @@ (define-module (2d wrappers freeimage) #:use-module (system foreign) - #:use-module (2d wrappers util)) + #:use-module (2d wrappers util) + #:use-module (ice-9 format)) (define libfreeimage (dynamic-link "libfreeimage")) diff --git a/2d/wrappers/ftgl.scm b/2d/wrappers/ftgl.scm index f44443b..1d18fad 100644 --- a/2d/wrappers/ftgl.scm +++ b/2d/wrappers/ftgl.scm @@ -23,7 +23,8 @@ (define-module (2d wrappers ftgl) #:use-module (system foreign) - #:use-module (2d wrappers util)) + #:use-module (2d wrappers util) + #:use-module (ice-9 format)) (define libftgl (dynamic-link "libftgl")) -- cgit v1.2.3 From b80e5144ebfe49f412d68002766efb01a8bc0b8a Mon Sep 17 00:00:00 2001 From: Pieter Slabbert Date: Fri, 23 Aug 2013 18:53:27 +0200 Subject: Update simple example program The example program provided in the readme doesn't work. It seems that the on-key-down hook changed since the readme was written. This takes bits from simple.scm to fix it. --- README.org | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.org b/README.org index 178bdc0..c8b4436 100644 --- a/README.org +++ b/README.org @@ -24,7 +24,8 @@ (use-modules (figl gl) (2d sprite) (2d game-loop) - (2d window)) + (2d window) + (2d helpers)) (define window-width 800) (define window-height 600) @@ -38,13 +39,13 @@ #:position (vector (/ window-width 2) (/ window-height 2)))) - (define (key-down key) - (display key) (newline) - (case key - ;; Quit program when ESCAPE or Q is pressed. - ((any-equal? key 'escape 'q) - (close-window) - (quit)))) + (define (quit-demo) + (close-window) + (quit)) + + (define (key-down key mod unicode) + (cond ((any-equal? key 'escape 'q) + (quit-demo)))) ;; Draw our sprite (define (render) @@ -53,8 +54,9 @@ ;; Register hooks. Lambdas are used as "trampolines" so that render ;; and key-down can be redefined later and the hooks will call the ;; updated procedures. + (add-hook! on-quit-hook (lambda () (quit-demo))) (add-hook! on-render-hook (lambda () (render))) - (add-hook! on-key-down-hook (lambda (key) (key-down key))) + (add-hook! on-key-down-hook (lambda (key mod unicode) (key-down key mod unicode))) ;; Start the game loop. ;; The render callback will be called through this procedure. -- cgit v1.2.3 From bf314ba7017c4cb0a902726a049c7313b5e1f156 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 24 Aug 2013 15:32:35 -0400 Subject: Throw error if image file does not exist. --- 2d/texture.scm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/2d/texture.scm b/2d/texture.scm index b7808b3..19c26c8 100644 --- a/2d/texture.scm +++ b/2d/texture.scm @@ -132,7 +132,13 @@ 0 0 1 1))) (define (load-bitmap filename) - (let* ((bitmap (freeimage-load (freeimage-get-file-type filename) filename)) + ;; Throw an error if image file does not exist or else we will + ;; segfault later. + (unless (file-exists? filename) + (throw 'image-not-found filename)) + ;; Load image and convert it to 32 bit color. + (let* ((image-type (freeimage-get-file-type filename)) + (bitmap (freeimage-load image-type filename)) (32bit-bitmap (freeimage-convert-to-32-bits bitmap))) (freeimage-unload bitmap) 32bit-bitmap)) -- cgit v1.2.3 From 0a4da8e7193cb82c6b188de19bb0ba616a912de4 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 24 Aug 2013 15:33:04 -0400 Subject: Tidy up freeimage module. --- 2d/wrappers/freeimage.scm | 57 ++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/2d/wrappers/freeimage.scm b/2d/wrappers/freeimage.scm index b29e950..964eff7 100644 --- a/2d/wrappers/freeimage.scm +++ b/2d/wrappers/freeimage.scm @@ -84,7 +84,8 @@ ;;; General functions ;;; -(define-foreign %freeimage-get-version '* "FreeImage_GetVersion" '()) +(define-foreign %freeimage-get-version + '* "FreeImage_GetVersion" '()) (define-foreign %freeimage-set-output-message void "FreeImage_SetOutputMessage" '(*)) @@ -125,8 +126,10 @@ (%freeimage-get-height bitmap) (%freeimage-get-bpp bitmap))))) -(define-foreign %freeimage-load '* "FreeImage_Load" (list unsigned-int '* unsigned-int)) -(define-foreign %freeimage-unload void "FreeImage_Unload" '(*)) +(define-foreign %freeimage-load + '* "FreeImage_Load" (list unsigned-int '* unsigned-int)) +(define-foreign %freeimage-unload + void "FreeImage_Unload" '(*)) (define (freeimage-load image-format filename) (wrap-freeimage-bitmap @@ -135,22 +138,33 @@ (define (freeimage-unload bitmap) (%freeimage-unload (unwrap-freeimage-bitmap bitmap))) -(export freeimage-load +(export + freeimage-bitmap? + freeimage-load freeimage-unload) ;;; ;;; Bitmap information functions ;;; -(define-foreign %freeimage-get-image-type unsigned-int "FreeImage_GetImageType" '(*)) -(define-foreign %freeimage-get-bpp unsigned-int "FreeImage_GetBPP" '(*)) -(define-foreign %freeimage-get-width unsigned-int "FreeImage_GetWidth" '(*)) -(define-foreign %freeimage-get-height unsigned-int "FreeImage_GetHeight" '(*)) -(define-foreign %freeimage-get-pitch unsigned-int "FreeImage_GetPitch" '(*)) -(define-foreign %freeimage-get-red-mask unsigned-int "FreeImage_GetRedMask" '(*)) -(define-foreign %freeimage-get-green-mask unsigned-int "FreeImage_GetGreenMask" '(*)) -(define-foreign %freeimage-get-blue-mask unsigned-int "FreeImage_GetBlueMask" '(*)) -(define-foreign %freeimage-has-pixels unsigned-int "FreeImage_HasPixels" '(*)) +(define-foreign %freeimage-get-image-type + unsigned-int "FreeImage_GetImageType" '(*)) +(define-foreign %freeimage-get-bpp + unsigned-int "FreeImage_GetBPP" '(*)) +(define-foreign %freeimage-get-width + unsigned-int "FreeImage_GetWidth" '(*)) +(define-foreign %freeimage-get-height + unsigned-int "FreeImage_GetHeight" '(*)) +(define-foreign %freeimage-get-pitch + unsigned-int "FreeImage_GetPitch" '(*)) +(define-foreign %freeimage-get-red-mask + unsigned-int "FreeImage_GetRedMask" '(*)) +(define-foreign %freeimage-get-green-mask + unsigned-int "FreeImage_GetGreenMask" '(*)) +(define-foreign %freeimage-get-blue-mask + unsigned-int "FreeImage_GetBlueMask" '(*)) +(define-foreign %freeimage-has-pixels + unsigned-int "FreeImage_HasPixels" '(*)) (define (freeimage-get-image-type bitmap) (%freeimage-get-image-type (unwrap-freeimage-bitmap bitmap))) @@ -193,10 +207,11 @@ ;;; Filetype functions ;;; -(define-foreign %freeimage-get-file-type unsigned-int "FreeImage_GetFileType" '(*)) +(define-foreign %freeimage-get-file-type + unsigned-int "FreeImage_GetFileType" (list '* int)) (define (freeimage-get-file-type filename) - (%freeimage-get-file-type (string->pointer filename))) + (%freeimage-get-file-type (string->pointer filename) 0)) (export freeimage-get-file-type) @@ -218,11 +233,10 @@ ;;; Conversion functions ;;; -(define-foreign %freeimage-convert-to-24-bits '* "FreeImage_ConvertTo24Bits" '(*)) -(define-foreign %freeimage-convert-to-32-bits '* "FreeImage_ConvertTo32Bits" '(*)) -(define-foreign %freeimage-convert-to-raw-bits - void "FreeImage_ConvertToRawBits" - (list '* '* int unsigned-int unsigned-int unsigned-int unsigned-int uint8)) +(define-foreign %freeimage-convert-to-24-bits + '* "FreeImage_ConvertTo24Bits" '(*)) +(define-foreign %freeimage-convert-to-32-bits + '* "FreeImage_ConvertTo32Bits" '(*)) (define (freeimage-convert-to-24-bits bitmap) (wrap-freeimage-bitmap @@ -239,7 +253,8 @@ ;;; Rotation and flipping ;;; -(define-foreign %freeimage-flip-vertical uint8 "FreeImage_FlipVertical" '(*)) +(define-foreign %freeimage-flip-vertical + uint8 "FreeImage_FlipVertical" '(*)) (define (freeimage-flip-vertical bitmap) (number->boolean -- cgit v1.2.3 From fd326a63b6ef49257c165289e8244bff92ef0994 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 24 Aug 2013 15:59:37 -0400 Subject: Fix typo in README. --- README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.org b/README.org index c8b4436..947d2b7 100644 --- a/README.org +++ b/README.org @@ -75,7 +75,7 @@ Guile-2d uses the FreeImage library and can load many different image formats. See the FreeImage [[http://freeimage.sourceforge.net/features.html][features page]] for a full list of - support formats. + supported formats. #+BEGIN_SRC scheme (define sprite (load-sprite "cirno.png" -- cgit v1.2.3