--- /dev/null
+;;; 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 'software '(640 480) 16 #f #f #f))
+(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)
+ #t)
+
+;; draw everything
+(while (device-run? device)
+ (begin-scene driver #t #t '(255 100 101 140))
+ (gui-draw-all gui-env)
+ (end-scene driver))
+
+;; delete device
+(device-drop! device)
+(exit #t)
+++ /dev/null
-;;; 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/>.
-
-
-(use-modules (irrlicht))
-
-;; Create device
-(define device (create-device 'software '(640 480) 16 #f #f #f))
-(when (not device)
- (exit #f))
-
-(define driver (get-video-driver device))
-(define scene-manager (get-scene-manager device))
-
-(set-window-caption! device "Hello World!")
-
-(while (device-run? device))
-
-(device-drop! device)
#:use-module (system foreign)
#:use-module ((irrlicht bindings) #:prefix ffi:)
#:use-module ((irrlicht bindings core) #:prefix ffi-core:)
+ #:use-module ((irrlicht bindings gui) #:prefix ffi-gui:)
#:use-module ((irrlicht bindings video) #:prefix ffi-video:)
- #:export (create-device
+ #:export (;; device
+ create-device
get-video-driver
+ get-gui-environment
get-scene-manager
set-window-caption!
device-run?
- device-drop!))
+ device-drop!
+ ;; driver
+ begin-scene
+ end-scene
+ ;; gui
+ add-static-text!
+ gui-draw-all))
+;; Device functions
(define* (create-device #:optional
(device-type 'software)
(window-size '(640 480))
(define (get-video-driver device)
(ffi:get-video-driver device))
+(define (get-gui-environment device)
+ (ffi:get-gui-environment device))
+
(define (get-scene-manager device)
(ffi:get-scene-manager device))
(define (device-drop! device)
(if (> (ffi:drop device) 0) #t #f))
+
+
+;; Driver functions
+(define* (begin-scene driver
+ #:optional
+ (back-buffer #t)
+ (z-buffer #t)
+ (color '(255 0 0 0))
+ (video-data %null-pointer)
+ (source-rect '()))
+ (ffi-video:begin-scene driver
+ (if back-buffer 1 0)
+ (if z-buffer 1 0)
+ (make-c-struct ffi-video:scolor color)
+ video-data
+ (if (null? source-rect)
+ %null-pointer
+ (make-c-struct ffi-core:rect source-rect))))
+
+(define (end-scene driver)
+ (ffi-video:end-scene driver))
+
+
+;; GUI functions
+(define* (add-static-text! gui-env text rectangle
+ #:optional
+ (border #f)
+ (word-wrap #t)
+ (parent %null-pointer)
+ (id -1)
+ (fill-background #f))
+ (ffi-gui:add-static-text gui-env
+ (string->pointer text)
+ (make-c-struct ffi-core:rect rectangle)
+ (if border 1 0)
+ (if word-wrap 1 0)
+ parent
+ id
+ (if fill-background 1 0)))
+
+(define (gui-draw-all gui-env)
+ (ffi-gui:draw-all gui-env))
(dynamic-func "irr_IrrlichtDevice_getVideoDriver" cirr)
(list '*)))
+(define-public get-gui-environment
+ (pointer->procedure
+ '*
+ (dynamic-func "irr_IrrlichtDevice_getGUIEnvironment" cirr)
+ (list '*)))
+
(define-public get-scene-manager
(pointer->procedure
'*
;; dimension2d struct
(define-public dimension2d
(list uint32 uint32))
+
+;; rect struct
+(define-public rect
+ (list int32 int32 int32 int32))
--- /dev/null
+;;; 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/>.
+
+
+(define-module (irrlicht bindings gui)
+ #:use-module (system foreign))
+
+(define cirr (dynamic-link "libCIrrlicht"))
+
+(define-public add-static-text
+ (pointer->procedure
+ '*
+ (dynamic-func "irr_gui_IGUIEnvironment_addStaticText" cirr)
+ (list '* '* '* int int '* int int)))
+
+(define-public draw-all
+ (pointer->procedure
+ void
+ (dynamic-func "irr_gui_IGUIEnvironment_drawAll" cirr)
+ (list '*)))
;;; <http://www.gnu.org/licenses/>.
-(define-module (irrlicht bindings video))
+(define-module (irrlicht bindings video)
+ #:use-module (system foreign))
+
+(define cirr (dynamic-link "libCIrrlicht"))
;; E_DRIVER_TYPE enum
(define-public EDT_NULL 0)
(define-public EDT_DIRECT3D9 4)
(define-public EDT_OPENGL 5)
(define-public EDT_COUNT 6)
+
+;; scolor struct
+(define-public scolor
+ (list uint32 uint32 uint32 uint32))
+
+;; Driver functions
+(define-public begin-scene
+ (pointer->procedure
+ int
+ (dynamic-func "irr_video_IVideoDriver_beginScene" cirr)
+ (list '* int int '* '* '*)))
+
+(define-public end-scene
+ (pointer->procedure
+ int
+ (dynamic-func "irr_video_IVideoDriver_endScene" cirr)
+ (list '*)))