#:use-module (gacela gl)
#:use-module (gacela ftgl)
#:use-module (gacela math)
+ #:use-module (gacela utils)
#:use-module (ice-9 optargs)
#:use-module (ice-9 receive)
#:export (init-video
3d-mode?
get-frames-per-second
set-frames-per-second!
+ get-fullscreen
+ set-fullscreen!
init-frame-time
get-frame-time
delay-frame
progn-textures
draw
load-texture
+ load-texture-without-cache
+ get-texture-properties
draw-texture
draw-line
draw-quad
set-camera
camera-look
load-font
+ load-font-without-texture
render-text)
- #:export-syntax (glmatrix-block)
#:re-export (glPushMatrix
- glPopMatrix))
+ glPopMatrix)
+ #:export-syntax (glmatrix-block))
(define screen #f)
(define flags 0)
-(define* (init-video width height bpp #:key (mode '2d) (title "") (fps 20))
+(define* (init-video width height bpp #:key (mode '2d) (title "") (fps 20) (fullscreen 'off))
(SDL_Init SDL_INIT_VIDEO)
(let ((info (SDL_GetVideoInfo)))
(SDL_GL_SetAttribute SDL_GL_DOUBLEBUFFER 1)
(set! flags (+ SDL_OPENGL SDL_GL_DOUBLEBUFFER SDL_HWPALETTE SDL_RESIZABLE
(if (= (assoc-ref info 'hw_available) 0) SDL_SWSURFACE SDL_HWSURFACE)
- (if (= (assoc-ref info 'blit_hw) 0) 0 SDL_HWACCEL)))
+ (if (= (assoc-ref info 'blit_hw) 0) 0 SDL_HWACCEL)
+ (if (eq? fullscreen 'on) SDL_FULLSCREEN 0)))
(set! screen (SDL_SetVideoMode width height bpp flags))
(set-screen-title! title)
(set-frames-per-second! fps)
+ (set-fullscreen! fullscreen #f)
(init-gl)
(if (eq? mode '3d) (set-3d-mode) (set-2d-mode))))
(define (set-screen-bpp! bpp)
(cond (screen
- (set! screen (SDL_SetVideoMode (get-screen-width) (get-screen-height) bpp flags)))))
+ (set! screen (SDL_SetVideoMode (get-screen-width) (get-screen-height) (get-screen-bpp) flags)))))
(define (resize-screen width height)
(cond (screen
(eq? mode '3d))
+(define fullscreen 'off)
+
+(define* (set-fullscreen! fs #:optional (toggle #t))
+ (cond ((or (and (eq? fullscreen 'on) (eq? fs 'off))
+ (and (eq? fullscreen 'off) (eq? fs 'on)))
+ (set! fullscreen fs)
+ (cond (toggle
+ (SDL_WM_ToggleFullScreen screen))))))
+
+(define (get-fullscreen)
+ fullscreen)
+
+
(define (init-gl)
(glShadeModel GL_SMOOTH)
(glClearColor 0 0 0 0)
(else (let ((zoomx (/ (+ width 0.5) old-width)) (zoomy (/ (+ height 0.5) old-height)))
(zoomSurface surface zoomx zoomy 0))))))
-(define* (load-texture filename #:key (min-filter GL_LINEAR) (mag-filter GL_LINEAR))
+(define* (load-texture-without-cache filename #:key (min-filter GL_LINEAR) (mag-filter GL_LINEAR))
(progn-textures
(receive
(image real-w real-h) (load-image-for-texture filename)
(set-texture-size! texture real-w real-h)
texture))))))
-(define* (draw-texture texture #:optional (zoom 1))
+(define load-texture (use-cache-with load-texture-without-cache))
+
+(define (get-texture-properties texture)
+ `((width . ,(texture-w texture)) (height . ,(texture-h texture))))
+
+(define* (draw-texture texture #:key (zoom 1) (sprite '((0 0) (1 1))))
(cond (texture
(let ((width (texture-w texture))
(height (texture-h texture)))
- (draw-rectangle (* zoom width) (* zoom height) #:texture texture)))))
+ (draw-rectangle (* zoom width (- (caadr sprite) (caar sprite)))
+ (* zoom height (- (cadadr sprite) (cadar sprite)))
+ #:texture texture
+ #:texture-coord sprite)))))
(define* (draw-line length #:optional color)
(let ((l (/ length 2)))
(else
(draw (list 0 l) (list 0 (- l)))))))
-(define* (draw-quad v1 v2 v3 v4 #:key texture color)
+(define* (draw-quad v1 v2 v3 v4 #:key texture color (texture-coord '((0 0) (1 1))))
(cond (texture
(progn-textures
(glBindTexture GL_TEXTURE_2D 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))
+ (draw-vertex v1 #:texture-coord (car texture-coord))
+ (draw-vertex v2 #:texture-coord (list (caadr texture-coord) (cadar texture-coord)))
+ (draw-vertex v3 #:texture-coord (cadr texture-coord))
+ (draw-vertex v4 #:texture-coord (list (caar texture-coord) (cadadr texture-coord)))
(glEnd)))
(color
(with-color color (draw v1 v2 v3 v4)))
(else
(draw v1 v2 v3 v4))))
-(define* (draw-rectangle width height #:key texture color)
+(define* (draw-rectangle width height #:key texture color texture-coord)
(let ((w (/ width 2)) (h (/ height 2)))
(draw-quad (list (- w) h 0)
(list w h 0)
(list w (- h) 0)
(list (- w) (- h) 0)
#:texture texture
+ #:texture-coord texture-coord
#:color color)))
(define* (draw-square #:key (size 1) texture color)
(define* (translate x y #:optional (z 0))
(glTranslatef x y z))
-(define* (rotate #:rest rot)
+(define (rotate . rot)
(cond ((3d-mode?)
(apply 3d-rotate rot))
(else
- (apply 2d-rotate rot))))
+ (2d-rotate (car (last-pair rot))))))
(define (3d-rotate xrot yrot zrot)
(glRotatef xrot 1 0 0)
;;; Text and fonts
-(define* (load-font font-file #:key (size 40) (encoding ft_encoding_unicode))
+(define* (load-font-without-cache font-file #:key (size 40) (encoding ft_encoding_unicode))
(let ((font (ftglCreateTextureFont font-file size)))
(ftglSetFontFaceSize font size 72)
(ftglSetFontCharMap font encoding)
font))
+(define load-font (use-cache-with load-font-without-cache))
+
(define* (render-text text font #:key (size #f))
(cond (size
(cond ((not (= (ftglGetFontFaceSize font) size))