Permalink
Browse files

Merge pull request #42 from joinr/master

Penumbra updated
  • Loading branch information...
2 parents 7fe9a3d + 30bd7a4 commit db43d01c280305beab26d1004ae78b1777ab3fc7 @ztellman committed on GitHub Jul 2, 2016
Showing with 721 additions and 106 deletions.
  1. +2 −1 .gitignore
  2. +17 −1 README.textile
  3. +12 −7 project.clj
  4. +2 −2 src/penumbra/app.clj
  5. +2 −2 src/penumbra/app/core.clj
  6. +3 −3 src/penumbra/app/input.clj
  7. +1 −2 src/penumbra/app/window.clj
  8. +2 −1 src/penumbra/compute.clj
  9. +175 −0 src/penumbra/def.clj
  10. +2 −2 src/penumbra/glsl/core.clj
  11. +3 −2 src/penumbra/glsl/operators.clj
  12. +113 −0 src/penumbra/imports.clj
  13. +114 −0 src/penumbra/meta.clj
  14. +1 −1 src/penumbra/openal/core.clj
  15. +40 −29 src/penumbra/opengl.clj
  16. +2 −2 src/penumbra/opengl/capabilities.clj
  17. +1 −1 src/penumbra/opengl/core.clj
  18. +2 −2 src/penumbra/opengl/frame_buffer.clj
  19. +1 −1 src/penumbra/opengl/geometry.clj
  20. +2 −2 src/penumbra/opengl/shader.clj
  21. +4 −5 src/penumbra/opengl/slate.clj
  22. +13 −3 src/penumbra/opengl/texture.clj
  23. +148 −0 src/penumbra/seq.clj
  24. +1 −1 src/penumbra/text.clj
  25. +1 −1 src/penumbra/time.clj
  26. +6 −4 src/penumbra/translate/c.clj
  27. +2 −2 src/penumbra/translate/core.clj
  28. +8 −6 src/penumbra/translate/operators.clj
  29. +2 −1 test/example/app/async.clj
  30. +3 −2 test/example/app/nested.clj
  31. +4 −4 test/example/app/switch.clj
  32. +4 −2 test/example/game/asteroids.clj
  33. +2 −1 test/example/game/pong.clj
  34. +3 −3 test/example/game/tetris.clj
  35. +3 −3 test/example/gpgpu/n_body.clj
  36. +2 −0 test/example/opengl/async.clj
  37. +3 −0 test/example/opengl/marble.clj
  38. +2 −0 test/example/opengl/render_to_texture.clj
  39. +2 −0 test/example/opengl/shadow.clj
  40. +5 −3 test/example/opengl/squares.clj
  41. +6 −4 test/example/wiki/clock3.clj
View
3 .gitignore
@@ -10,4 +10,5 @@ autodoc
*.jar
pom.xml
META-INF
-lein
+lein
+*.clj~
View
18 README.textile
@@ -1,4 +1,20 @@
-*Penumbra is not under active development.* However, it's still a fun way to play around with OpenGL and Clojure. Bugs will be fixed, time permitting, but new features are unlikely.
+Port of legacy Penumbra circa Clojure 1.2 to Clojure 1.8+
+
+This is an update of Zach Tellman's impressive penumbra library.
+All of the legacy cruft from clojure.contrib has been migrated or
+removed. Currently this is a stability release intended to get the
+examples working. They all compile and run, however, many of the
+examples that rely on shader implementations (like a bunch of the
+demos in test/examples/opengl) rather than the fixed function
+pipeline, will drop out when you run them.
+
+I'm not sure where to go with this library, but it seemed a waste to
+leave it in the dustbin. I'm currently evaluating alternatives for
+rendering, and I remembered penumbra.
+-Tom
+
+*Penumbra is not under active development.*
+However, it's still a fun way to play around with OpenGL and Clojure. Bugs will be fixed, time permitting, but new features are unlikely.
Penumbra is an idiomatic wrapper for OpenGL in Clojure, by way of LWJGL.
View
19 project.clj
@@ -1,11 +1,16 @@
-(defproject penumbra "0.6.0"
+(defproject penumbra "0.6.1"
:description "An idiomatic wrapper for OpenGL"
:dependencies [[slick-util "1.0.0"]
[cantor "0.3.0"]
- [org.clojure/clojure "1.2.0"]
- [org.clojure/clojure-contrib "1.2.0"]
- [org.clojars.charles-stain/lwjgl "3.0"]
- [org.lwjgl/lwjgl-util "2.7.1"]
- [org.clojars.charles-stain/jme3-lwjgl-natives "3.0"]]
+ [org.clojure/clojure "1.8.0"]
+ [org.clojure/math.combinatorics "0.1.3"]
+; [org.clojure/clojure-contrib "1.2.0"]
+ [org.clojars.charles-stain/lwjgl "3.0"]
+ [org.lwjgl/lwjgl-util "2.7.1"]
+ [org.clojars.charles-stain/jme3-lwjgl-natives "3.0"]]
:java-source-paths ["java"]
- :dev-dependencies [[swank-clojure "1.3.0"]])
+ :plugins [[lein-localrepo "0.5.3"]]
+ :profiles {:dev {:source-paths ["src"
+ "test"]}}
+ ;:dev-dependencies [[swank-clojure "1.3.0"]]
+ )
View
4 src/penumbra/app.clj
@@ -8,8 +8,8 @@
;; software.
(ns penumbra.app
- (:use [clojure.contrib.core :only (-?>)]
- [clojure.contrib.def :only [defmacro- defvar-]]
+ (:use
+ [penumbra.def :only [defmacro- defvar-]]
[penumbra.opengl]
[penumbra.opengl.core]
[clojure.walk :only (postwalk-replace)])
View
4 src/penumbra/app/core.clj
@@ -7,7 +7,7 @@
;; You must not remove this notice, or any other, from this software.
(ns penumbra.app.core
- (:use [clojure.contrib.def :only [defvar]]))
+ (:use [penumbra.def :only [defvar]]))
(defvar *app* nil
"Current application.")
@@ -25,4 +25,4 @@
(defmacro with-app [app & body]
`(binding [*app* ~app]
- ~@body))
+ ~@body))
View
6 src/penumbra/app/input.clj
@@ -7,8 +7,8 @@
;; You must not remove this notice, or any other, from this software.
(ns penumbra.app.input
- (:use [clojure.contrib.seq :only [indexed]]
- [clojure.contrib.def :only [defvar]])
+ (:use [penumbra.seq :only [indexed]]
+ [penumbra.def :only [defvar]])
(:require [penumbra.app.window :as window]
[penumbra.app.event :as event])
(:import [org.lwjgl.input Keyboard Mouse]))
@@ -134,4 +134,4 @@
(mouse-location [_] (let [[w h] (window/size app)]
[(Mouse/getX) (- h (Mouse/getY))]))
(handle-mouse! [_] (dosync (alter buttons #(handle-mouse app %))))
- (handle-keyboard! [_] (dosync (alter keys #(handle-keyboard app %)))))))
+ (handle-keyboard! [_] (dosync (alter keys #(handle-keyboard app %)))))))
View
3 src/penumbra/app/window.clj
@@ -7,8 +7,7 @@
;; You must not remove this notice, or any other, from this software.
(ns penumbra.app.window
- (:use [penumbra.opengl]
- [clojure.contrib.core :only (-?>)])
+ (:use [penumbra.opengl])
(:require [penumbra.opengl
[texture :as texture]
[context :as context]]
View
3 src/penumbra/compute.clj
@@ -9,7 +9,8 @@
(ns penumbra.compute
(:require [penumbra.glsl.operators :as glsl]
[penumbra.opengl.texture :as tex]
- [clojure.contrib.def :only (defmacro-)])
+ [penumbra.def :only (defmacro-)]
+ )
(:use [penumbra.opengl.core :only (*render-to-screen?*)]
[cantor :only (rectangle-factors)]))
View
175 src/penumbra/def.clj
@@ -0,0 +1,175 @@
+;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and
+;; distribution terms for this software are covered by the Eclipse Public
+;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
+;; be found in the file epl-v10.html at the root of this distribution. By
+;; using this software in any fashion, you are agreeing to be bound by the
+;; terms of this license. You must not remove this notice, or any other,
+;; from this software.
+;;
+;; File: def.clj
+;;
+;; def.clj provides variants of def that make including doc strings and
+;; making private definitions more succinct.
+;;
+;; scgilardi (gmail)
+;; 17 May 2008
+
+;;Tom - Ripped functions we're actually using to eliminate dependency on
+;;contrib...
+
+(ns
+ #^{:author "Stephen C. Gilardi",
+ :doc "def.clj provides variants of def that make including doc strings and
+making private definitions more succinct."}
+ penumbra.def)
+
+
+;;added by tom to account for implicitly dynamic vars...
+(defn dynamic-meta [symb]
+ (let [nm (name symb)
+ fst (first nm)
+ lst (last nm)]
+ (if (and (= fst lst \*))
+ ;;dynamic var...
+ (merge (meta symb) {:dynamic true})
+ (meta symb))))
+
+;;modified by tom to account for implicitly dynamic vars...
+(defmacro defvar
+ "Defines a var with an optional intializer and doc string"
+ ([name]
+ `(def ~(with-meta name (dynamic-meta name))))
+ ([name init]
+ `(def ~(with-meta name (dynamic-meta name)) ~init))
+ ([name init doc]
+ `(def ~(with-meta name
+ (assoc (dynamic-meta name) :doc doc)) ~init)))
+
+;;original
+;; (defmacro defvar
+;; "Defines a var with an optional intializer and doc string"
+;; ([name]
+;; (list `def name))
+;; ([name init]
+;; (list `def name init))
+;; ([name init doc]
+;; (list `def (with-meta name (assoc (meta name) :doc doc)) init)))
+
+(defmacro defunbound
+ "Defines an unbound var with optional doc string"
+ ([name]
+ (list `def name))
+ ([name doc]
+ (list `def (with-meta name (assoc (meta name) :doc doc)))))
+
+(defmacro defmacro-
+ "Same as defmacro but yields a private definition"
+ [name & decls]
+ (list* `defmacro (with-meta name (assoc (meta name) :private true)) decls))
+
+(defmacro defvar-
+ "Same as defvar but yields a private definition"
+ [name & decls]
+ (list* `defvar (with-meta name (assoc (meta name) :private true)) decls))
+
+(defmacro defunbound-
+ "Same as defunbound but yields a private definition"
+ [name & decls]
+ (list* `defunbound (with-meta name (assoc (meta name) :private true)) decls))
+
+(defmacro defstruct-
+ "Same as defstruct but yields a private definition"
+ [name & decls]
+ (list* `defstruct (with-meta name (assoc (meta name) :private true)) decls))
+
+(defmacro defonce-
+ "Same as defonce but yields a private definition"
+ ([name expr]
+ (list `defonce (with-meta name (assoc (meta name) :private true)) expr))
+ ([name expr doc]
+ (list `defonce (with-meta name (assoc (meta name) :private true :doc doc)) expr)))
+
+(defmacro defalias
+ "Defines an alias for a var: a new var with the same root binding (if
+ any) and similar metadata. The metadata of the alias is its initial
+ metadata (as provided by def) merged into the metadata of the original."
+ ([name orig]
+ `(do
+ (alter-meta!
+ (if (.hasRoot (var ~orig))
+ (def ~name (.getRoot (var ~orig)))
+ (def ~name))
+ ;; When copying metadata, disregard {:macro false}.
+ ;; Workaround for http://www.assembla.com/spaces/clojure/tickets/273
+ #(conj (dissoc % :macro)
+ (apply dissoc (meta (var ~orig)) (remove #{:macro} (keys %)))))
+ (var ~name)))
+ ([name orig doc]
+ (list `defalias (with-meta name (assoc (meta name) :doc doc)) orig)))
+
+; defhinted by Chouser:
+(defmacro defhinted
+ "Defines a var with a type hint matching the class of the given
+ init. Be careful about using any form of 'def' or 'binding' to a
+ value of a different type. See http://paste.lisp.org/display/73344"
+ [sym init]
+ `(do
+ (def ~sym ~init)
+ (alter-meta! (var ~sym) assoc :tag (class ~sym))
+ (var ~sym)))
+
+; name-with-attributes by Konrad Hinsen:
+(defn name-with-attributes
+ "To be used in macro definitions.
+ Handles optional docstrings and attribute maps for a name to be defined
+ in a list of macro arguments. If the first macro argument is a string,
+ it is added as a docstring to name and removed from the macro argument
+ list. If afterwards the first macro argument is a map, its entries are
+ added to the name's metadata map and the map is removed from the
+ macro argument list. The return value is a vector containing the name
+ with its extended metadata map and the list of unprocessed macro
+ arguments."
+ [name macro-args]
+ (let [[docstring macro-args] (if (string? (first macro-args))
+ [(first macro-args) (next macro-args)]
+ [nil macro-args])
+ [attr macro-args] (if (map? (first macro-args))
+ [(first macro-args) (next macro-args)]
+ [{} macro-args])
+ attr (if docstring
+ (assoc attr :doc docstring)
+ attr)
+ attr (if (meta name)
+ (conj (meta name) attr)
+ attr)]
+ [(with-meta name attr) macro-args]))
+
+; defnk by Meikel Brandmeyer:
+(defmacro defnk
+ "Define a function accepting keyword arguments. Symbols up to the first
+ keyword in the parameter list are taken as positional arguments. Then
+ an alternating sequence of keywords and defaults values is expected. The
+ values of the keyword arguments are available in the function body by
+ virtue of the symbol corresponding to the keyword (cf. :keys destructuring).
+ defnk accepts an optional docstring as well as an optional metadata map."
+ [fn-name & fn-tail]
+ (let [[fn-name [args & body]] (name-with-attributes fn-name fn-tail)
+ [pos kw-vals] (split-with symbol? args)
+ syms (map #(-> % name symbol) (take-nth 2 kw-vals))
+ values (take-nth 2 (rest kw-vals))
+ sym-vals (apply hash-map (interleave syms values))
+ de-map {:keys (vec syms)
+ :or sym-vals}]
+ `(defn ~fn-name
+ [~@pos & options#]
+ (let [~de-map (apply hash-map options#)]
+ ~@body))))
+
+; defn-memo by Chouser:
+(defmacro defn-memo
+ "Just like defn, but memoizes the function using clojure.core/memoize"
+ [fn-name & defn-stuff]
+ `(do
+ (defn ~fn-name ~@defn-stuff)
+ (alter-var-root (var ~fn-name) memoize)
+(var ~fn-name)))
View
4 src/penumbra/glsl/core.clj
@@ -8,8 +8,8 @@
(ns penumbra.glsl.core
(:use [penumbra.translate core])
- (:use [clojure.contrib.def :only (defvar defvar- defmacro-)])
- (:use [clojure.contrib.pprint :only (pprint)])
+ (:use [penumbra.def :only (defvar defvar- defmacro-)])
+ (:use [clojure.pprint :only (pprint)])
(:import (java.text ParseException))
(:require [penumbra.translate.c :as c]))
View
5 src/penumbra/glsl/operators.clj
@@ -12,9 +12,10 @@
[penumbra.translate core operators]
[penumbra.glsl core]
[penumbra.opengl.context :only (draw-frame-buffer)]
- [clojure.contrib
+ [penumbra
(seq :only (separate indexed))
- (def :only (defvar- defn-memo))
+ (def :only (defvar- defn-memo))]
+ [clojure
(pprint :only (pprint))])
(:require [clojure.zip :as zip]
[penumbra.translate.c :as c]
View
113 src/penumbra/imports.clj
@@ -0,0 +1,113 @@
+(ns penumbra.imports)
+;;Code from Zachary Tellman's excellent Potemkin library,
+
+;;specifically for importing vars. Rather than add a full dependency
+;;on potemkin, I chose to extract the pieces I needed here.
+;;Copyright © 2013 Zachary Tellman
+;;Distributed under the MIT License. This means that pieces of this library may be
+;;copied into other libraries if they don't wish to have this as an explicit
+;;dependency, as long as it is credited within the code.
+
+(defn link-vars
+ "Makes sure that all changes to `src` are reflected in `dst`."
+ [src dst]
+ (add-watch src dst
+ (fn [_ src old new]
+ (alter-var-root dst (constantly @src))
+ (alter-meta! dst merge (dissoc (meta src) :name)))))
+
+(defmacro import-fn
+ "Given a function in another namespace, defines a function with the
+ same name in the current namespace. Argument lists, doc-strings,
+ and original line-numbers are preserved."
+ ([sym]
+ `(import-fn ~sym nil))
+ ([sym name]
+ (let [vr (resolve sym)
+ m (meta vr)
+ n (or name (:name m))
+ arglists (:arglists m)
+ protocol (:protocol m)]
+ (when-not vr
+ (throw (IllegalArgumentException. (str "Don't recognize " sym))))
+ (when (:macro m)
+ (throw (IllegalArgumentException.
+ (str "Calling import-fn on a macro: " sym))))
+
+ `(do
+ (def ~(with-meta n {:protocol protocol}) (deref ~vr))
+ (alter-meta! (var ~n) merge (dissoc (meta ~vr) :name))
+ (link-vars ~vr (var ~n))
+ ~vr))))
+
+(defmacro import-macro
+ "Given a macro in another namespace, defines a macro with the same
+ name in the current namespace. Argument lists, doc-strings, and
+ original line-numbers are preserved."
+ ([sym]
+ `(import-macro ~sym nil))
+ ([sym name]
+ (let [vr (resolve sym)
+ m (meta vr)
+ n (or name (with-meta (:name m) {}))
+ arglists (:arglists m)]
+ (when-not vr
+ (throw (IllegalArgumentException. (str "Don't recognize " sym))))
+ (when-not (:macro m)
+ (throw (IllegalArgumentException.
+ (str "Calling import-macro on a non-macro: " sym))))
+ `(do
+ (def ~n ~(resolve sym))
+ (alter-meta! (var ~n) merge (dissoc (meta ~vr) :name))
+ (.setMacro (var ~n))
+ (link-vars ~vr (var ~n))
+ ~vr))))
+
+(defmacro import-def
+ "Given a regular def'd var from another namespace, defined a new var with the
+ same name in the current namespace."
+ ([sym]
+ `(import-def ~sym nil))
+ ([sym name]
+ (let [vr (resolve sym)
+ m (meta vr)
+ n (or name (:name m))
+ n (with-meta n (if (:dynamic m) {:dynamic true} {}))
+ nspace (:ns m)]
+ (when-not vr
+ (throw (IllegalArgumentException. (str "Don't recognize " sym))))
+ `(do
+ (def ~n @~vr)
+ (alter-meta! (var ~n) merge (dissoc (meta ~vr) :name))
+ (link-vars ~vr (var ~n))
+ ~vr))))
+
+(defmacro import-vars
+ "Imports a list of vars from other namespaces."
+ [& syms]
+ (let [unravel (fn unravel [x]
+ (if (sequential? x)
+ (->> x
+ rest
+ (mapcat unravel)
+ (map
+ #(symbol
+ (str (first x)
+ (when-let [n (namespace %)]
+ (str "." n)))
+ (name %))))
+ [x]))
+ syms (mapcat unravel syms)]
+ `(do
+ ~@(map
+ (fn [sym]
+ (let [vr (resolve sym)
+ m (meta vr)]
+ (cond
+ (:macro m) `(import-macro ~sym)
+ (:arglists m) `(import-fn ~sym)
+ :else `(import-def ~sym))))
+ syms))))
+
+
+;;end Potemkin
View
114 src/penumbra/meta.clj
@@ -0,0 +1,114 @@
+(ns penumbra.meta)
+;;Code from Zachary Tellman's excellent Potemkin library,
+
+
+;;specifically for importing vars. Rather than add a full dependency
+;;on potemkin, I chose to extract the pieces I needed here.
+;;Copyright © 2013 Zachary Tellman
+;;Distributed under the MIT License. This means that pieces of this library may be
+;;copied into other libraries if they don't wish to have this as an explicit
+;;dependency, as long as it is credited within the code.
+
+(defn link-vars
+ "Makes sure that all changes to `src` are reflected in `dst`."
+ [src dst]
+ (add-watch src dst
+ (fn [_ src old new]
+ (alter-var-root dst (constantly @src))
+ (alter-meta! dst merge (dissoc (meta src) :name)))))
+
+(defmacro import-fn
+ "Given a function in another namespace, defines a function with the
+ same name in the current namespace. Argument lists, doc-strings,
+ and original line-numbers are preserved."
+ ([sym]
+ `(import-fn ~sym nil))
+ ([sym name]
+ (let [vr (resolve sym)
+ m (meta vr)
+ n (or name (:name m))
+ arglists (:arglists m)
+ protocol (:protocol m)]
+ (when-not vr
+ (throw (IllegalArgumentException. (str "Don't recognize " sym))))
+ (when (:macro m)
+ (throw (IllegalArgumentException.
+ (str "Calling import-fn on a macro: " sym))))
+
+ `(do
+ (def ~(with-meta n {:protocol protocol}) (deref ~vr))
+ (alter-meta! (var ~n) merge (dissoc (meta ~vr) :name))
+ (link-vars ~vr (var ~n))
+ ~vr))))
+
+(defmacro import-macro
+ "Given a macro in another namespace, defines a macro with the same
+ name in the current namespace. Argument lists, doc-strings, and
+ original line-numbers are preserved."
+ ([sym]
+ `(import-macro ~sym nil))
+ ([sym name]
+ (let [vr (resolve sym)
+ m (meta vr)
+ n (or name (with-meta (:name m) {}))
+ arglists (:arglists m)]
+ (when-not vr
+ (throw (IllegalArgumentException. (str "Don't recognize " sym))))
+ (when-not (:macro m)
+ (throw (IllegalArgumentException.
+ (str "Calling import-macro on a non-macro: " sym))))
+ `(do
+ (def ~n ~(resolve sym))
+ (alter-meta! (var ~n) merge (dissoc (meta ~vr) :name))
+ (.setMacro (var ~n))
+ (link-vars ~vr (var ~n))
+ ~vr))))
+
+(defmacro import-def
+ "Given a regular def'd var from another namespace, defined a new var with the
+ same name in the current namespace."
+ ([sym]
+ `(import-def ~sym nil))
+ ([sym name]
+ (let [vr (resolve sym)
+ m (meta vr)
+ n (or name (:name m))
+ n (with-meta n (if (:dynamic m) {:dynamic true} {}))
+ nspace (:ns m)]
+ (when-not vr
+ (throw (IllegalArgumentException. (str "Don't recognize " sym))))
+ `(do
+ (def ~n @~vr)
+ (alter-meta! (var ~n) merge (dissoc (meta ~vr) :name))
+ (link-vars ~vr (var ~n))
+ ~vr))))
+
+(defmacro import-vars
+ "Imports a list of vars from other namespaces."
+ [& syms]
+ (let [unravel (fn unravel [x]
+ (if (sequential? x)
+ (->> x
+ rest
+ (mapcat unravel)
+ (map
+ #(symbol
+ (str (first x)
+ (when-let [n (namespace %)]
+ (str "." n)))
+ (name %))))
+ [x]))
+ syms (mapcat unravel syms)]
+ `(do
+ ~@(map
+ (fn [sym]
+ (let [vr (resolve sym)
+ m (meta vr)]
+ (cond
+ (:macro m) `(import-macro ~sym)
+ (:arglists m) `(import-fn ~sym)
+ :else `(import-def ~sym))))
+ syms))))
+
+
+;;end Potemkin
View
2 src/penumbra/openal/core.clj
@@ -7,7 +7,7 @@
;; You must not remove this notice, or any other, from this software.
(ns penumbra.openal.core
- (:use [clojure.contrib.def])
+ (:use [penumbra.def])
(:import [org.lwjgl.openal AL AL10 AL11]
[java.lang.reflect Field Method]))
View
69 src/penumbra/opengl.clj
@@ -9,29 +9,31 @@
(ns ^{:author "Zachary Tellman"}
penumbra.opengl
(:use [penumbra.opengl core]
- [clojure.contrib.def :only (defn-memo defmacro- defvar)])
+ [penumbra.def :only (defn-memo defmacro- defvar)])
(:require [penumbra.opengl.texture :as tex]
[penumbra.data :as data]
[penumbra.opengl.frame-buffer :as fb]
[penumbra.opengl.shader :as shader]
[penumbra.opengl.effects :as fx]
[penumbra.glsl.core :as glsl]
[penumbra.opengl.geometry :as geometry]
- [penumbra.opengl.teapot :as t])
+ [penumbra.opengl.teapot :as t]
+ [penumbra.meta :as import])
(:import (org.lwjgl BufferUtils)
(java.io File ByteArrayOutputStream ByteArrayInputStream)
(javax.imageio ImageIO)
(org.newdawn.slick.opengl InternalTextureLoader Texture TextureImpl)))
;;;
-(defmacro- import-fn [sym]
- (let [m (meta (eval sym))
- m (meta (intern (:ns m) (:name m)))
- n (:name m)
- arglists (:arglists m)
- doc (:doc m)]
- (list `def (with-meta n {:doc doc :arglists (list 'quote arglists)}) (eval sym))))
+;;out of date..doesn't work with current clojure definitions. using potemkin instead.
+;; (defmacro- import-fn [sym]
+;; (let [m (meta (eval sym))
+;; m (meta (intern (:ns m) (:name m)))
+;; n (:name m)
+;; arglists (:arglists m)
+;; doc (:doc m)]
+;; (list `def (with-meta n {:doc doc :arglists (list 'quote arglists)}) (eval sym))))
;;;
@@ -155,17 +157,19 @@
(gl-matrix-mode :modelview))
;;Geometry
-
-(import-fn geometry/vertex)
-(import-fn geometry/normal)
-(import-fn geometry/texture)
-(import-fn geometry/attribute)
-(import-fn geometry/rotate)
-(import-fn geometry/scale)
-(import-fn geometry/color)
-(import-fn geometry/translate)
-(import-fn geometry/load-identity)
-(import-fn geometry/declare-attributes)
+;;replaced old import-fn
+(import/import-vars
+ [penumbra.opengl.geometry
+ vertex
+ normal
+ texture
+ attribute
+ rotate
+ scale
+ color
+ translate
+ load-identity
+ declare-attributes])
(defmacro push-matrix [& body]
`(geometry/with-transform- *renderer* (fn [] ~@body)))
@@ -230,11 +234,15 @@
(gl-import+ glBlendFunc blend-func)
(gl-import+ glShadeModel shade-model)
-(import-fn fx/render-mode)
-(import-fn fx/color)
-(import-fn fx/material)
-(import-fn fx/fog)
-(import-fn fx/light)
+;;replaced old import-fn
+(import/import-vars
+ [penumbra.opengl.effects
+ render-mode
+ color
+ material
+ fog
+ light
+ ])
(defmacro with-render-mode [mode & body]
`(fx/with-render-mode ~mode (fn [] ~@body)))
@@ -295,10 +303,13 @@
(gl-import+ glTexParameteri tex-parameter)
(gl-import+ glIsTexture valid-texture-id?)
-(import-fn tex/bind-texture)
-(import-fn tex/texture)
-(import-fn tex/create-texture)
-(import-fn tex/build-mip-map)
+;;replaced old import-fn
+(import/import-vars
+ [penumbra.opengl.texture
+ bind-texture
+ texture
+ create-texture
+ build-mip-map])
(defmacro with-texture [tex & body]
`(tex/with-texture ~tex (fn [] ~@body)))
View
4 src/penumbra/opengl/capabilities.clj
@@ -13,8 +13,8 @@
[penumbra.opengl.frame-buffer :as fb]
[penumbra.data :as data])
(:use [penumbra.opengl.core :only (enum enum-name gl-import- get-integer)]
- [clojure.contrib.def :only (defn-memo)]
- [clojure.contrib.combinatorics :only (cartesian-product)])
+ [penumbra.def :only (defn-memo)]
+ [clojure.math.combinatorics :only (cartesian-product)])
(:import [java.nio IntBuffer]))
(defn- get-frame-buffer []
View
2 src/penumbra/opengl/core.clj
@@ -7,7 +7,7 @@
;; You must not remove this notice, or any other, from this software.
(ns penumbra.opengl.core
- (:use [clojure.contrib.def :only (defn-memo defmacro- defvar defvar-)])
+ (:use [penumbra.def :only (defn-memo defmacro- defvar defvar-)])
(:import (org.lwjgl.opengl GL11 GL12 GL13 GL14 GL15 GL20 GL30 GL31 GL32
ARBDrawBuffers
ARBFramebufferObject
View
4 src/penumbra/opengl/frame_buffer.clj
@@ -9,8 +9,8 @@
(ns penumbra.opengl.frame-buffer
(:use [penumbra.opengl core]
[penumbra.opengl.shader :only [uniform-location]]
- [clojure.contrib.def :only [defn-memo]]
- [clojure.contrib.seq :only [indexed]])
+ [penumbra.def :only [defn-memo]]
+ [penumbra.seq :only [indexed]])
(require [penumbra.opengl.texture :as tex])
(:import [org.lwjgl BufferUtils]))
View
2 src/penumbra/opengl/geometry.clj
@@ -8,7 +8,7 @@
(ns ^{:skip-wiki true}
penumbra.opengl.geometry
- (:use [clojure.contrib.def :only (defmacro- defvar)]
+ (:use [penumbra.def :only (defmacro- defvar)]
[cantor]
[penumbra.opengl.core])
(:require [penumbra.opengl.effects :as fx])
View
4 src/penumbra/opengl/shader.clj
@@ -7,8 +7,8 @@
; You must not remove this notice, or any other, from this software.
(ns penumbra.opengl.shader
- (:use [clojure.contrib.def :only (defmacro- defvar)])
- (:use [clojure.contrib.seq :only (indexed)])
+ (:use [penumbra.def :only (defmacro- defvar)])
+ (:use [penumbra.seq :only (indexed)])
(:use [penumbra.opengl.core])
(:use [penumbra.glsl.core])
(:use [penumbra.translate.core])
View
9 src/penumbra/opengl/slate.clj
@@ -7,10 +7,9 @@
; You must not remove this notice, or any other, from this software.
(ns penumbra.opengl.slate
- (:use [clojure.contrib.def :only [defmacro- defn-memo defvar-]]
- [clojure.contrib.pprint]
- [clojure.contrib.seq :only [separate]]
- [clojure.contrib.core :only [-?>]]
+ (:use [penumbra.def :only [defmacro- defn-memo defvar-]]
+ [clojure.pprint]
+ [penumbra.seq :only [separate]]
[penumbra.opengl core]
[penumbra.app core])
(:import [org.lwjgl.opengl Pbuffer PixelFormat]))
@@ -33,7 +32,7 @@
([]
(create nil))
([parent]
- (let [drawable (when-let [drawable-fn (-?> *app* :window :drawable)]
+ (let [drawable (when-let [drawable-fn (some-> *app* :window :drawable)]
(drawable-fn))
pixel-buffer (Pbuffer. 1 1 (-> (PixelFormat.)) drawable)]
(struct-map slate-struct
View
16 src/penumbra/opengl/texture.clj
@@ -7,8 +7,8 @@
; You must not remove this notice, or any other, from this software.
(ns penumbra.opengl.texture
- (:use [clojure.contrib.def :only (defmacro- defn-memo)])
- (:use [clojure.contrib.seq :only (separate)])
+ (:use [penumbra.def :only (defmacro- defn-memo)])
+ (:use [penumbra.seq :only (separate)])
(:use [penumbra.opengl core])
(:use [penumbra data])
(:import [org.lwjgl BufferUtils])
@@ -153,14 +153,24 @@
(byte-array (denormalize-bytes s)))))
(defn- array-to-buffer [a type]
- (println "type" type)
+ (println "type" type)
(cond
+ (isa? (class a) java.nio.Buffer) a ;;return the buffer
(= type :double) (-> (BufferUtils/createDoubleBuffer (count a)) (.put a) .rewind)
(= type :float) (-> (BufferUtils/createFloatBuffer (count a)) (.put a) .rewind)
(= type :int) (-> (BufferUtils/createIntBuffer (count a)) (.put a) .rewind)
(= type :unsigned-byte) (-> (BufferUtils/createByteBuffer (count a)) (.put a) .rewind)
:else (throw (Exception. (str "Don't recognize type " type)))))
+;; (defn- array-to-buffer [a type]
+;; (println "type" type)
+;; (cond
+;; (= type :double) (-> (BufferUtils/createDoubleBuffer (count a)) (.put a) .rewind)
+;; (= type :float) (-> (BufferUtils/createFloatBuffer (count a)) (.put a) .rewind)
+;; (= type :int) (-> (BufferUtils/createIntBuffer (count a)) (.put a) .rewind)
+;; (= type :unsigned-byte) (-> (BufferUtils/createByteBuffer (count a)) (.put a) .rewind)
+;; :else (throw (Exception. (str "Don't recognize type " type)))))
+
(defn- create-buffer [size type]
(cond
(= type :double) (BufferUtils/createDoubleBuffer size)
View
148 src/penumbra/seq.clj
@@ -0,0 +1,148 @@
+;;; seq_utils.clj -- Sequence utilities for Clojure
+
+;; by Stuart Sierra, http://stuartsierra.com/
+;; last updated March 2, 2009
+
+;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use
+;; and distribution terms for this software are covered by the Eclipse
+;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+;; which can be found in the file epl-v10.html at the root of this
+;; distribution. By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license. You must not
+;; remove this notice, or any other, from this software.
+
+
+;; Change Log
+;;
+;; January 10, 2009 (Stuart Sierra):
+;;
+;; * BREAKING CHANGE: "includes?" now takes collection as first
+;; argument. This is more consistent with Clojure collection
+;; functions; see discussion at http://groups.google.com/group/clojure/browse_thread/thread/8b2c8dc96b39ddd7/a8866d34b601ff43
+
+;;Pulled in to eliminate old dependency on contrib. a lot of this is no longer
+;;useful.
+(ns
+ #^{:author "Stuart Sierra (and others)",
+ :doc "Sequence utilities for Clojure"}
+ penumbra.seq
+ (:import (java.util.concurrent LinkedBlockingQueue TimeUnit)
+ (java.lang.ref WeakReference)))
+
+
+(defn separate
+ "Returns a vector:
+ [ (filter f s), (filter (complement f) s) ]"
+ [f s]
+ [(filter f s) (filter (complement f) s)])
+
+(defn indexed
+ "Returns a lazy sequence of [index, item] pairs, where items come
+ from 's' and indexes count up from zero.
+ (indexed '(a b c d)) => ([0 a] [1 b] [2 c] [3 d])"
+ [s]
+ (map vector (iterate inc 0) s))
+
+
+;; recursive sequence helpers by Christophe Grand
+;; see http://clj-me.blogspot.com/2009/01/recursive-seqs.html
+(defmacro rec-seq
+ "Similar to lazy-seq but binds the resulting seq to the supplied
+ binding-name, allowing for recursive expressions."
+ [binding-name & body]
+ `(let [s# (atom nil)]
+ (reset! s# (lazy-seq (let [~binding-name @s#] ~@body)))))
+
+(defmacro rec-cat
+ "Similar to lazy-cat but binds the resulting sequence to the supplied
+ binding-name, allowing for recursive expressions."
+ [binding-name & exprs]
+ `(rec-seq ~binding-name (lazy-cat ~@exprs)))
+
+
+(defn rotations
+ "Returns a lazy seq of all rotations of a seq"
+ [x]
+ (if (seq x)
+ (map
+ (fn [n _]
+ (lazy-cat (drop n x) (take n x)))
+ (iterate inc 0) x)
+ (list nil)))
+
+(defn rand-elt
+ "DEPRECATED. Prefer clojure.core/rand-nth.
+ Return a random element of this seq"
+ {:deprecated "1.2"}
+ [s]
+ (nth s (rand-int (count s))))
+
+;; seq-on written by Konrad Hinsen
+(defmulti seq-on
+ "Returns a seq on the object s. Works like the built-in seq but as
+ a multimethod that can have implementations for new classes and types."
+ {:arglists '([s])}
+ type)
+
+(defmethod seq-on :default
+ [s]
+ (seq s))
+
+
+(defn find-first
+ "Returns the first item of coll for which (pred item) returns logical true.
+ Consumes sequences up to the first match, will consume the entire sequence
+ and return nil if no match is found."
+ [pred coll]
+ (first (filter pred coll)))
+
+; based on work related to Rich Hickey's seque.
+; blame Chouser for anything broken or ugly.
+(defn fill-queue
+ "filler-func will be called in another thread with a single arg
+ 'fill'. filler-func may call fill repeatedly with one arg each
+ time which will be pushed onto a queue, blocking if needed until
+ this is possible. fill-queue will return a lazy seq of the values
+ filler-func has pushed onto the queue, blocking if needed until each
+ next element becomes available. filler-func's return value is ignored."
+ ([filler-func & optseq]
+ (let [opts (apply array-map optseq)
+ apoll (:alive-poll opts 1)
+ q (LinkedBlockingQueue. (:queue-size opts 1))
+ NIL (Object.) ;nil sentinel since LBQ doesn't support nils
+ weak-target (Object.)
+ alive? (WeakReference. weak-target)
+ fill (fn fill [x]
+ (if (.get alive?)
+ (if (.offer q (if (nil? x) NIL x) apoll TimeUnit/SECONDS)
+ x
+ (recur x))
+ (throw (Exception. "abandoned"))))
+ f (future
+ (try
+ (filler-func fill)
+ (finally
+ (.put q q))) ;q itself is eos sentinel
+ nil)] ; set future's value to nil
+ ((fn drain []
+ weak-target ; force closing over this object
+ (lazy-seq
+ (let [x (.take q)]
+ (if (identical? x q)
+ @f ;will be nil, touch just to propagate errors
+ (cons (if (identical? x NIL) nil x)
+ (drain))))))))))
+
+(defn positions
+ "Returns a lazy sequence containing the positions at which pred
+ is true for items in coll."
+ [pred coll]
+ (for [[idx elt] (indexed coll) :when (pred elt)] idx))
+
+(defn includes?
+ "Returns true if coll contains something equal (with =) to x,
+ in linear time. Deprecated. Prefer 'contains?' for key testing,
+ or 'some' for ad hoc linear searches."
+ {:deprecated "1.2"}
+ [coll x]
+(boolean (some (fn [y] (= y x)) coll)))
View
2 src/penumbra/text.clj
@@ -9,7 +9,7 @@
(ns penumbra.text
(:use [penumbra.opengl]
[penumbra.opengl.core :only [get-integer *view* *font-cache* *font*]]
- [clojure.contrib.def :only (defvar defn-memo)])
+ [penumbra.def :only (defvar defn-memo)])
(:import [java.awt Font]
[java.awt.font TextAttribute]
[org.newdawn.slick TrueTypeFont]
View
2 src/penumbra/time.clj
@@ -7,7 +7,7 @@
;; You must not remove this notice, or any other, from this software.
(ns penumbra.time
- (:use [clojure.contrib.def :only [defn-memo]]))
+ (:use [penumbra.def :only [defn-memo]]))
(defn wall-time []
(/ (double (System/nanoTime)) (double 1e9)))
View
10 src/penumbra/translate/c.clj
@@ -8,8 +8,8 @@
(ns penumbra.translate.c
(:use [penumbra.translate core]
- [clojure.contrib
- (def :only (defmacro-))]))
+ [penumbra.def
+ :only (defmacro-)]))
;;;;;;;;;;;;;;;;;;;
@@ -158,7 +158,8 @@
(not (seq? x))
(-> x first seq?)))
-(def *line-terminator* ";")
+;;updated to dynvar declaration.
+(def ^:dynamic *line-terminator* ";")
(defmethod parser nil
;handle base cases
@@ -200,7 +201,8 @@
`(defmethod parser ~op-symbol [x#]
(str ~op-string (parse (second x#)))))
-(def *assignment* false)
+;;updated to 1.7 dynvar decl
+(def ^:dynamic *assignment* false)
(defmacro- def-assignment-parser
"Defines an assignment operator, making use of parse-assignment for the l-value
View
4 src/penumbra/translate/core.clj
@@ -7,8 +7,8 @@
; You must not remove this notice, or any other, from this software.
(ns penumbra.translate.core
- (:use [clojure.contrib.pprint])
- (:use [clojure.contrib.def :only (defmacro- defvar defvar-)])
+ (:use [clojure.pprint])
+ (:use [penumbra.def :only (defmacro- defvar defvar-)])
(:use [clojure.walk])
(:import (java.text ParseException))
(:import (java.io StringWriter))
View
14 src/penumbra/translate/operators.clj
@@ -10,18 +10,20 @@
(:use [clojure.walk]
[penumbra.translate core]
[cantor :only (rectangle-factors)]
- [clojure.contrib.seq :only (indexed separate)]
- [clojure.contrib.def :only (defn-memo defvar-)]
+ [penumbra.seq :only (indexed separate)]
+ [penumbra.def :only (defn-memo defvar-)]
[penumbra.translate.core])
(:require [clojure.zip :as zip]
[penumbra.data :as data]))
;;
-(def *dim-element* nil)
-(def *typeof-dim* nil)
-(def *typeof-element* nil)
-(def *typeof-param* nil)
+;;tom
+;;patched these to use clojure's changed dynamic declarations.
+(def ^:dynamic *dim-element* nil)
+(def ^:dynamic *typeof-dim* nil)
+(def ^:dynamic *typeof-element* nil)
+(def ^:dynamic *typeof-param* nil)
;;utilities
View
3 test/example/app/async.clj
@@ -46,8 +46,9 @@
(rotate (:rot state) 0 1 0)
(call-display-list (:cube state)))
+;;fixed app/start* -> app/start
(defn start []
- (let [app (app/start* {:init init, :reshape reshape, :display display} {:rot 0})]
+ (let [app (app/start {:init init, :reshape reshape, :display display} {:rot 0})]
(Thread/sleep 5000)
(app/pause! app)
(Thread/sleep 1000)
View
5 test/example/app/nested.clj
@@ -25,7 +25,8 @@
(write-to-screen (str "nested " (:count state) " deep!") 0 0))
(def callbacks {:key-press key-press :display display})
-
+
+;;This works fine.
(defn start
([] (start {:count 1}))
- ([state] (app/start callbacks state)))
+ ([state] (app/start callbacks state)))
View
8 test/example/app/switch.clj
@@ -49,10 +49,10 @@
(write-to-screen "second app" 0 0))
;;
-
(def apps {:controller (app/create {:init controller-init} {})
- :first (app/create {:init first-init, :key-press first-key-press, :display first-display} {})
- :second (app/create {:init second-init, :key-press second-key-press :display second-display} {})})
+ :first (app/create {:init first-init, :key-press first-key-press, :display first-display} {})
+ :second (app/create {:init second-init, :key-press second-key-press :display second-display} {})})
+;;tom- can't get this one to work....app/start was called with one arg, needed a second. ask Zach.
(defn start []
- (app/start (:controller apps)))
+ (app/start (:controller apps) nil))
View
6 test/example/game/asteroids.clj
@@ -8,7 +8,7 @@
(ns example.game.asteroids
(:use [penumbra opengl]
- [clojure.contrib.seq :only (separate)]
+ [penumbra.seq :only (separate)] ;;modified to drop contrib.
[cantor])
(:require [penumbra.app :as app]
[penumbra.text :as text]
@@ -379,7 +379,9 @@
(draw-spaceship (:spaceship state)))
(app/repaint!)))
+;;tom
+;;Doesn't work for me, probably not supported shader stuff on my hardware.
(defn start []
(app/start
{:reshape reshape, :init init, :key-press key-press, :update update, :display display}
- {:dim *dim*}))
+ {:dim *dim*}))
View
3 test/example/game/pong.clj
@@ -125,7 +125,8 @@
(draw-paddle (- 0.99 paddle-width) (:right state))
(app/repaint!))
+;;pong works, yay.
(defn start []
(app/start
{:display display, :reshape reshape, :update update, :init init}
- {}))
+ {}))
View
6 test/example/game/tetris.clj
@@ -9,9 +9,9 @@
(ns example.game.tetris
(:use [penumbra opengl])
(:require [penumbra.app :as app])
- (:use [clojure.contrib.seq :only (indexed)])
- (:use [clojure.contrib.def :only (defn-memo)])
- (:use [clojure.contrib.pprint]))
+ (:use [penumbra.seq :only (indexed)])
+ (:use [penumbra.def :only (defn-memo)])
+ (:use [clojure.pprint]))
;;;
View
6 test/example/gpgpu/n_body.clj
@@ -7,8 +7,8 @@
;; You must not remove this notice, or any other, from this software.
(ns example.gpgpu.n-body
- (:use [penumbra compute]
- [clojure.contrib.seq :only (partition-all flatten)])
+ (:use [penumbra compute])
+; [clojure.contrib.seq :only (partition-all flatten)])
(:require [penumbra.app :as app]
[penumbra.data :as data]))
@@ -87,4 +87,4 @@
(let [num (* 100 (inc i))]
(println num)
(dotimes [_ 1]
- (run-sim num 1))))))
+ (run-sim num 1))))))
View
2 test/example/opengl/async.clj
@@ -53,5 +53,7 @@
(blit (first (:textures state)))
(app/repaint!))
+;;Ask Zach..
+;;currently just blits out and exits.
(defn start []
(app/start {:display display, :init init} {}))
View
3 test/example/opengl/marble.clj
@@ -94,6 +94,9 @@
;;(text/write-to-screen (str (int (/ 1 delta)) "fps") 0 0)
((:teapot state)))))
+
+;;tom
+;;doesn't work for me, exits out. May be due to hardware limitations. Test on another machine...
(defn start []
(app/start
{:reshape reshape, :display display, :init init, :mouse-drag mouse-drag, :key-press key-press}
View
2 test/example/opengl/render_to_texture.clj
@@ -114,6 +114,8 @@
(load-identity)
(draw-lines (vertex 0.5 0) (vertex 0.5 1)))))))
+;;tom
+;;This one quits immeidately, no rendering. Dunno if it's hardware limitation.
(defn start []
(app/start
{:display display, :mouse-drag mouse-drag, :reshape reshape, :init init}
View
2 test/example/opengl/shadow.clj
@@ -47,6 +47,8 @@
(clear)
(draw-scene)))))
+;;tom
+;;doesn't work for me. Probably hardware not supporting the shader pipeline.
(defn start []
(app/start {:init init, :reshape reshape, :mouse-drag mouse-drag, :display display}
{:rot-x 0, :rot-y 0}))
View
8 test/example/opengl/squares.clj
@@ -6,8 +6,8 @@
;; You must not remove this notice, or any other, from this software.
(ns example.opengl.squares
- (:use [penumbra opengl compute]
- [clojure.contrib.seq :only (flatten)])
+ (:use [penumbra opengl compute])
+; [clojure.contrib.seq :only (flatten)]) ;;already in clojure.core
(:require [penumbra.app :as app]
[penumbra.data :as data]))
@@ -38,5 +38,7 @@
(vertex -1 -1) (vertex 1 -1)
(vertex 1 1) (vertex -1 1)))))
+;;tom
+;;also doesn't work for me, probably due to not supporting shader model.
(defn start []
- (app/start {:init init, :reshape reshape, :display display} {}))
+ (app/start {:init init, :reshape reshape, :display display} {}))
View
10 test/example/wiki/clock3.clj
@@ -25,10 +25,12 @@
(defn incrementer [k]
(fn [state] (update-in state [k] inc)))
+;;tom
+;;fixed periodic-update -> periodic-update!
(defn init [state]
- (app/periodic-update 1 (incrementer :second))
- (app/periodic-update (/ 1 60) (incrementer :minute))
- (app/periodic-update (/ 1 3600) (incrementer :hour))
+ (app/periodic-update! 1 (incrementer :second))
+ (app/periodic-update! (/ 1 60) (incrementer :minute))
+ (app/periodic-update! (/ 1 3600) (incrementer :hour))
state)
(defn reshape [[x y w h] state]
@@ -43,4 +45,4 @@
(app/start
{:display display, :reshape reshape, :init init}
- {:hour 0 :minute 0 :second 0})
+ {:hour 0 :minute 0 :second 0})

0 comments on commit db43d01

Please sign in to comment.