From 3914e9792b605a1a018fbffd70b1a140719a0cff Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Mon, 10 Feb 2014 17:35:28 +0400 Subject: [PATCH 1/3] fix example dependencies OpenGL < 2.9 (like library) & GLFW instead of GLFW-b because demo is written for GLFW and doesn't work with GLFW-b. --- graphics-drawingcombinators.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics-drawingcombinators.cabal b/graphics-drawingcombinators.cabal index 1156a7e..1b8cfe0 100644 --- a/graphics-drawingcombinators.cabal +++ b/graphics-drawingcombinators.cabal @@ -47,5 +47,5 @@ Executable example else Buildable: True Build-depends: base >= 3 && < 5, - GLFW-b, OpenGL >= 2.2 && < 2.7, graphics-drawingcombinators + GLFW, OpenGL >= 2.2 && < 2.9, graphics-drawingcombinators ghc-options: -Wall From a17c04a4e58e18f810f9ef9cae053fc2be4c3baa Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Tue, 11 Feb 2014 01:17:37 +0400 Subject: [PATCH 2/3] minimal README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b86df85 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +Combinators for drawing 2D shapes and images in Haskell (using OpenGL) + +* Summary: this module is a functional wrapper around OpenGL, so you don't have to go into the deep, dark world of imperative stateful programming just to draw stuff. It supports 2D only (for now), with support drawing geometry, images, and text. + +* [Online documentation](http://hackage.haskell.org/package/graphics-drawingcombinators-1.4.4.1/docs/Graphics-DrawingCombinators.html) + +* [Hackage entry](http://hackage.haskell.org/package/graphics-drawingcombinators) From defd423e85710c6d2ef20dd99c85d59516e515a2 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Tue, 11 Feb 2014 14:41:32 +0400 Subject: [PATCH 3/3] ported example to GLFW-b / glfw-3 --- demo/example_b.hs | 63 +++++++++++++++++++++++++++++++ graphics-drawingcombinators.cabal | 12 +++++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 demo/example_b.hs diff --git a/demo/example_b.hs b/demo/example_b.hs new file mode 100644 index 0000000..7769805 --- /dev/null +++ b/demo/example_b.hs @@ -0,0 +1,63 @@ +import Control.Monad +import Data.Monoid +import Graphics.DrawingCombinators ((%%)) +import qualified Graphics.DrawingCombinators as Draw +import qualified Graphics.UI.GLFW as GLFW +import Data.IORef +import Data.Maybe + +import System.Environment(getArgs) + +windowWidth, windowHeight :: Int +windowWidth = 800 +windowHeight = 600 + +initGL :: IO GLFW.Window +initGL = do + isInited <- GLFW.init + unless isInited $ error "Cannot init GLFW" + + maybeW <- GLFW.createWindow windowWidth windowHeight "DrawingCombinators demo" Nothing Nothing + let window = fromMaybe (error "No window was created") maybeW + GLFW.makeContextCurrent $ Just window + + return window + +unitText :: Draw.Font -> String -> Draw.Image Any +unitText font str = (Draw.translate (-1,0) %% Draw.scale (2/w) (2/w) %% Draw.text font str) + `mappend` + Draw.tint (Draw.Color 1 0 0 1) (Draw.line (-1,0) (1,0)) + where + w = Draw.textWidth font str + +quadrants :: (Monoid a) => Draw.Image a -> Draw.Image a +quadrants img = mconcat [ + (Draw.translate (-0.5,0.5) %%), + (Draw.translate (0.5,0.5) `Draw.compose` Draw.rotate (-pi/2) %%), + (Draw.translate (0.5,-0.5) `Draw.compose` Draw.rotate pi %%), + (Draw.translate (-0.5,-0.5) `Draw.compose` Draw.rotate (pi/2) %%)] (Draw.scale 0.5 0.5 %% img) + +circleText :: Draw.Font -> String -> Draw.Image Any +circleText font str = unitText font str `mappend` Draw.tint (Draw.Color 0 0 1 0.5) Draw.circle + +main :: IO () +main = do + args <- getArgs + font <- case args of + [fontName] -> Draw.openFont fontName + _ -> error "Usage: drawingcombinators-example some_font.ttf" + + window <- initGL + + done <- newIORef False + GLFW.setWindowCloseCallback window (Just $ const $ writeIORef done True) + mainLoop window font done 0.0 + + where + mainLoop window font done rotation = do + Draw.clearRender $ Draw.rotate rotation %% quadrants (circleText font "Hello, world!") + GLFW.swapBuffers window + GLFW.pollEvents + doneValue <- readIORef done + when (not doneValue) $ + mainLoop window font done (rotation - 0.01) diff --git a/graphics-drawingcombinators.cabal b/graphics-drawingcombinators.cabal index 1b8cfe0..e1d9893 100644 --- a/graphics-drawingcombinators.cabal +++ b/graphics-drawingcombinators.cabal @@ -13,7 +13,7 @@ Author: Luke Palmer Homepage: http://github.com/luqui/graphics-drawingcombinators Maintainer: lrpalmer@gmail.com Build-Type: Simple -Extra-Source-Files: demo/example.hs +Extra-Source-Files: demo/example.hs, demo/example-b.hs cabal-Version: >= 1.8 source-repository head @@ -49,3 +49,13 @@ Executable example Build-depends: base >= 3 && < 5, GLFW, OpenGL >= 2.2 && < 2.9, graphics-drawingcombinators ghc-options: -Wall + +Executable example_b + Main-is: demo/example_b.hs + if !flag(examples) + Buildable: False + else + Buildable: True + Build-depends: base >= 3 && < 5, + GLFW-b >= 1.4, OpenGL >= 2.2 && < 2.9, graphics-drawingcombinators + ghc-options: -Wall