From 3c8d1a6786c9ccc88fff5c1d381f5f4a9b333c72 Mon Sep 17 00:00:00 2001 From: jsancho Date: Tue, 6 Dec 2011 19:03:43 +0000 Subject: [PATCH 1/1] Gacela as Guile modules. --- src/gacela.scm | 13 ------ src/ttf.scm | 36 ---------------- src/{gacela_draw.scm => video.scm} | 66 +++++++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 54 deletions(-) delete mode 100644 src/ttf.scm rename src/{gacela_draw.scm => video.scm} (84%) diff --git a/src/gacela.scm b/src/gacela.scm index bfb4d12..d440c08 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -136,19 +136,6 @@ (glLoadIdentity) #t) -(define get-current-color #f) -(define set-current-color #f) - -(let ((current-color '(1 1 1 1))) - (set! get-current-color - (lambda () - current-color)) - - (set! set-current-color - (lambda* (red green blue #:optional (alpha 1)) - (set! current-color (list red green blue alpha)) - (glColor4f red green blue alpha)))) - ;;; Audio Subsystem diff --git a/src/ttf.scm b/src/ttf.scm deleted file mode 100644 index 8185eda..0000000 --- a/src/ttf.scm +++ /dev/null @@ -1,36 +0,0 @@ -;;; Gacela, a GNU Guile extension for fast games development -;;; Copyright (C) 2009 by Javier Sancho Fernandez -;;; -;;; This program is free software: you can redistribute it and/or modify -;;; it under the terms of the GNU General Public License as published by -;;; the Free Software Foundation, either version 3 of the License, or -;;; (at your option) any later version. -;;; -;;; This program is distributed in the hope that it will be useful, -;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with this program. If not, see . - - -(define-module (gacela ttf) - #:use-module (gacela ftgl) - #:use-module (ice-9 optargs) - #:export (load-font - render-text)) - -(define* (load-font font-file #:key (size 40) (encoding ft_encoding_unicode)) - (let* ((key (list font-file)) - (font (get-resource-from-cache key))) - (cond ((not font) - (set! font (ftglCreateTextureFont font-file)) - (insert-resource-into-cache key font))) - (ftglSetFontFaceSize font size 72) - (ftglSetFontCharMap font encoding) - font)) - -(define* (render-text text font #:key (size #f)) - (cond (size (ftglSetFontFaceSize font size 72))) - (ftglRenderFont font text FTGL_RENDER_ALL)) diff --git a/src/gacela_draw.scm b/src/video.scm similarity index 84% rename from src/gacela_draw.scm rename to src/video.scm index 595efe9..1b2a9e7 100644 --- a/src/gacela_draw.scm +++ b/src/video.scm @@ -15,6 +15,47 @@ ;;; along with this program. If not, see . +(define-module (gacela video) + #:use-module (gacela sdl) + #:use-module (gacela gl) + #:use-module (gacela ftgl) + #:use-module (ice-9 optargs) + #:use-module (ice-9 receive) + #:export (with-color + progn-textures + draw + load-image + resize-surface + load-texture + draw-texture + draw-line + draw-quad + draw-rectangle + draw-square + draw-cube + add-light + translate + rotate + to-origin + set-camera + camera-look + load-font + render-text)) + + +(define get-current-color #f) +(define set-current-color #f) + +(let ((current-color '(1 1 1 1))) + (set! get-current-color + (lambda () + current-color)) + + (set! set-current-color + (lambda* (red green blue #:optional (alpha 1)) + (set! current-color (list red green blue alpha)) + (glColor4f red green blue alpha)))) + (define-macro (with-color color . code) (cond (color `(let ((original-color (get-current-color)) @@ -27,7 +68,6 @@ (define-macro (progn-textures . code) `(let ((result #f)) - (init-video-mode) (glEnable GL_TEXTURE_2D) (set! result (begin ,@code)) (glDisable GL_TEXTURE_2D) @@ -61,7 +101,6 @@ (else (glVertex2f x y)))) (define (load-image filename) - (init-sdl) (let ((image (IMG_Load filename))) (cond (image (SDL_DisplayFormatAlpha image))))) @@ -108,9 +147,9 @@ (insert-resource-into-cache key texture) texture))))))))) -(define* (draw-image filename #:optional (zoom 1)) - (let ((texture (load-texture filename))) - (cond (texture (draw-texture texture zoom))))) +;; (define* (draw-image filename #:optional (zoom 1)) +;; (let ((texture (load-texture filename))) +;; (cond (texture (draw-texture texture zoom))))) (define* (draw-texture texture #:optional (zoom 1)) (cond (texture @@ -210,3 +249,20 @@ (set! camera-look (lambda () (apply gluLookAt (append camera-eye camera-center camera-up))))) + + +;;; Text and fonts + +(define* (load-font font-file #:key (size 40) (encoding ft_encoding_unicode)) + (let* ((key (list font-file)) + (font (get-resource-from-cache key))) + (cond ((not font) + (set! font (ftglCreateTextureFont font-file)) + (insert-resource-into-cache key font))) + (ftglSetFontFaceSize font size 72) + (ftglSetFontCharMap font encoding) + font)) + +(define* (render-text text font #:key (size #f)) + (cond (size (ftglSetFontFaceSize font size 72))) + (ftglRenderFont font text FTGL_RENDER_ALL)) -- 2.39.5