! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel accessors arrays alien system combinators
-alien.syntax namespaces alien.c-types sequences vocabs
-shuffle openal openal.alut.backend alien.libraries generalizations
-specialized-arrays alien.destructors ;
-FROM: alien.c-types => float short ;
+USING: alien alien.c-types alien.libraries alien.syntax
+combinators kernel namespaces openal openal.alut.backend
+specialized-arrays system vocabs ;
SPECIALIZED-ARRAY: uint
+FROM: alien.c-types => float short ;
IN: openal.alut
<< "alut" {
SYMBOL: init
+: throw-alut-error ( -- )
+ alutGetError alutGetErrorString throw ;
+
: init-openal ( -- )
init get-global expired? [
- f f alutInit 0 = [ "Could not initialize OpenAL" throw ] when
+ f f alutInit 0 = [ throw-alut-error ] when
1337 <alien> init set-global
] when ;
: exit-openal ( -- )
init get-global expired? [
- alutExit 0 = [ "Could not close OpenAL" throw ] when
+ alutExit 0 = [ throw-alut-error ] when
f init set-global
] unless ;
: create-buffer-from-file ( filename -- buffer )
alutCreateBufferFromFile dup AL_NONE = [
- "create-buffer-from-file failed" throw
+ throw-alut-error
] when ;
os macosx? "openal.alut.macosx" "openal.alut.other" ? require
: create-buffer-from-wav ( filename -- buffer )
gen-buffer dup rot load-wav-file
- [ alBufferData ] 4 nkeep alutUnloadWAV ;
+ [ alBufferData ] 4keep alutUnloadWAV ;
: check-error ( -- )
alGetError dup ALUT_ERROR_NO_ERROR = [