]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - examples/01-hello-world.scm
Rename examples
[guile-irrlicht.git] / examples / 01-hello-world.scm
diff --git a/examples/01-hello-world.scm b/examples/01-hello-world.scm
new file mode 100644 (file)
index 0000000..b480c89
--- /dev/null
@@ -0,0 +1,72 @@
+;;; guile-irrlicht --- FFI bindings for Irrlicht Engine
+;;; Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
+;;;
+;;; 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
+;;; <http://www.gnu.org/licenses/>.
+
+
+;;; Irrlicht 01.HelloWorld example
+;;; http://irrlicht.sourceforge.net/docu/example001.html
+
+
+(use-modules (irrlicht))
+
+;; start up the engine
+(define device
+  (create-device
+   #:device-type 'software
+   #:window-size '(640 480)))
+(when (not device)
+  (exit #f))
+
+(set-window-caption! device "Hello World! - Irrlicht Engine Demo")
+
+(define driver (get-video-driver device))
+(define scene-manager (get-scene-manager device))
+(define gui-env (get-gui-environment device))
+
+;; static text
+(add-static-text!
+ gui-env
+ "Hello World! This is the Irrlicht Software renderer!"
+ '(10 10 260 22)
+ #:border #t)
+
+;; load a Quake2 model
+(define mesh (get-mesh scene-manager "media/sydney.md2"))
+(when (not mesh)
+  (drop! device)
+  (exit #f))
+
+(define node (add-animated-mesh-scene-node! scene-manager mesh))
+(when node
+  (set-material-flag! node 'lighting #f)
+  (set-md2-animation! node 'stand)
+  (set-material-texture! node 0 (get-texture driver "media/sydney.bmp")))
+
+;; place camera
+(add-camera-scene-node! scene-manager #:position '(0 30 -40) #:lookat '(0 5 0))
+
+;; draw everything
+(while (run device)
+  (begin-scene driver #:color '(255 100 101 140))
+  (draw-all scene-manager)
+  (draw-all gui-env)
+  (end-scene driver))
+
+;; delete device
+(drop! device)
+(exit #t)