From: Javier Sancho Date: Thu, 14 Jun 2012 19:24:26 +0000 (+0200) Subject: Fullscreen mode. X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=e2b3664ab965f251fb9ec1e5588510293ef52e61;hp=6db93f044c899a6b7ce0166d9909711f8b414791;p=gacela.git Fullscreen mode. --- diff --git a/src/gacela.scm b/src/gacela.scm index 9096ddf..63d6bd3 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -151,8 +151,9 @@ (define *bpp-screen* 32) (define *frames-per-second* 20) (define *mode* '2d) +(define *fullscreen* 'off) -(define* (set-game-properties! #:key title width height bpp fps mode) +(define* (set-game-properties! #:key title width height bpp fps mode fullscreen) (if title (set-screen-title! title)) (if bpp @@ -166,10 +167,12 @@ (set-frames-per-second! fps)) (if mode (if (eq? mode '3d) (set-3d-mode) (set-2d-mode))) + (if fullscreen + (set-fullscreen! fullscreen)) (get-game-properties)) (define (get-game-properties) - `((title . ,(get-screen-title)) (width . ,(get-screen-width)) (height . ,(get-screen-height)) (bpp . ,(get-screen-bpp)) (fps . ,(get-frames-per-second)) (mode . ,(if (3d-mode?) '3d '2d)))) + `((title . ,(get-screen-title)) (width . ,(get-screen-width)) (height . ,(get-screen-height)) (bpp . ,(get-screen-bpp)) (fps . ,(get-frames-per-second)) (mode . ,(if (3d-mode?) '3d '2d)) (fullscreen . ,(get-fullscreen)))) ;;; Mobs Factory diff --git a/src/sdl.c b/src/sdl.c index c59d607..4fba1ff 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -176,6 +176,12 @@ gacela_SDL_WM_SetCaption (SCM title, SCM icon) return SCM_UNSPECIFIED; } +SCM +gacela_SDL_WM_ToggleFullScreen(SCM surface) +{ + return scm_from_int (SDL_WM_ToggleFullScreen (get_surface_address (surface))); +} + SCM gacela_SDL_Flip (SCM screen) { @@ -504,6 +510,7 @@ init_gacela_sdl (void *data) scm_c_define_gsubr ("SDL_SetVideoMode", 4, 0, 0, gacela_SDL_SetVideoMode); scm_c_define_gsubr ("SDL_FreeSurface", 1, 0, 0, gacela_SDL_FreeSurface); scm_c_define_gsubr ("SDL_WM_SetCaption", 2, 0, 0, gacela_SDL_WM_SetCaption); + scm_c_define_gsubr ("SDL_WM_ToggleFullScreen", 1, 0, 0, gacela_SDL_WM_ToggleFullScreen); scm_c_define_gsubr ("SDL_Flip", 1, 0, 0, gacela_SDL_Flip); scm_c_define_gsubr ("SDL_Delay", 1, 0, 0, gacela_SDL_Delay); scm_c_define_gsubr ("SDL_GetTicks", 0, 0, 0, gacela_SDL_GetTicks); diff --git a/src/video.scm b/src/video.scm index 466438f..ad74c86 100644 --- a/src/video.scm +++ b/src/video.scm @@ -39,6 +39,8 @@ 3d-mode? get-frames-per-second set-frames-per-second! + get-fullscreen + set-fullscreen! init-frame-time get-frame-time delay-frame @@ -74,16 +76,18 @@ (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)))) @@ -98,7 +102,7 @@ (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 @@ -146,6 +150,19 @@ (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)