diff --git a/Graphics/Rendering/OpenGL/Capture.hs b/Graphics/Rendering/OpenGL/Capture.hs
new file mode 100644
--- /dev/null
+++ b/Graphics/Rendering/OpenGL/Capture.hs
@@ -0,0 +1,57 @@
+{- |
+
+Module      :  Graphics.Rendering.OpenGL.Capture
+Copyright   :  (c) Claude Heiland-Allen 2012
+License     :  BSD3
+
+Maintainer  :  claude@mathr.co.uk
+Stability   :  provisional
+Portability :  portable
+
+Simple image capture from OpenGL.
+
+-}
+module Graphics.Rendering.OpenGL.Capture (capturePPM) where
+
+import Control.Monad (forM_)
+import Foreign (allocaBytes, plusPtr)
+
+import qualified Data.ByteString.Internal as BSI
+import qualified Data.ByteString as BS
+import Data.ByteString (ByteString)
+
+import Graphics.Rendering.OpenGL
+
+{- |  Capture the current viewport to a ByteString in PPM P6 format.
+      Correctly handles pixel alignment for oddly-sized regions.
+      Corrects the image orientation so that the origin is top left.
+-}
+--    This is too monolithic - patches welcome.
+capturePPM :: IO ByteString
+capturePPM = do
+  (p0, s0@(Size vw vh)) <- get viewport
+  let p6 = "P6\n" ++ show vw ++ " " ++ show vh ++ "\n255\n"
+  allocaBytes (fromIntegral (vw*vh*3)) $ \ptr -> do
+    preservingBufferBinding PixelPackBuffer $ do
+      -- pack buffer   needs OpenGL version >= 2.1
+      bindBuffer PixelPackBuffer $= Nothing
+      -- client attrib needs OpenGL version >= 1.1
+      preservingClientAttrib [PixelStoreAttributes] $ do
+        -- FIXME what else needs setting to avoid crashes or bad output?
+        rowAlignment Pack $= 1
+        readPixels p0 s0 $ PixelData RGB UnsignedByte ptr
+    px <- BSI.create (fromIntegral $ vw * vh * 3) $ \d ->
+      forM_ [0..vh-1] $ \y ->
+        BSI.memcpy
+          (d `plusPtr` fromIntegral (y*vw*3))
+          (ptr `plusPtr` fromIntegral ((vh-1-y)*vw*3))
+          (fromIntegral (vw*3))
+    return $ BS.pack (map (toEnum . fromEnum) p6) `BS.append` px
+
+--    This should check OpenGL version >= 2.1 - patches welcome.
+preservingBufferBinding :: BufferTarget -> IO a -> IO a
+preservingBufferBinding target action = do
+  buffer <- get $ bindBuffer target
+  result <- action
+  bindBuffer target $= buffer
+  return result
diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright (c) 2012, Claude Heiland-Allen
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+
+    * Neither the name of Claude Heiland-Allen nor the names of other
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/gl-capture.cabal b/gl-capture.cabal
new file mode 100644
--- /dev/null
+++ b/gl-capture.cabal
@@ -0,0 +1,26 @@
+name:                gl-capture
+version:             0.1.0.0
+synopsis:            simple image capture from OpenGL
+description:
+  Simplify image capture from OpenGL to ByteString in PPM P6 format.
+
+license:             BSD3
+license-file:        LICENSE
+author:              Claude Heiland-Allen
+maintainer:          claude@mathr.co.uk
+category:            Graphics
+build-type:          Simple
+cabal-version:       >=1.8
+
+library
+  exposed-modules:     Graphics.Rendering.OpenGL.Capture
+  build-depends:       base < 5, bytestring, OpenGL
+
+source-repository head
+  type:                git
+  location:            git://gitorious.org/maximus/gl-capture.git
+                       
+source-repository this
+  type:                git
+  location:            git://gitorious.org/maximus/gl-capture.git
+  tag:                 v0.1.0.0
