https://github.com/apirogov/sdl2-cairo
Haskell library providing functions to use Cairo to draw on SDL textures and containing a Processing-style convenience drawing API.
https://github.com/apirogov/sdl2-cairo
Last synced: 11 months ago
JSON representation
Haskell library providing functions to use Cairo to draw on SDL textures and containing a Processing-style convenience drawing API.
- Host: GitHub
- URL: https://github.com/apirogov/sdl2-cairo
- Owner: apirogov
- License: mit
- Created: 2015-09-26T10:28:23.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-08-13T15:30:50.000Z (almost 9 years ago)
- Last Synced: 2025-04-20T13:11:04.590Z (about 1 year ago)
- Language: Haskell
- Size: 35.2 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sdl2-cairo [](https://hackage.haskell.org/package/sdl2-cairo) [](https://travis-ci.org/apirogov/sdl2-cairo)
Haskell library providing functions to use Cairo to draw on SDL textures.
**NOTE:**
The Processing-style drawing API has been moved to a separate package
[cairo-canvas](https://github.com/apirogov/cairo-canvas).
##### Install
This library depends on the new
[SDL2 bindings](https://github.com/haskell-game/sdl2), available on Hackage as
[sdl2 version 2.1.0 or greater](http://hackage.haskell.org/package/sdl2)
and [cairo bindings](https://hackage.haskell.org/package/cairo).
Just clone and install this repository:
```bash
git clone git@github.com:apirogov/sdl2-cairo.git
cd sdl2-cairo
stack install
```
It should work with recent GHC versions (>= 7.8.4) without problems under Linux und OS X.
##### Documentation
You can use Cairo with the Render monad on an SDL texture like this:
```haskell
import SDL.Cairo
import Graphics.Rendering.Cairo
...
texture <- createCairoTexture renderer (V2 800 600)
withCairoTexture texture $ do
setSourceRGBA 1 0 0
lineTo 800 600
stroke
copy renderer texture Nothing Nothing
present renderer
```
If you are familiar with [Processing](https://processing.org/reference),
you can also use this together with the
[cairo-canvas](https://github.com/apirogov/cairo-canvas) package.
```haskell
import SDL.Cairo
import Graphics.Rendering.Cairo.Canvas
...
texture <- createCairoTexture renderer (V2 800 600)
withCairoTexture' texture $ runCanvas $ do
background $ gray 100
stroke $ red 255
fill $ blue 255 !@ 128
rect $ D 0 0 100 100
rect $ toD (V2 50 50) (V2 150 150)
copy renderer texture Nothing Nothing
present renderer
```
Finally, you can of course use this as glue to use [diagrams](http://projects.haskell.org/diagrams/)
with SDL with the [Cairo backend](https://hackage.haskell.org/package/diagrams-cairo):
```haskell
import SDL.Cairo
import Diagrams.Backend.Cairo
...
let (_,render) = renderDia Cairo (CairoOptions "" (mkSizeSpec $ V2 (Just 800) (Just 600))
RenderOnly False)
(myDiagram :: QDiagram Cairo V2 Double Any)
withCairoTexture texture render
...
```