X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=examples%2F02-quake3map.scm;fp=examples%2F02-quake3map.scm;h=208740127c5ba01c2d7ab41352e35911bf8499b6;hb=9137f8fdb1e89ffdec1fb498084f71e92e7f02a9;hp=0000000000000000000000000000000000000000;hpb=0cb94da9c4b0cc97e1a6e3452922b78f9f84124e;p=guile-irrlicht.git diff --git a/examples/02-quake3map.scm b/examples/02-quake3map.scm new file mode 100644 index 0000000..2087401 --- /dev/null +++ b/examples/02-quake3map.scm @@ -0,0 +1,96 @@ +;;; guile-irrlicht --- FFI bindings for Irrlicht Engine +;;; Copyright (C) 2019 Javier Sancho +;;; +;;; This file is part of guile-irrlicht. +;;; +;;; Guile-irrlicht is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; Guile-irrlicht 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 Lesser General Public +;;; License along with guile-irrlicht. If not, see +;;; . + + +;;; Irrlicht 02.Quake3Map example +;;; http://irrlicht.sourceforge.net/docu/example002.html + + +(use-modules (irrlicht) + (ice-9 match)) + +;; ask user for driver +(format #t + "Please select the driver you want for this example: + (a) OpenGL 1.5 + (b) Direct3D 9.0c + (c) Direct3D 8.1 + (d) Burning's Software Renderer + (e) Software Renderer + (f) NullDevice + (otherKey) exit~%~%") + +(define driver (match (read-char) + (#\a 'opengl) + (#\b 'direct3d9) + (#\c 'direct3d8) + (#\d 'burnings) + (#\e 'software) + (#\f 'null) + (_ #f))) + +(when (not driver) + (exit #f)) + +;; start up the engine +(define device + (create-device + #:device-type driver + #:window-size '(640 480))) +(when (not device) + (exit #f)) + +;; instances for doing things +(define driver (get-video-driver device)) +(define scene-manager (get-scene-manager device)) +(define driver-name (get-name driver)) + +;; load Quake3 map +(add-file-archive! (get-file-system device) "media/map-20kdm2.pk3") + +(define mesh (get-mesh scene-manager "20kdm2.bsp")) +(define node (add-octree-scene-node! + scene-manager mesh + #:minimal-polys-per-node 1024)) +(set-position! node '(-1300 -144 -1249)) + +;; FPS camera +(add-camera-scene-node-fps! scene-manager) +(set-visible! (get-cursor-control device) #f) + +;; loop +(define last-fps -1) +(while (run device) + (cond ((is-window-active? device) + (begin-scene driver #:color '(255 200 200 200)) + (draw-all scene-manager) + (end-scene driver) + + (let ((fps (get-fps driver))) + (when (not (= last-fps fps)) + (let ((caption + (format #f "Irrlicht Engine - Quake 3 Map example [~a] FPS:~a" driver-name fps))) + (set-window-caption! device caption)) + (set! last-fps fps)))) + (else + ((@ (irrlicht) yield) device)))) + +;; delete device +(drop! device) +(exit #t)