From: jsancho Date: Mon, 23 May 2011 05:43:24 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=4fa4326c57c1022891fd0a7678f139119e997116;p=gacela.git --- diff --git a/src/gacela.c b/src/gacela.c index e1e05aa..18e2439 100644 --- a/src/gacela.c +++ b/src/gacela.c @@ -46,6 +46,7 @@ void load_scheme_files (char *path) { load_scheme_file (path, "gacela.scm"); + load_scheme_file (path, "gacela_events.scm"); load_scheme_file (path, "gacela_ttf.scm"); } diff --git a/src/gacela.scm b/src/gacela.scm index f83e117..f70a9c6 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -208,7 +208,9 @@ (define-macro (run-game . code) - `(let ((game-function (lambda () (begin ,@code)))) + `(let ((game-function ,(if (null? code) + `(lambda () #f) + `(lambda () ,@code)))) (init-video-mode) (set-game-code game-function) (cond ((not (game-running?)) @@ -222,14 +224,13 @@ (set! game-loop (lambda () (set! running #t) -; (do () ((quit?)) - (do () (#f) + (quit? #f) + (do () ((quit?)) (init-frame-time) ; (check-connections) ; (eval-from-clients) -; (process-events) -; (cond ((not (quit?)) - (cond ((not #f) + (process-events) + (cond ((not (quit?)) (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) ; (to-origin) ; (refresh-active-objects) diff --git a/src/gacela_FTGL.c b/src/gacela_FTGL.c index 8a44d8e..af14aba 100644 --- a/src/gacela_FTGL.c +++ b/src/gacela_FTGL.c @@ -94,15 +94,14 @@ print_font (SCM font_smob, SCM port, scm_print_state *pstate) SCM gacela_ftglCreateTextureFont (SCM file) { - FTGLfont *font_address = NULL; - - font_address = ftglCreateTextureFont (scm_to_locale_string (file)); + FTGLfont *font_address = ftglCreateTextureFont (scm_to_locale_string (file)); if (font_address) { return make_font (file, font_address); } else { - return SCM_UNSPECIFIED; + // return SCM_UNSPECIFIED; + return SCM_UNDEFINED; } } diff --git a/src/gacela_SDL.c b/src/gacela_SDL.c index f40c0ac..07ab347 100644 --- a/src/gacela_SDL.c +++ b/src/gacela_SDL.c @@ -17,34 +17,99 @@ #include #include +#include #include #include #include "gacela_SDL.h" struct surface { - SCM name; + SCM filename; + SDL_Surface *surface_address; }; static scm_t_bits surface_tag; SCM -gacela_make_surface (SCM name) +make_surface (SCM file, SDL_Surface *surface_address) { SCM smob; struct surface *surface; surface = (struct surface *) scm_gc_malloc (sizeof (struct surface), "surface"); - surface->name = SCM_BOOL_F; + surface->filename = SCM_BOOL_F; + surface->surface_address = NULL; SCM_NEWSMOB (smob, surface_tag, surface); - surface->name = name; + surface->filename = file; + surface->surface_address = surface_address; return smob; } +SDL_Surface * +get_surface_address (SCM surface_smob) +{ + struct surface *surface; + + scm_assert_smob_type (surface_tag, surface_smob); + surface = (struct surface *) SCM_SMOB_DATA (surface_smob); + return surface->surface_address; +} + +SCM +get_surface_width (SCM surface_smob) +{ + SDL_Surface *surface = get_surface_address (surface_smob); + + return scm_from_int (surface->w); +} + +SCM +get_surface_height (SCM surface_smob) +{ + SDL_Surface *surface = get_surface_address (surface_smob); + + return scm_from_int (surface->h); +} + +SCM +mark_surface (SCM surface_smob) +{ + struct surface *surface = (struct surface *) SCM_SMOB_DATA (surface_smob); + + scm_gc_mark (surface->filename); + + return SCM_BOOL_F; +} + +size_t +free_surface (SCM surface_smob) +{ + struct surface *surface = (struct surface *) SCM_SMOB_DATA (surface_smob); + + SDL_FreeSurface (surface->surface_address); + scm_gc_free (surface, sizeof (struct surface), "surface"); + + return 0; +} + +static int +print_surface (SCM surface_smob, SCM port, scm_print_state *pstate) +{ + struct surface *surface = (struct surface *) SCM_SMOB_DATA (surface_smob); + + scm_puts ("#filename, port); + scm_puts ("\">", port); + + /* non-zero means success */ + return 1; +} + + SCM gacela_SDL_Init (SCM flags) { @@ -61,8 +126,15 @@ gacela_SDL_Quit (void) SCM gacela_SDL_SetVideoMode (SCM width, SCM height, SCM bpp, SCM flags) { - return scm_from_int ((int)SDL_SetVideoMode (scm_to_int (width), scm_to_int (height), \ - scm_to_int (bpp), scm_to_int (flags))); + SDL_Surface *screen = SDL_SetVideoMode (scm_to_int (width), scm_to_int (height), \ + scm_to_int (bpp), scm_to_int (flags)); + + if (screen) { + return make_surface (scm_from_locale_string ("screen"), screen); + } + else { + return SCM_UNSPECIFIED; + } } SCM @@ -75,14 +147,7 @@ gacela_SDL_WM_SetCaption (SCM title, SCM icon) SCM gacela_SDL_Flip (SCM screen) { - return scm_from_int (SDL_Flip ((SDL_Surface *)scm_to_int (screen))); -} - -SCM -gacela_SDL_FreeSurface (SCM surface) -{ - SDL_FreeSurface ((SDL_Surface *)scm_to_int (surface)); - return SCM_UNSPECIFIED; + return scm_from_int (SDL_Flip (get_surface_address (screen))); } SCM @@ -101,7 +166,7 @@ gacela_SDL_GetTicks (void) SCM gacela_SDL_DisplayFormat (SCM surface) { - return scm_from_int ((int)SDL_DisplayFormat ((SDL_Surface *)scm_to_int (surface))); + return scm_from_int ((int)SDL_DisplayFormat (get_surface_address (surface))); } SCM @@ -113,19 +178,33 @@ gacela_SDL_MapRGB (SCM format, SCM r, SCM g, SCM b) SCM gacela_SDL_SetColorKey (SCM surface, SCM flag, SCM key) { - return scm_from_int (SDL_SetColorKey ((SDL_Surface *)scm_to_int (surface), scm_to_int (flag), scm_to_int (key))); + return scm_from_int (SDL_SetColorKey (get_surface_address (surface), scm_to_int (flag), scm_to_int (key))); } SCM gacela_SDL_LoadBMP (SCM file) { - return scm_from_int ((int)SDL_LoadBMP (scm_to_locale_string (file))); + SDL_Surface *image = SDL_LoadBMP (scm_to_locale_string (file)); + + if (image) { + return make_surface (file, image); + } + else { + return SCM_UNSPECIFIED; + } } SCM gacela_IMG_Load (SCM filename) { - return scm_from_int ((int)IMG_Load (scm_to_locale_string (filename))); + SDL_Surface *image = IMG_Load (scm_to_locale_string (filename)); + + if (image) { + return make_surface (filename, image); + } + else { + return SCM_UNSPECIFIED; + } } SCM @@ -271,10 +350,11 @@ void* SDL_register_functions (void* data) { surface_tag = scm_make_smob_type ("surface", sizeof (struct surface)); - // scm_set_smob_mark (surface_tag, mark_surface); - // scm_set_smob_free (surface_tag, free_surface); - // scm_set_smob_print (surface_tag, print_surface); - // scm_set_smob_equalp (surface_tag, equalp_surface); + scm_set_smob_mark (surface_tag, mark_surface); + scm_set_smob_free (surface_tag, free_surface); + scm_set_smob_print (surface_tag, print_surface); + scm_c_define_gsubr ("surface-w", 1, 0, 0, get_surface_width); + scm_c_define_gsubr ("surface-h", 1, 0, 0, get_surface_height); scm_c_define ("SDL_INIT_TIMER", scm_from_int (SDL_INIT_TIMER)); scm_c_define ("SDL_INIT_AUDIO", scm_from_int (SDL_INIT_AUDIO)); @@ -312,12 +392,38 @@ SDL_register_functions (void* data) scm_c_define ("MIX_DEFAULT_FORMAT", scm_from_int (MIX_DEFAULT_FORMAT)); + scm_c_define ("SDL_NOEVENT", scm_from_int (SDL_NOEVENT)); + scm_c_define ("SDL_ACTIVEEVENT", scm_from_int (SDL_ACTIVEEVENT)); + scm_c_define ("SDL_KEYDOWN", scm_from_int (SDL_KEYDOWN)); + scm_c_define ("SDL_KEYUP", scm_from_int (SDL_KEYUP)); + scm_c_define ("SDL_MOUSEMOTION", scm_from_int (SDL_MOUSEMOTION)); + scm_c_define ("SDL_MOUSEBUTTONDOWN", scm_from_int (SDL_MOUSEBUTTONDOWN)); + scm_c_define ("SDL_MOUSEBUTTONUP", scm_from_int (SDL_MOUSEBUTTONUP)); + scm_c_define ("SDL_JOYAXISMOTION", scm_from_int (SDL_JOYAXISMOTION)); + scm_c_define ("SDL_JOYBALLMOTION", scm_from_int (SDL_JOYBALLMOTION)); + scm_c_define ("SDL_JOYHATMOTION", scm_from_int (SDL_JOYHATMOTION)); + scm_c_define ("SDL_JOYBUTTONDOWN", scm_from_int (SDL_JOYBUTTONDOWN)); + scm_c_define ("SDL_JOYBUTTONUP", scm_from_int (SDL_JOYBUTTONUP)); + scm_c_define ("SDL_QUIT", scm_from_int (SDL_QUIT)); + scm_c_define ("SDL_SYSWMEVENT", scm_from_int (SDL_SYSWMEVENT)); + scm_c_define ("SDL_EVENT_RESERVEDA", scm_from_int (SDL_EVENT_RESERVEDA)); + scm_c_define ("SDL_EVENT_RESERVEDB", scm_from_int (SDL_EVENT_RESERVEDB)); + scm_c_define ("SDL_VIDEORESIZE", scm_from_int (SDL_VIDEORESIZE)); + scm_c_define ("SDL_VIDEOEXPOSE", scm_from_int (SDL_VIDEOEXPOSE)); + scm_c_define ("SDL_EVENT_RESERVED2", scm_from_int (SDL_EVENT_RESERVED2)); + scm_c_define ("SDL_EVENT_RESERVED3", scm_from_int (SDL_EVENT_RESERVED3)); + scm_c_define ("SDL_EVENT_RESERVED4", scm_from_int (SDL_EVENT_RESERVED4)); + scm_c_define ("SDL_EVENT_RESERVED5", scm_from_int (SDL_EVENT_RESERVED5)); + scm_c_define ("SDL_EVENT_RESERVED6", scm_from_int (SDL_EVENT_RESERVED6)); + scm_c_define ("SDL_EVENT_RESERVED7", scm_from_int (SDL_EVENT_RESERVED7)); + scm_c_define ("SDL_USEREVENT", scm_from_int (SDL_USEREVENT)); + scm_c_define ("SDL_NUMEVENTS", scm_from_int (SDL_NUMEVENTS)); + scm_c_define_gsubr ("SDL_Init", 1, 0, 0, gacela_SDL_Init); scm_c_define_gsubr ("SDL_Quit", 0, 0, 0, gacela_SDL_Quit); scm_c_define_gsubr ("SDL_SetVideoMode", 4, 0, 0, gacela_SDL_SetVideoMode); scm_c_define_gsubr ("SDL_WM_SetCaption", 2, 0, 0, gacela_SDL_WM_SetCaption); scm_c_define_gsubr ("SDL_Flip", 1, 0, 0, gacela_SDL_Flip); - scm_c_define_gsubr ("SDL_FreeSurface", 1, 0, 0, gacela_SDL_FreeSurface); scm_c_define_gsubr ("SDL_Delay", 1, 0, 0, gacela_SDL_Delay); scm_c_define_gsubr ("SDL_GetTicks", 0, 0, 0, gacela_SDL_GetTicks); scm_c_define_gsubr ("SDL_DisplayFormat", 1, 0, 0, gacela_SDL_DisplayFormat); @@ -343,7 +449,6 @@ SDL_register_functions (void* data) scm_c_define_gsubr ("Mix_FreeMusic", 1, 0, 0, gacela_Mix_FreeMusic); scm_c_define_gsubr ("Mix_FreeChunk", 1, 0, 0, gacela_Mix_FreeChunk); scm_c_define_gsubr ("Mix_CloseAudio", 0, 0, 0, gacela_Mix_CloseAudio); - scm_c_define_gsubr ("make-surface", 1, 0, 0, gacela_make_surface); return NULL; } diff --git a/src/gacela_draw.scm b/src/gacela_draw.scm new file mode 100644 index 0000000..f5f239b --- /dev/null +++ b/src/gacela_draw.scm @@ -0,0 +1,190 @@ +;;; 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-macro (with-color color . code) + (cond (color + `(let ((original-color (get-current-color)) + (result #f)) + (apply set-current-color ,color) + (set! result (begin ,@code)) + (apply set-current-color original-color) + result)) + (else `(begin ,@code)))) + +(define-macro (progn-textures . code) + `(let (values) + (init-video-mode) + (glEnable GL_TEXTURE_2D) + (set! values (multiple-value-list (begin ,@code))) + (glDisable GL_TEXTURE_2D) + (apply values values))) + +(define (draw . vertexes) + (begin-draw (length vertexes)) + (draw-vertexes vertexes) + (glEnd)) + +(define (begin-draw number-of-points) + (cond ((= number-of-points 3) (glBegin GL_TRIANGLES)) + ((= number-of-points 4) (glBegin GL_QUADS)))) + +(define (draw-vertexes vertexes) + (cond ((not (null? vertexes)) + (draw-vertex (car vertexes)) + (draw-vertexes (cdr vertexes))))) + +(define* (draw-vertex vertex #:key texture-coord) + (cond ((list? (car vertex)) + (with-color (car vertex) + (apply simple-draw-vertex (cadr vertex)))) + (else + (cond (texture-coord (apply glTexCoord2f texture-coord))) + (apply simple-draw-vertex vertex)))) + +(define* (simple-draw-vertex x y #:optional (z 0)) + (cond ((3d-mode?) (glVertex3f x y z)) + (else (glVertex2f x y)))) + +(define (load-image-for-texture filename) + (init-video-mode) + (let ((image (IMG_Load filename))) + (cond ((not (= image 0)) + (let* ((width (surface-w image)) (height (surface-h image)) + (power-2 (nearest-power-of-two (min width height))) + resized-image) + (cond ((and (= width power-2) (= height power-2)) (values image width height)) + (t (setq resized-image (resize-surface image power-2 power-2)) + (SDL_FreeSurface image) + (cond ((/= resized-image 0) (values resized-image width height)))))))))) + +(defun resize-surface (surface width height) + (let ((old-width (surface-w surface)) (old-height (surface-h surface))) + (cond ((and (= width old-width) (= height old-height)) surface) + (t (let ((zoomx (/ (+ width 0.5) old-width)) (zoomy (/ (+ height 0.5) old-height))) + (zoomSurface surface zoomx zoomy 0)))))) + +(defun load-texture (filename &key (min-filter GL_LINEAR) (mag-filter GL_LINEAR) static) + (let ((key (make-resource-texture :filename filename :min-filter min-filter :mag-filter mag-filter))) + (cond ((get-resource key) key) + (t (true-load-texture filename min-filter mag-filter static))))) + +(defun true-load-texture (filename min-filter mag-filter static) + (let ((key (make-resource-texture :filename filename :min-filter min-filter :mag-filter mag-filter))) + (progn-textures + (multiple-value-bind + (image real-w real-h) (load-image-for-texture filename) + (cond (image + (let ((width (surface-w image)) (height (surface-h image)) + (byteorder (if (= (SDL_ByteOrder) SDL_LIL_ENDIAN) + (if (= (surface-format-BytesPerPixel image) 3) GL_BGR GL_BGRA) + (if (= (surface-format-BytesPerPixel image) 3) GL_RGB GL_RGBA))) + (texture (car (glGenTextures 1)))) + + (glBindTexture GL_TEXTURE_2D texture) + (glTexImage2D GL_TEXTURE_2D 0 3 width height 0 byteorder GL_UNSIGNED_BYTE (surface-pixels image)) + (glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER min-filter) + (glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER mag-filter) + (SDL_FreeSurface image) + (set-resource key + `(:id-texture ,texture :width ,real-w :height ,real-h) + (lambda () (true-load-texture filename min-filter mag-filter static)) + (lambda () (glDeleteTextures 1 `(,texture))) + :static static) + key))))))) + +(defun draw-image (filename &ptional (zoom 1)) + (let ((texture (load-texture filename))) + (cond (texture (draw-texture texture zoom))))) + +(defun draw-texture (texture &optional (zoom 1)) + (cond (texture + (let ((width (getf (get-resource texture) :width)) + (height (getf (get-resource texture) :height))) + (draw-rectangle (* zoom width) (* zoom height) :texture texture))))) + +(defun draw-quad (v1 v2 v3 v4 &key texture) + (let ((id-texture (getf (get-resource texture) :id-texture))) + (cond (id-texture + (progn-textures + (glBindTexture GL_TEXTURE_2D id-texture) + (begin-draw 4) + (draw-vertex v1 :texture-coord '(0 0)) + (draw-vertex v2 :texture-coord '(1 0)) + (draw-vertex v3 :texture-coord '(1 1)) + (draw-vertex v4 :texture-coord '(0 1)) + (glEnd))) + ((consp texture) (with-color texture (draw v1 v2 v3 v4))) + (t (draw v1 v2 v3 v4))))) + +(defun draw-rectangle (width height &key texture) + (let* ((w (/ width 2)) (-w (neg w)) (h (/ height 2)) (-h (neg h))) + (draw-quad (list -w h 0) (list w h 0) (list w -h 0) (list -w -h 0) :texture texture))) + +(defun draw-square (&key (size 1) texture) + (draw-rectangle size size :texture texture)) + +(defun draw-cube (&key (size 1) texture texture-1 texture-2 texture-3 texture-4 texture-5 texture-6) + (let ((-size (neg size))) + (progn-textures + (glNormal3f 0 0 1) + (draw-quad (list -size size size) (list size size size) (list size -size size) (list -size -size size) :texture (or texture-1 texture)) + (glNormal3f 0 0 -1) + (draw-quad (list -size -size -size) (list size -size -size) (list size size -size) (list -size size -size) :texture (or texture-2 texture)) + (glNormal3f 0 1 0) + (draw-quad (list size size size) (list -size size size) (list -size size -size) (list size size -size) :texture (or texture-3 texture)) + (glNormal3f 0 -1 0) + (draw-quad (list -size -size size) (list size -size size) (list size -size -size) (list -size -size -size) :texture (or texture-4 texture)) + (glNormal3f 1 0 0) + (draw-quad (list size -size -size) (list size -size size) (list size size size) (list size size -size) :texture (or texture-5 texture)) + (glNormal3f -1 0 0) + (draw-quad (list -size -size size) (list -size -size -size) (list -size size -size) (list -size size size) :texture (or texture-6 texture))))) + +(defun add-light (&key light position ambient (id GL_LIGHT1) (turn-on t)) + (init-lighting) + (and light (glLightfv id GL_DIFFUSE (first light) (second light) (third light) (fourth light))) + (and light position (glLightfv GL_POSITION (first position) (second position) (third position) (fourth position))) + (and ambient (glLightfv id GL_AMBIENT (first ambient) (second ambient) (third ambient) (fourth ambient))) + (and turn-on (glEnable id)) + id) + +(defun translate (x y &optional (z 0)) + (glTranslatef x y z)) + +(defun rotate (&rest rot) + (cond ((3d-mode?) (apply #'3d-rotate rot)) + (t (apply #'2d-rotate rot)))) + +(defun 3d-rotate (xrot yrot zrot) + (glRotatef xrot 1 0 0) + (glRotatef yrot 0 1 0) + (glRotatef zrot 0 0 1)) + +(defun 2d-rotate (rot) + (glRotatef rot 0 0 1)) + +(defun to-origin () + (glLoadIdentity) + (cond ((3d-mode?) (camera-look)))) + +(let ((camera-eye '(0 0 0)) (camera-center '(0 0 -100)) (camera-up '(0 1 0))) + (defun set-camera (&key eye center up) + (cond (eye (setq camera-eye eye))) + (cond (center (setq camera-center center))) + (cond (up (setq camera-up up)))) + + (defun camera-look () + (apply #'gluLookAt (concatenate 'list camera-eye camera-center camera-up)))) diff --git a/src/gacela_events.scm b/src/gacela_events.scm new file mode 100644 index 0000000..a57e9a1 --- /dev/null +++ b/src/gacela_events.scm @@ -0,0 +1,163 @@ +;;; 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 (get-event events types) + (cond ((null? events) '()) + (else + (let ((res (get-event (cdr events) types)) + (event (car events))) + (cond ((member (assoc-ref event 'type) types) (cons event res)) + (else res)))))) + +(define (poll-events) + (let ((event (SDL_PollEvent))) + (cond ((null? event) '()) + (else (cons event (poll-events)))))) + +(define (process-events) + (let ((events (poll-events))) + (quit? (not (null? (get-event events `(,SDL_QUIT))))) + (clear-key-state) + (process-keyboard-events (get-event events `(,SDL_KEYDOWN ,SDL_KEYUP))))) + +(define quit? #f) + +(let ((quit #f)) + (set! quit? + (lambda* (#:optional (value '())) + (if (null? value) quit (set! quit value))))) + +(define (process-keyboard-events events) + (cond ((not (null? events)) + (let ((event (car events))) + (cond ((= (assoc-ref event 'type) SDL_KEYDOWN) (key-press (assoc-ref event 'key.keysym.sym))) + ((= (assoc-ref event 'type) SDL_KEYUP) (key-release (assoc-ref event :key.keysym.sym))))) + (process-keyboard-events (cdr events))))) + +(define key? #f) +(define key-pressed? #f) +(define key-released? #f) +(define key-press #f) +(define key-release #f) +(define clear-keymap #f) +(define clear-key-state #f) + +(let ((keymap (make-hash-table)) + (pressed (make-hash-table)) + (released (make-hash-table))) + (set! key? + (lambda (key) + (hash-ref keymap (get-keycode key)))) + + (set! key-pressed? + (lambda (key) + (hash-ref pressed (get-keycode key)))) + + (set! key-released? + (lambda (key) + (hash-ref released (get-keycode key)))) + + (set! key-press + (lambda (key-code) + (hash-set! keymap key-code #t) + (hash-set! pressed key-code #t) + (hash-set! released key-code #f))) + + (set! key-release + (lambda (key-code) + (hash-set! keymap key-code #f) + (hash-set! pressed key-code #f) + (hash-set! released key-code #t))) + + (set! clear-keymap + (lambda () + (hash-clear! keymap))) + + (set! clear-key-state + (lambda () + (hash-clear! pressed) + (hash-clear! released)))) + +(define get-keycode #f) +(define get-keyname #f) + +(let* ((keys + '((8 . backspace) + (9 . tab) + (12 . clear) + (13 . return) + (19 . pause) + (27 . escape) + (32 . space) + (33 . exclaim) + (34 . quotedbl) + (35 . hash) + (36 . dollar) + (38 . ampersand) + (39 . quote) + (40 . leftparen) + (41 . rightparen) + (42 . asterisk) + (43 . plus) + (44 . comma) + (45 . minus) + (46 . period) + (47 . slash) + (48 . 0) + (49 . 1) + (50 . 2) + (51 . 3) + (52 . 4) + (53 . 5) + (54 . 6) + (55 . 7) + (56 . 8) + (57 . 9) + (58 . colon) + (59 . semicolon) + (60 . less) + (61 . equals) + (62 . greater) + (63 . question) + (64 . at) + (269 . kp-minus) + (270 . kp-plus) + (273 . up) + (274 . down) + (275 . right) + (276 . left) + (282 . f1) + (283 . f2) + (284 . f3) + (285 . f4) + (286 . f5) + (287 . f6) + (288 . f7) + (289 . f8) + (290 . f9) + (291 . f10) + (292 . f11) + (293 . f12))) + (keynames (map (lambda (k) (cons (cdr k) (car k))) keys))) + + (set! get-keycode + (lambda (keyname) + (assoc-ref keynames keyname))) + + (set! get-keyname + (lambda (keycode) + (assoc-ref keys keycode)))) diff --git a/src/gacela_ttf.scm b/src/gacela_ttf.scm index 2281532..2a5caed 100644 --- a/src/gacela_ttf.scm +++ b/src/gacela_ttf.scm @@ -17,8 +17,8 @@ (define* (load-font font-file #:key (size 40) (encoding ft_encoding_unicode)) (let ((font (ftglCreateTextureFont font-file))) - (ftglSetFontFaceSize font size 72) - (ftglSetFontCharMap font encoding) +; (ftglSetFontFaceSize font size 72) +; (ftglSetFontCharMap font encoding) font)) (define* (render-text text font #:key (size #f))