Skip to content

Instantly share code, notes, and snippets.

@quephird
Created August 17, 2012 20:29
Show Gist options
  • Save quephird/3382354 to your computer and use it in GitHub Desktop.
Save quephird/3382354 to your computer and use it in GitHub Desktop.
stereo viewing
; This is a transliteration of the code listed here: http://wiki.processing.org/w/Stereo_viewing
; I stumbled on it in search of a means to get a handle to the GL context that
; exposes the lower level OpenGL methods.
(ns stereo-viewing
(:import [processing.core PConstants])
(:use [quil.core] [quil.applet])
)
(def rotation (atom 0))
(def gl (atom nil))
(defn setup []
; This is needed to stop the images being squashed
(perspective (/ PConstants/PI 3.0) 1 0.1 1000)
(no-stroke)
; current-applet returns the current PApplet object which contains
; the PGraphicsOpenGL object which itself contains the raw GL object,
; which is what I need to call the lower-level OpenGL goodies.
(reset! gl (-> (current-applet) .g .gl))
)
(defn draw-two-boxes []
(push-matrix)
(rotate-x @rotation)
(rotate-y (/ @rotation 2.3))
(box 30)
(translate 0 0 30)
(box 10)
(pop-matrix)
)
(defn draw []
(swap! rotation + 0.01)
(ambient-light 64 64 64)
(point-light 128 128 128 0 20 -50)
(background 0)
(fill 255)
; Left Eye
; Using Camera gives us much more control over the eye position
(camera -10 0 -100 0 0 0 0 -1 0)
; This means anything we draw will be limited to the left half of the screen
(.glViewport @gl 50 50 200 200)
(draw-two-boxes)
; Right Eye
(camera 10 0 -100 0 0 0 0 -1 0)
; This means anything we draw will be limited to the _right_ half of the screen
(.glViewport @gl 250 50 200 200)
(draw-two-boxes)
)
(defsketch main
:title "stereo viewing"
:setup setup
:draw draw
:size [500 300]
:renderer :opengl
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment