https://wiki.haskell.org/api.php?action=feedcontributions&user=Jmcarthur&feedformat=atomHaskellWiki - User contributions [en]2021-05-14T17:56:59ZUser contributionsMediaWiki 1.27.4https://wiki.haskell.org/index.php?title=Newtype&diff=60788Newtype2016-05-22T15:57:02Z<p>Jmcarthur: /* Examples */</p>
<hr />
<div>A <hask>newtype</hask> declaration creates a new type in much the same way as <hask>data</hask>. The syntax and usage of newtypes is virtually identical to that of data declarations - in fact, you can replace the <hask>newtype</hask> keyword with <hask>data</hask> and it'll still compile, indeed there's even a good chance your program will still work. The converse is not true, however - <hask>data</hask> can only be replaced with <hask>newtype</hask> if the type has ''exactly one constructor'' with ''exactly one field'' inside it.<br />
<br />
Some examples:<br />
<br />
<haskell><br />
newtype Fd = Fd CInt<br />
-- data Fd = Fd CInt would also be valid<br />
<br />
-- newtypes can have deriving clauses just like normal types<br />
newtype Identity a = Identity a<br />
deriving (Eq, Ord, Read, Show)<br />
<br />
-- record syntax is still allowed, but only for one field<br />
newtype State s a = State { runState :: s -> (s, a) }<br />
<br />
-- this is *not* allowed:<br />
-- newtype Pair a b = Pair { pairFst :: a, pairSnd :: b }<br />
-- but this is:<br />
data Pair a b = Pair { pairFst :: a, pairSnd :: b }<br />
-- and so is this:<br />
newtype NPair a b = NPair (a, b)<br />
</haskell><br />
<br />
Sounds pretty limited! So why does anyone use <hask>newtype</hask>?<br />
<br />
== The short version ==<br />
<br />
The restriction to one constructor with one field means that the new type and the type of the field are in direct correspondence:<br />
<br />
<haskell><br />
State :: (s -> (s, a)) -> State s a<br />
runState :: State s a -> (s -> (s, a))<br />
</haskell><br />
<br />
or in mathematical terms they are ''isomorphic''. This means that after the type is checked at compile time, at run time the two types can be treated essentially the same, without the overhead or indirection normally associated with a data constructor. So if you want to declare different type class instances for a particular type, or want to make a type abstract, you can wrap it in a <hask>newtype</hask> and it'll be considered distinct to the type-checker, but identical at runtime. You can then use all sorts of deep trickery like phantom or recursive types without worrying about GHC shuffling buckets of bytes for no reason.<br />
<br />
== The messy bits ==<br />
<br />
Why doesn't everyone just use <hask>newtype</hask> whenever they can, then? Well, quite often they do. But there is a subtle yet semantically significant difference. When we create a data type supposedly isomorphic to <hask>Bool</hask> like so:<br />
<br />
<haskell>data Any = Any { getAny :: Bool }</haskell><br />
<br />
we actually find that the isomorphism isn't exact:<br />
<br />
<haskell><br />
Any . getAny $ Any True = Any True -- okay, fine<br />
Any . getAny $ Any False = Any False -- also fine<br />
Any . getAny $ Any ⊥ = Any ⊥ -- so far so good<br />
Any . getAny $ ⊥ = Any ⊥ -- wait a second...<br />
</haskell><br />
([[Bottom|what's that upside-down T thing?]])<br />
<br />
The problem is that types declared with the <hask>data</hask> keyword are ''lifted'' - that is, they contain their own ⊥ value that is distinct from all the others. In this example, we have <hask>⊥ :: Any</hask> distinct from <hask>Any ⊥ :: Any</hask>. What this means is that the following pattern match:<br />
<br />
<haskell><br />
case x of<br />
Any _ -> ()<br />
</haskell><br />
<br />
must evaluate its argument, even though it seems like the pattern match can't fail: we must check whether <hask>x</hask> is <hask>⊥</hask> or <hask>Any y</hask> for some <hask>y</hask>.<br />
<br />
This is intrinsic to Haskell's lazy, non-total semantics. The problem is that this means tracking whether a value is wrapped in a constructor or not, which means keeping track of those extra constructors at runtime even when all they do is distinguish an extra bottom value we don't even want. So in order to be consistent, but also allow the exact isomorphism to be preserved, Haskell provides the <hask>newtype</hask> keyword, for the construction of unlifted types. Pattern-matching on a newtype constructor doesn't do any work, because there is no separate ⊥ so every value in the type is wrapped in the constructor.<br />
<br />
== What about strict types? ==<br />
<br />
You may notice that a type like<br />
<br />
<haskell>data Identity' a = Identity' !a</haskell><br />
<br />
has <hask>Identity' ⊥ = ⊥</hask> and so you might think you have your coveted isomorphism. But all the strictness annotation means is that <hask>Identity' ⊥</hask> really means <hask>Identity' $! ⊥</hask> - the semantics of the type are fundamentally the same, and in particular the case expression still forces the value.<br />
<br />
== Examples ==<br />
<br />
<haskell><br />
module Foo where<br />
<br />
data Foo1 = Foo1 Int -- Defines Foo1 constructor that lazily refers to an Int<br />
data Foo2 = Foo2 !Int -- Defines Foo2 constructor that strictly refers to an Int<br />
newtype Foo3 = Foo3 Int -- Defines Foo3 constructor that has the same representation as Int<br />
<br />
-- Argument is lazy and ignored, so <br />
-- undefined does not cause failure since<br />
-- the contructor pattern match succeeds.<br />
x1 = case Foo1 undefined of<br />
Foo1 _ -> 1 -- 1<br />
<br />
-- Argument is strict (because of !), so<br />
-- undefined does cause failure.<br />
x2 = case Foo2 undefined of<br />
Foo2 _ -> 1 -- undefined<br />
<br />
-- The newtype behaves like Int, see yInt below<br />
x3 = case Foo3 undefined of<br />
Foo3 _ -> 1 -- 1<br />
<br />
-- Constructor pattern match fails<br />
y1 = case undefined of<br />
Foo1 _ -> 1 -- undefined<br />
<br />
-- Constructor pattern match fails<br />
y2 = case undefined of<br />
Foo2 _ -> 1 -- undefined<br />
<br />
-- The newtype behaves like Int, there is no<br />
-- constructor at runtime.<br />
y3 = case undefined of<br />
Foo3 _ -> 1 -- 1<br />
<br />
-- Demonstration of Int behavior<br />
int :: Int<br />
int = undefined<br />
<br />
yInt = case int of<br />
_ -> 1 -- 1<br />
</haskell><br />
<br />
Here are some tabulated examples which may be easier to read:<br />
<br />
{| class="wikitable"<br />
|-<br />
!<br />
! <haskell>newtype Foo = Foo ()</haskell><br />
! <haskell>data Foo = Foo ()</haskell><br />
! <haskell>data Foo = Foo !()</haskell><br />
|-<br />
| <haskell>case Foo undefined of Foo _ -> ()</haskell><br />
| <haskell>()</haskell><br />
| <haskell>()</haskell><br />
| <haskell>undefined</haskell><br />
|-<br />
| <haskell>case undefined of Foo _ -> ()</haskell><br />
| <haskell>()</haskell><br />
| <haskell>undefined</haskell><br />
| <haskell>undefined</haskell><br />
|-<br />
| <haskell> Foo undefined `seq` ()</haskell><br />
| <haskell>undefined</haskell><br />
| <haskell>()</haskell><br />
| <haskell>undefined</haskell><br />
|-<br />
| <haskell> (undefined :: Foo) `seq` ()</haskell><br />
| <haskell>undefined</haskell><br />
| <haskell>undefined</haskell><br />
| <haskell>undefined</haskell><br />
|}<br />
<br />
== See also ==<br />
<br />
The Haskell 98 Report defines newtypes in [http://www.haskell.org/onlinereport/decls.html#sect4.2.3 section 4.2.3].<br />
<br />
[[Category:FAQ]]<br />
[[Category:Language]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=56641Applications and libraries/Games2013-08-22T11:25:53Z<p>Jmcarthur: formatting</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
See also the [http://hackage.haskell.org/packages/archive/pkg-list.html#cat:game Game] category on Hackage.<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/boomslang boomslang]<br />
: A clone of the popular Flash game Boomshine.<br />
<br />
;[https://github.com/yairchu/defend/tree Defend The King from Forces of Different]: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.increpare.com/2008/11/endless-cavern/ Endless Cavern]: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hex, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
; [http://folk.uio.no/carljsv/gorillabas/GorillaBAS-0.1.tar.gz GorillaBAS]<br />
: A concrete game from an attempt on defining computer games.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://www.cs.ox.ac.uk/people/ian.lynagh/Hetris/ Hetris]<br />
:ASCII tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[http://quasimal.com/projects/level_0.html Level 0]<br />
:A fun and featureful Snake II clone using SDL.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071203 Hackage])<br />
<br />
;[http://mokehehe.blogspot.com/2009/04/super-nario-move-to-github.html Monao]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [https://github.com/mokehehe/monao Monao on github]<br />
<br />
;[http://joyridelabs.de/game/ Nikki and the Robots]<br />
:A puzzle, platformer game.<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://haskell-tetris.pbworks.com/w/page/16967421/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://www24.brinkster.com/srineet/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://hackage.haskell.org/package/SpaceInvaders Space Invaders]<br />
:A video game, based on [[Yampa]]<br />
<br />
;[http://hackage.haskell.org/package/stunts stunts]<br />
:A revival of the classic racing game Stunts to serve as a non-toy-sized example for LambdaCube.<br />
<br />
;[https://github.com/nbartlomiej/tfoo Tfoo]<br />
:A simple Five in a Row game. Online, with server-sent events, deployed to [http://tfoo.herokuapp.com/ Heroku], open source.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
;{{HackagePackage | id =Yogurt}}<br />
:A functional MUD client featuring prioritized, regex-based hooks, variables, timers, logging, dynamic loading of Yogurt scripts and more. For example programs, please see [http://code.google.com/p/yogurt-mud/ Yogurt's home page]. <br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
;[https://github.com/Mikolaj/Allure Allure of the Stars]<br />
:A near-future Sci-Fi roguelike and tactical squad game. Long-term goals are high replayability and auto-balancing through procedural content generation and persistent content modification based on player behaviour. The game is written using the [http://hackage.haskell.org/package/LambdaHack LambdaHack] roguelike game engine.<br />
<br />
;[http://ipwnstudios.com/node/4 Bloodknight]<br />
:An action RPG for mobile devices<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://hackage.haskell.org/package/free-game free-game]<br />
:A GUI/game library based on free monads.<br />
<br />
;[http://hackage.haskell.org/package/FunGEn FunGEn]<br />
:FunGEn (Functional Game Engine) is a platform-independent BSD-licensed 2D game engine based on OpenGL and GLUT. Its light dependencies make it easy to install, however GLUT is reputed to be unsuitable for simultaneous keypresses. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [http://darcsden.com/sordina/fungen/browse/examples/helloworld.hs simple] [http://darcsden.com/sordina/fungen/browse/examples/pong/pong.hs 2D] [http://darcsden.com/sordina/fungen/browse/examples/worms/worms.hs games], in Haskell. Example code: [http://joyful.com/fungen/old-site/example.html A Brief Example]. Forks and patches welcome!<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/GLFW-b GLFW-b]<br />
:Bindings to GLFW, a free, open source, multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time.<br />
<br />
;[http://gloss.ouroborus.net/ Gloss]<br />
:An OpenGL abstraction layer supporting game-style main loops.<br />
<br />
;[https://github.com/haskell-game haskell-game]<br />
:A project to make game development with Haskell easier to get started with by providing a suite of libraries for covering all sorts of aspects of game development.<br />
<br />
;[http://helm-engine.org/ Helm]<br />
:A functionally reactive game engine inspired by [http://elm-lang.org/ Elm].<br />
<br />
;[http://hackage.haskell.org/package/HGamer3D HGamer3D]<br />
:A game engine for Windows which includes Haskell bindings to a couple of C++ libraries and a Haskell API on top of that. Features include Audio, Joystick, Mouse and Keyboard handling, GUI, Network, Physics, 3D graphics. <br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://chipmunk-physics.net/ Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/hogre hogre]<br />
:Haskell bindings to the excellent OGRE 3D rendering engine. Ogre has been used in commercial games such as Torchlight and several books exist documenting the Ogre API. Ogre uses an MIT license making it compatible with many Haskell libraries.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://lambdacube3d.wordpress.com/ LambdaCube 3D]<br />
:LambdaCube 3D is a domain specific language and library that makes it possible to program GPUs in a purely functional style.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[https://github.com/adorablepuppy/CurryDog CurryDog]<br />
:Aims to be a 2d and 3d modular game engine.<br />
<br />
;[https://github.com/keera-studios/gtk-helpers gtk-helpers]<br />
:A collection of auxiliary operations related to Gtk2hs. See also [http://keera.co.uk/blog/2013/03/19/creating-board-games-in-haskell/ Creating board games in Haskell in 100 lines of code]<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
;[https://github.com/kosmikus/LambdaHack LambdaHack]<br />
:A game engine library for roguelike games of arbitrary theme, size and complexity, packaged together with a small example dungeon crawler. When completed, it will let you specify content to be procedurally generated, define the AI behaviour on top of the generic content-independent rules and compile a ready-to-play game binary, using either the supplied or a custom-made main loop. Several frontends are available (GTK is the default) and many other generic engine components are easily overridden, but the fundamental source of flexibility lies in the strict and type-safe separation of code and content.<br />
<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=56640Applications and libraries/Games2013-08-22T11:25:38Z<p>Jmcarthur: add haskell-game</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
See also the [http://hackage.haskell.org/packages/archive/pkg-list.html#cat:game Game] category on Hackage.<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/boomslang boomslang]<br />
: A clone of the popular Flash game Boomshine.<br />
<br />
;[https://github.com/yairchu/defend/tree Defend The King from Forces of Different]: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.increpare.com/2008/11/endless-cavern/ Endless Cavern]: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hex, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
; [http://folk.uio.no/carljsv/gorillabas/GorillaBAS-0.1.tar.gz GorillaBAS]<br />
: A concrete game from an attempt on defining computer games.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://www.cs.ox.ac.uk/people/ian.lynagh/Hetris/ Hetris]<br />
:ASCII tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[http://quasimal.com/projects/level_0.html Level 0]<br />
:A fun and featureful Snake II clone using SDL.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071203 Hackage])<br />
<br />
;[http://mokehehe.blogspot.com/2009/04/super-nario-move-to-github.html Monao]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [https://github.com/mokehehe/monao Monao on github]<br />
<br />
;[http://joyridelabs.de/game/ Nikki and the Robots]<br />
:A puzzle, platformer game.<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://haskell-tetris.pbworks.com/w/page/16967421/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://www24.brinkster.com/srineet/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://hackage.haskell.org/package/SpaceInvaders Space Invaders]<br />
:A video game, based on [[Yampa]]<br />
<br />
;[http://hackage.haskell.org/package/stunts stunts]<br />
:A revival of the classic racing game Stunts to serve as a non-toy-sized example for LambdaCube.<br />
<br />
;[https://github.com/nbartlomiej/tfoo Tfoo]<br />
:A simple Five in a Row game. Online, with server-sent events, deployed to [http://tfoo.herokuapp.com/ Heroku], open source.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
;{{HackagePackage | id =Yogurt}}<br />
:A functional MUD client featuring prioritized, regex-based hooks, variables, timers, logging, dynamic loading of Yogurt scripts and more. For example programs, please see [http://code.google.com/p/yogurt-mud/ Yogurt's home page]. <br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
;[https://github.com/Mikolaj/Allure Allure of the Stars]<br />
:A near-future Sci-Fi roguelike and tactical squad game. Long-term goals are high replayability and auto-balancing through procedural content generation and persistent content modification based on player behaviour. The game is written using the [http://hackage.haskell.org/package/LambdaHack LambdaHack] roguelike game engine.<br />
<br />
;[http://ipwnstudios.com/node/4 Bloodknight]<br />
:An action RPG for mobile devices<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://hackage.haskell.org/package/free-game free-game]<br />
:A GUI/game library based on free monads.<br />
<br />
;[http://hackage.haskell.org/package/FunGEn FunGEn]<br />
:FunGEn (Functional Game Engine) is a platform-independent BSD-licensed 2D game engine based on OpenGL and GLUT. Its light dependencies make it easy to install, however GLUT is reputed to be unsuitable for simultaneous keypresses. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [http://darcsden.com/sordina/fungen/browse/examples/helloworld.hs simple] [http://darcsden.com/sordina/fungen/browse/examples/pong/pong.hs 2D] [http://darcsden.com/sordina/fungen/browse/examples/worms/worms.hs games], in Haskell. Example code: [http://joyful.com/fungen/old-site/example.html A Brief Example]. Forks and patches welcome!<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/GLFW-b GLFW-b]<br />
:Bindings to GLFW, a free, open source, multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time.<br />
<br />
;[http://gloss.ouroborus.net/ Gloss]<br />
:An OpenGL abstraction layer supporting game-style main loops.<br />
<br />
<br />
;[https://github.com/haskell-game haskell-game]<br />
:A project to make game development with Haskell easier to get started with by providing a suite of libraries for covering all sorts of aspects of game development.<br />
<br />
;[http://helm-engine.org/ Helm]<br />
:A functionally reactive game engine inspired by [http://elm-lang.org/ Elm].<br />
<br />
;[http://hackage.haskell.org/package/HGamer3D HGamer3D]<br />
:A game engine for Windows which includes Haskell bindings to a couple of C++ libraries and a Haskell API on top of that. Features include Audio, Joystick, Mouse and Keyboard handling, GUI, Network, Physics, 3D graphics. <br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://chipmunk-physics.net/ Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/hogre hogre]<br />
:Haskell bindings to the excellent OGRE 3D rendering engine. Ogre has been used in commercial games such as Torchlight and several books exist documenting the Ogre API. Ogre uses an MIT license making it compatible with many Haskell libraries.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://lambdacube3d.wordpress.com/ LambdaCube 3D]<br />
:LambdaCube 3D is a domain specific language and library that makes it possible to program GPUs in a purely functional style.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[https://github.com/adorablepuppy/CurryDog CurryDog]<br />
:Aims to be a 2d and 3d modular game engine.<br />
<br />
;[https://github.com/keera-studios/gtk-helpers gtk-helpers]<br />
:A collection of auxiliary operations related to Gtk2hs. See also [http://keera.co.uk/blog/2013/03/19/creating-board-games-in-haskell/ Creating board games in Haskell in 100 lines of code]<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
;[https://github.com/kosmikus/LambdaHack LambdaHack]<br />
:A game engine library for roguelike games of arbitrary theme, size and complexity, packaged together with a small example dungeon crawler. When completed, it will let you specify content to be procedurally generated, define the AI behaviour on top of the generic content-independent rules and compile a ready-to-play game binary, using either the supplied or a custom-made main loop. Several frontends are available (GTK is the default) and many other generic engine components are easily overridden, but the fundamental source of flexibility lies in the strict and type-safe separation of code and content.<br />
<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=OpenGLTutorial2&diff=45005OpenGLTutorial22012-03-25T19:49:20Z<p>Jmcarthur: /* Animation */</p>
<hr />
<div>''This tutorial [http://blog.mikael.johanssons.org/archive/2006/09/opengl-programming-in-haskell-a-tutorial-part-2/] was originally written by Mikael Vejdemo Johansson, and was copied here with permission.''<br />
<br />
As we left off the [[OpenGLTutorial1|last installment]], we were just about capable to open up a window, and draw some basic things in it by giving coordinate lists to the command renderPrimitive. The programs we built suffered under a couple of very infringing and ugly restraints when we wrote them - for one, they weren't really very modularized. The code would have been much clearer had we farmed out important subtasks on other modules. For another, we never even considered the fact that some manipulations would not necessarily be good to do on the entire picture.<br />
<br />
==Some modules==<br />
To deal with the first problem, let's break apart our program a little bit, forming several more or less independent code files linked together to form a whole.<br />
<br />
First off, HelloWorld.hs - containing a very generic program skeleton. We will use our module Bindings to setup everything else we might need, and tie them to the callbacks.<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Bindings<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
createWindow "Hello World"<br />
displayCallback $= display<br />
reshapeCallback $= Just reshape<br />
keyboardMouseCallback $= Just keyboardMouse<br />
mainLoop<br />
</haskell><br />
Then Bindings.hs - our switchboard<br />
<haskell><br />
module Bindings (display,reshape,keyboardMouse) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Display<br />
reshape s@(Size w h) = do <br />
viewport $= (Position 0 0, s)<br />
keyboardMouse key state modifiers position = return ()<br />
</haskell><br />
<br />
We're going to be hacking around a LOT with the display function, so let's isolate that one to a module of its own: Display.hs<br />
<haskell><br />
module Display (display) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Cube<br />
display = do <br />
clear [ColorBuffer]<br />
cube (0.2::GLfloat)<br />
flush<br />
</haskell><br />
And a first utility module, containing the gritty details of drawing the cube <math>[-w,w]^3</math>, called Cube.hs<br />
<haskell><br />
module Cube where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
cube w = do <br />
renderPrimitive Quads $ do<br />
vertex $ Vertex3 w w w<br />
vertex $ Vertex3 w w (-w)<br />
vertex $ Vertex3 w (-w) (-w)<br />
vertex $ Vertex3 w (-w) w<br />
vertex $ Vertex3 w w w<br />
vertex $ Vertex3 w w (-w)<br />
vertex $ Vertex3 (-w) w (-w)<br />
vertex $ Vertex3 (-w) w w<br />
vertex $ Vertex3 w w w<br />
vertex $ Vertex3 w (-w) w<br />
vertex $ Vertex3 (-w) (-w) w<br />
vertex $ Vertex3 (-w) w w<br />
vertex $ Vertex3 (-w) w w<br />
vertex $ Vertex3 (-w) w (-w)<br />
vertex $ Vertex3 (-w) (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) w<br />
vertex $ Vertex3 w (-w) w<br />
vertex $ Vertex3 w (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) w<br />
vertex $ Vertex3 w w (-w)<br />
vertex $ Vertex3 w (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) (-w)<br />
vertex $ Vertex3 (-w) w (-w)<br />
</haskell><br />
Now, compiling this entire section with the command <hask>ghc –make -package GLUT HelloWorld.hs -o HelloWorld</hask> compiles and links each module needed, and produces, in the end, an executable to be used. There we go! Much more modularized, much smaller and simpler bits and pieces. And - an added boon - we won't normally need to recompile as much for each change we do.<br />
<br />
This skeletal program will look like:<br />
<br />
[[image:OG-Skeleton.png]]<br />
<br />
==Local transformations==<br />
One of the core reasons I started to write this tutorial series was that I wanted to figure out why [http://www.tfh-berlin.de/~panitz/hopengl/skript.html Panitz' tutorial] didn't work for me. The core explanation is simple - the names of some of the functions used has changed since he wrote them. Thus, the matrixExcursion in his tutorial is nowadays named preservingMatrix. This may well change further - though I hope it won't - in which case this tutorial will be painfully out of date as well.<br />
<br />
The idea of preservingMatrix, however, is to take a small piece of drawing actions, and perform them independent of the transformations going on outside that small piece. For demonstration, let's draw a bunch of cubes, shall we?<br />
<br />
We'll change the rather boring display subroutine in Display.hs into one using preservingMatrix to modify each cube drawn individually, giving a new Display.hs:<br />
<haskell><br />
module Display (display) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Cube<br />
points :: [(GLfloat,GLfloat,GLfloat)]<br />
points = map (\k -> (sin(2*pi*k/12),cos(2*pi*k/12),0.0)) [1..12]<br />
display = do <br />
clear [ColorBuffer]<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 x y z<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) points<br />
flush<br />
</haskell><br />
Say... Those points on the unit circle might be something we'll want more of. Let's abstract some again! We'll break them out to a Points.hs. We'll have to juggle a bit with the typesystem to get things to work out, and in the end we get<br />
<haskell><br />
module Points where<br />
import Graphics.Rendering.OpenGL<br />
points :: Int -> [(GLfloat,GLfloat,GLfloat)]<br />
points n' = let n = fromIntegral n' in map (\k -> let t = 2*pi*k/n in (sin(t),cos(t),0.0)) [1..n]<br />
</haskell><br />
and then we get the Display.hs<br />
<haskell><br />
module Display (display) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Cube<br />
import Points<br />
display = do <br />
clear [ColorBuffer]<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
flush<br />
</haskell><br />
where we note that we need to renormalize our colours to get them within the interval [0,1] from the interval [-1,1] in order to get valid colour values. The program looks like<br />
<br />
[[image:OG-7circle.png]]<br />
<br />
The point of this yoga doesn't come apparent until you start adding some global transformations as well. So let's! We add the line<br />
<br />
<haskell>scale 0.7 0.7 (0.7::GLfloat)</haskell><br />
<br />
just after the <hask>clear [ColorBuffer]</hask>, in order to scale the entire picture. As a result, we get<br />
<br />
[[image:OG-7circlescaled.png]]<br />
<br />
We can do this with all sorts of transformations - we can rotate the picture, skew it, move the entire picture around. Using preservingMatrix, we make sure that the transformations “outside” apply in the way we'd expect them to.<br />
<br />
==Back to the callbacks==<br />
===Animation===<br />
A lot of the OpenGL programming is centered around the program being prepared to launch some sequence when some event occurs. Let's use this to build a rotating version of our bunch of points up there. In order to do things over time, we're going to be using the global callbacks idleCallback and timerCallback. So, we'll modify the structure of our files a bit - starting from the top.<br />
<br />
We'll need a new callback. And we'll also need a state variable of our own, which in turn needs to be fed to all functions that may need to use it. Incorporating these changes, we get a new HelloWorld.hs:<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Bindings<br />
import Data.IORef<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
createWindow "Hello World"<br />
reshapeCallback $= Just reshape<br />
keyboardMouseCallback $= Just keyboardMouse<br />
angle <- newIORef 0.0<br />
displayCallback $= (display angle)<br />
idleCallback $= Just (idle angle)<br />
mainLoop<br />
</haskell><br />
Note the addition of an angle, and an idle. We need to feed the value of angle both to idle and to display, in order for them to use it accordingly. Now, we need to define idle somewhere - and since we keep all the bits and pieces we modify a LOT in display, let's put it in there.<br />
<br />
Exporting it all the way requires us to change the first line of Bindings.hs to<br />
<haskell>module Bindings (idle,display,reshape,keyboardMouse) where</haskell><br />
<br />
Display.hs:<br />
<haskell><br />
module Display (display,idle) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Cube<br />
import Points<br />
display angle = do <br />
clear [ColorBuffer]<br />
a <- get angle<br />
rotate a $ Vector3 0 0 (1::GLfloat)<br />
scale 0.7 0.7 (0.7::GLfloat)<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
flush<br />
idle angle = do<br />
a <- get angle<br />
angle $=! (a + 0.1) -- The parens are necessary due to a precedence bug in StateVar<br />
postRedisplay Nothing -- Only required on Mac OS X, which double-buffers internally<br />
</haskell><br />
<br />
Now, running this program makes a couple of different things painfully obvious. One is that things flicker. (Note: Mac OS X double-buffers internally so it does not flicker). Another is that our ring is shrinking violently. The shrinking is due to our forgetting to reset all our transformations before we apply the next, and the flicker is because we're redrawing an entire picture step by step. Much smoother animation'll be had if we use a double buffering technique. Now, this isn't at all hard. We need to modify a few places - tell HOpenGL that we want to do doublebuffering and also when we want to swap the ready drawn canvas for the one on the screen. So, we modify, again, HelloWorld.hs:<br />
<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Bindings<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
initialDisplayMode $= [DoubleBuffered]<br />
createWindow "Hello World"<br />
reshapeCallback $= Just reshape<br />
keyboardMouseCallback $= Just keyboardMouse<br />
angle <- newIORef 0.0<br />
idleCallback $= Just (idle angle)<br />
displayCallback $= (display angle)<br />
mainLoop<br />
</haskell><br />
and we also need to modify Display.hs to implement the bufferswapping. While we're at it, we add the command loadIdentity, which resets the modification matrix.<br />
<haskell><br />
module Display (display,idle) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Cube<br />
import Points<br />
display angle = do <br />
clear [ColorBuffer]<br />
loadIdentity<br />
a <- get angle<br />
rotate a $ Vector3 0 0 (1::GLfloat)<br />
scale 0.7 0.7 (0.7::GLfloat)<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
swapBuffers<br />
idle angle = do<br />
a <- get angle<br />
angle $=! a+0.1<br />
postRedisplay Nothing<br />
</haskell><br />
<br />
There we are! That looks pretty, doesn't it? Now, we could start adding control to the user, couldn't we? Let's add some keyboard interfaces. We'll start by letting the rotation direction change when we press spacebar, and let the arrows displace the whole figure and + and - increase/decrease the rotation speed.<br />
Again, we're adding states, so we need to modify HelloWorld.hs<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Bindings<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
initialDisplayMode $= [DoubleBuffered]<br />
createWindow "Hello World"<br />
reshapeCallback $= Just reshape<br />
angle <- newIORef (0.0::GLfloat)<br />
delta <- newIORef (0.1::GLfloat)<br />
position <- newIORef (0.0::GLfloat, 0.0)<br />
keyboardMouseCallback $= Just (keyboardMouse delta position)<br />
idleCallback $= Just (idle angle delta)<br />
displayCallback $= (display angle position)<br />
mainLoop<br />
</haskell><br />
<br />
Note that position is sent along to the keyboard as well as the display callbacks. And in Bindings.hs, we give the keyboard callback actual function<br />
<haskell><br />
module Bindings (idle,display,reshape,keyboardMouse) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Display<br />
reshape s@(Size w h) = do <br />
viewport $= (Position 0 0, s)<br />
keyboardAct a p (Char ' ') Down = do<br />
a' <- get a<br />
a $= -a'<br />
keyboardAct a p (Char '+') Down = do<br />
a' <- get a<br />
a $= 2*a'<br />
keyboardAct a p (Char '-') Down = do<br />
a' <- get a<br />
a $= a'/2<br />
keyboardAct a p (SpecialKey KeyLeft) Down = do<br />
(x,y) <- get p<br />
p $= (x-0.1,y)<br />
keyboardAct a p (SpecialKey KeyRight) Down = do<br />
(x,y) <- get p<br />
p $= (x+0.1,y)<br />
keyboardAct a p(SpecialKey KeyUp) Down = do<br />
(x,y) <- get p<br />
p $= (x,y+0.1)<br />
keyboardAct a p (SpecialKey KeyDown) Down = do<br />
(x,y) <- get p<br />
p $= (x,y-0.1)<br />
keyboardAct _ _ _ _ = return ()<br />
keyboardMouse angle pos key state modifiers position = do<br />
keyboardAct angle pos key state<br />
</haskell><br />
<br />
finally, in Display.hs we use the new information to accordingly redraw the scene, specifically the now changing amount to change the current angle with. Note that in order to avoid the placement of the circle to be pulled in with all the other modifications we're doing, we do the translation outside a preservingMatrix call.<br />
<br />
<haskell><br />
module Display (display,idle) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Cube<br />
import Points<br />
display angle position = do <br />
clear [ColorBuffer]<br />
loadIdentity<br />
(x,y) <- get position<br />
translate $ Vector3 x y 0<br />
preservingMatrix $ do <br />
a <- get angle<br />
rotate a $ Vector3 0 0 (1::GLfloat)<br />
scale 0.7 0.7 (0.7::GLfloat)<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
swapBuffers<br />
idle angle delta = do<br />
a <- get angle<br />
d <- get delta<br />
angle $=! a+d<br />
postRedisplay Nothing<br />
</haskell><br />
<br />
==Summary==<br />
We now know how to modify only parts of a picture, and we also know how to use the idle and the keyboardMouse callback to support animations and keyboard input.<br />
<br />
In order to somewhat limit the amount of typing I need to do, I'll give links that give details on some of the themes we've touched upon.<br />
<br />
First of all, the callbacks are described in more detail and with call signatures at<br />
[http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/GLUT-2.1.2.1/doc/html/Graphics-UI-GLUT-Callbacks-Global.html Graphics.UI.GLUT.Callbacks.Global] for the global callbacks (menu systems, and timing/idle callbacks)<br />
<br />
[http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/GLUT-2.1.2.1/doc/html/Graphics-UI-GLUT-Callbacks-Window.html Graphics.UI.GLUT.Callbacks.Window] for the window-specific callbacks (display, reshape, keyboard&mouse, visibility changes, window closing, mouse movement, spaceballs, drawing tablets, joysticks and dial&button)<br />
<br />
Furthermore, the various primitives for drawing are listed at [http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/OpenGL-2.2.3.0/doc/html/Graphics-Rendering-OpenGL-GL-BeginEnd.html Graphics.Rendering.OpenGL.GL.BeginEnd].<br />
<br />
There are 3-dimensional primitives ready as well. These can be found at [http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/GLUT-2.1.2.1/doc/html/Graphics-UI-GLUT-Objects.html Graphics.UI.GLUT.Objects]<br />
<br />
The flag I set to trigger double buffering is described among the GLUT initialization methods, see [http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/GLUT-2.1.2.1/doc/html/Graphics-UI-GLUT-Initialization.html Graphics.UI.GLUT.Initialization] for everything you can do there.<br />
<br />
[[Category:Graphics]]<br />
[[Category:How to]]<br />
[[Category:User interfaces]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=OpenGLTutorial2&diff=45004OpenGLTutorial22012-03-25T19:44:46Z<p>Jmcarthur: precedence bug fix</p>
<hr />
<div>''This tutorial [http://blog.mikael.johanssons.org/archive/2006/09/opengl-programming-in-haskell-a-tutorial-part-2/] was originally written by Mikael Vejdemo Johansson, and was copied here with permission.''<br />
<br />
As we left off the [[OpenGLTutorial1|last installment]], we were just about capable to open up a window, and draw some basic things in it by giving coordinate lists to the command renderPrimitive. The programs we built suffered under a couple of very infringing and ugly restraints when we wrote them - for one, they weren't really very modularized. The code would have been much clearer had we farmed out important subtasks on other modules. For another, we never even considered the fact that some manipulations would not necessarily be good to do on the entire picture.<br />
<br />
==Some modules==<br />
To deal with the first problem, let's break apart our program a little bit, forming several more or less independent code files linked together to form a whole.<br />
<br />
First off, HelloWorld.hs - containing a very generic program skeleton. We will use our module Bindings to setup everything else we might need, and tie them to the callbacks.<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Bindings<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
createWindow "Hello World"<br />
displayCallback $= display<br />
reshapeCallback $= Just reshape<br />
keyboardMouseCallback $= Just keyboardMouse<br />
mainLoop<br />
</haskell><br />
Then Bindings.hs - our switchboard<br />
<haskell><br />
module Bindings (display,reshape,keyboardMouse) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Display<br />
reshape s@(Size w h) = do <br />
viewport $= (Position 0 0, s)<br />
keyboardMouse key state modifiers position = return ()<br />
</haskell><br />
<br />
We're going to be hacking around a LOT with the display function, so let's isolate that one to a module of its own: Display.hs<br />
<haskell><br />
module Display (display) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Cube<br />
display = do <br />
clear [ColorBuffer]<br />
cube (0.2::GLfloat)<br />
flush<br />
</haskell><br />
And a first utility module, containing the gritty details of drawing the cube <math>[-w,w]^3</math>, called Cube.hs<br />
<haskell><br />
module Cube where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
cube w = do <br />
renderPrimitive Quads $ do<br />
vertex $ Vertex3 w w w<br />
vertex $ Vertex3 w w (-w)<br />
vertex $ Vertex3 w (-w) (-w)<br />
vertex $ Vertex3 w (-w) w<br />
vertex $ Vertex3 w w w<br />
vertex $ Vertex3 w w (-w)<br />
vertex $ Vertex3 (-w) w (-w)<br />
vertex $ Vertex3 (-w) w w<br />
vertex $ Vertex3 w w w<br />
vertex $ Vertex3 w (-w) w<br />
vertex $ Vertex3 (-w) (-w) w<br />
vertex $ Vertex3 (-w) w w<br />
vertex $ Vertex3 (-w) w w<br />
vertex $ Vertex3 (-w) w (-w)<br />
vertex $ Vertex3 (-w) (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) w<br />
vertex $ Vertex3 w (-w) w<br />
vertex $ Vertex3 w (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) w<br />
vertex $ Vertex3 w w (-w)<br />
vertex $ Vertex3 w (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) (-w)<br />
vertex $ Vertex3 (-w) w (-w)<br />
</haskell><br />
Now, compiling this entire section with the command <hask>ghc –make -package GLUT HelloWorld.hs -o HelloWorld</hask> compiles and links each module needed, and produces, in the end, an executable to be used. There we go! Much more modularized, much smaller and simpler bits and pieces. And - an added boon - we won't normally need to recompile as much for each change we do.<br />
<br />
This skeletal program will look like:<br />
<br />
[[image:OG-Skeleton.png]]<br />
<br />
==Local transformations==<br />
One of the core reasons I started to write this tutorial series was that I wanted to figure out why [http://www.tfh-berlin.de/~panitz/hopengl/skript.html Panitz' tutorial] didn't work for me. The core explanation is simple - the names of some of the functions used has changed since he wrote them. Thus, the matrixExcursion in his tutorial is nowadays named preservingMatrix. This may well change further - though I hope it won't - in which case this tutorial will be painfully out of date as well.<br />
<br />
The idea of preservingMatrix, however, is to take a small piece of drawing actions, and perform them independent of the transformations going on outside that small piece. For demonstration, let's draw a bunch of cubes, shall we?<br />
<br />
We'll change the rather boring display subroutine in Display.hs into one using preservingMatrix to modify each cube drawn individually, giving a new Display.hs:<br />
<haskell><br />
module Display (display) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Cube<br />
points :: [(GLfloat,GLfloat,GLfloat)]<br />
points = map (\k -> (sin(2*pi*k/12),cos(2*pi*k/12),0.0)) [1..12]<br />
display = do <br />
clear [ColorBuffer]<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 x y z<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) points<br />
flush<br />
</haskell><br />
Say... Those points on the unit circle might be something we'll want more of. Let's abstract some again! We'll break them out to a Points.hs. We'll have to juggle a bit with the typesystem to get things to work out, and in the end we get<br />
<haskell><br />
module Points where<br />
import Graphics.Rendering.OpenGL<br />
points :: Int -> [(GLfloat,GLfloat,GLfloat)]<br />
points n' = let n = fromIntegral n' in map (\k -> let t = 2*pi*k/n in (sin(t),cos(t),0.0)) [1..n]<br />
</haskell><br />
and then we get the Display.hs<br />
<haskell><br />
module Display (display) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Cube<br />
import Points<br />
display = do <br />
clear [ColorBuffer]<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
flush<br />
</haskell><br />
where we note that we need to renormalize our colours to get them within the interval [0,1] from the interval [-1,1] in order to get valid colour values. The program looks like<br />
<br />
[[image:OG-7circle.png]]<br />
<br />
The point of this yoga doesn't come apparent until you start adding some global transformations as well. So let's! We add the line<br />
<br />
<haskell>scale 0.7 0.7 (0.7::GLfloat)</haskell><br />
<br />
just after the <hask>clear [ColorBuffer]</hask>, in order to scale the entire picture. As a result, we get<br />
<br />
[[image:OG-7circlescaled.png]]<br />
<br />
We can do this with all sorts of transformations - we can rotate the picture, skew it, move the entire picture around. Using preservingMatrix, we make sure that the transformations “outside” apply in the way we'd expect them to.<br />
<br />
==Back to the callbacks==<br />
===Animation===<br />
A lot of the OpenGL programming is centered around the program being prepared to launch some sequence when some event occurs. Let's use this to build a rotating version of our bunch of points up there. In order to do things over time, we're going to be using the global callbacks idleCallback and timerCallback. So, we'll modify the structure of our files a bit - starting from the top.<br />
<br />
We'll need a new callback. And we'll also need a state variable of our own, which in turn needs to be fed to all functions that may need to use it. Incorporating these changes, we get a new HelloWorld.hs:<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Bindings<br />
import Data.IORef<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
createWindow "Hello World"<br />
reshapeCallback $= Just reshape<br />
keyboardMouseCallback $= Just keyboardMouse<br />
angle <- newIORef 0.0<br />
displayCallback $= (display angle)<br />
idleCallback $= Just (idle angle)<br />
mainLoop<br />
</haskell><br />
Note the addition of an angle, and an idle. We need to feed the value of angle both to idle and to display, in order for them to use it accordingly. Now, we need to define idle somewhere - and since we keep all the bits and pieces we modify a LOT in display, let's put it in there.<br />
<br />
Exporting it all the way requires us to change the first line of Bindings.hs to<br />
<haskell>module Bindings (idle,display,reshape,keyboardMouse) where</haskell><br />
<br />
Display.hs:<br />
<haskell><br />
module Display (display,idle) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Cube<br />
import Points<br />
display angle = do <br />
clear [ColorBuffer]<br />
a <- get angle<br />
rotate a $ Vector3 0 0 (1::GLfloat)<br />
scale 0.7 0.7 (0.7::GLfloat)<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
flush<br />
idle angle = do<br />
a <- get angle<br />
angle $=! (a + 0.1)<br />
postRedisplay Nothing -- Only required on Mac OS X, which double-buffers internally<br />
</haskell><br />
<br />
Now, running this program makes a couple of different things painfully obvious. One is that things flicker. (Note: Mac OS X double-buffers internally so it does not flicker). Another is that our ring is shrinking violently. The shrinking is due to our forgetting to reset all our transformations before we apply the next, and the flicker is because we're redrawing an entire picture step by step. Much smoother animation'll be had if we use a double buffering technique. Now, this isn't at all hard. We need to modify a few places - tell HOpenGL that we want to do doublebuffering and also when we want to swap the ready drawn canvas for the one on the screen. So, we modify, again, HelloWorld.hs:<br />
<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Bindings<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
initialDisplayMode $= [DoubleBuffered]<br />
createWindow "Hello World"<br />
reshapeCallback $= Just reshape<br />
keyboardMouseCallback $= Just keyboardMouse<br />
angle <- newIORef 0.0<br />
idleCallback $= Just (idle angle)<br />
displayCallback $= (display angle)<br />
mainLoop<br />
</haskell><br />
and we also need to modify Display.hs to implement the bufferswapping. While we're at it, we add the command loadIdentity, which resets the modification matrix.<br />
<haskell><br />
module Display (display,idle) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Cube<br />
import Points<br />
display angle = do <br />
clear [ColorBuffer]<br />
loadIdentity<br />
a <- get angle<br />
rotate a $ Vector3 0 0 (1::GLfloat)<br />
scale 0.7 0.7 (0.7::GLfloat)<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
swapBuffers<br />
idle angle = do<br />
a <- get angle<br />
angle $=! a+0.1<br />
postRedisplay Nothing<br />
</haskell><br />
<br />
There we are! That looks pretty, doesn't it? Now, we could start adding control to the user, couldn't we? Let's add some keyboard interfaces. We'll start by letting the rotation direction change when we press spacebar, and let the arrows displace the whole figure and + and - increase/decrease the rotation speed.<br />
Again, we're adding states, so we need to modify HelloWorld.hs<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Bindings<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
initialDisplayMode $= [DoubleBuffered]<br />
createWindow "Hello World"<br />
reshapeCallback $= Just reshape<br />
angle <- newIORef (0.0::GLfloat)<br />
delta <- newIORef (0.1::GLfloat)<br />
position <- newIORef (0.0::GLfloat, 0.0)<br />
keyboardMouseCallback $= Just (keyboardMouse delta position)<br />
idleCallback $= Just (idle angle delta)<br />
displayCallback $= (display angle position)<br />
mainLoop<br />
</haskell><br />
<br />
Note that position is sent along to the keyboard as well as the display callbacks. And in Bindings.hs, we give the keyboard callback actual function<br />
<haskell><br />
module Bindings (idle,display,reshape,keyboardMouse) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Display<br />
reshape s@(Size w h) = do <br />
viewport $= (Position 0 0, s)<br />
keyboardAct a p (Char ' ') Down = do<br />
a' <- get a<br />
a $= -a'<br />
keyboardAct a p (Char '+') Down = do<br />
a' <- get a<br />
a $= 2*a'<br />
keyboardAct a p (Char '-') Down = do<br />
a' <- get a<br />
a $= a'/2<br />
keyboardAct a p (SpecialKey KeyLeft) Down = do<br />
(x,y) <- get p<br />
p $= (x-0.1,y)<br />
keyboardAct a p (SpecialKey KeyRight) Down = do<br />
(x,y) <- get p<br />
p $= (x+0.1,y)<br />
keyboardAct a p(SpecialKey KeyUp) Down = do<br />
(x,y) <- get p<br />
p $= (x,y+0.1)<br />
keyboardAct a p (SpecialKey KeyDown) Down = do<br />
(x,y) <- get p<br />
p $= (x,y-0.1)<br />
keyboardAct _ _ _ _ = return ()<br />
keyboardMouse angle pos key state modifiers position = do<br />
keyboardAct angle pos key state<br />
</haskell><br />
<br />
finally, in Display.hs we use the new information to accordingly redraw the scene, specifically the now changing amount to change the current angle with. Note that in order to avoid the placement of the circle to be pulled in with all the other modifications we're doing, we do the translation outside a preservingMatrix call.<br />
<br />
<haskell><br />
module Display (display,idle) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Cube<br />
import Points<br />
display angle position = do <br />
clear [ColorBuffer]<br />
loadIdentity<br />
(x,y) <- get position<br />
translate $ Vector3 x y 0<br />
preservingMatrix $ do <br />
a <- get angle<br />
rotate a $ Vector3 0 0 (1::GLfloat)<br />
scale 0.7 0.7 (0.7::GLfloat)<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
swapBuffers<br />
idle angle delta = do<br />
a <- get angle<br />
d <- get delta<br />
angle $=! a+d<br />
postRedisplay Nothing<br />
</haskell><br />
<br />
==Summary==<br />
We now know how to modify only parts of a picture, and we also know how to use the idle and the keyboardMouse callback to support animations and keyboard input.<br />
<br />
In order to somewhat limit the amount of typing I need to do, I'll give links that give details on some of the themes we've touched upon.<br />
<br />
First of all, the callbacks are described in more detail and with call signatures at<br />
[http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/GLUT-2.1.2.1/doc/html/Graphics-UI-GLUT-Callbacks-Global.html Graphics.UI.GLUT.Callbacks.Global] for the global callbacks (menu systems, and timing/idle callbacks)<br />
<br />
[http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/GLUT-2.1.2.1/doc/html/Graphics-UI-GLUT-Callbacks-Window.html Graphics.UI.GLUT.Callbacks.Window] for the window-specific callbacks (display, reshape, keyboard&mouse, visibility changes, window closing, mouse movement, spaceballs, drawing tablets, joysticks and dial&button)<br />
<br />
Furthermore, the various primitives for drawing are listed at [http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/OpenGL-2.2.3.0/doc/html/Graphics-Rendering-OpenGL-GL-BeginEnd.html Graphics.Rendering.OpenGL.GL.BeginEnd].<br />
<br />
There are 3-dimensional primitives ready as well. These can be found at [http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/GLUT-2.1.2.1/doc/html/Graphics-UI-GLUT-Objects.html Graphics.UI.GLUT.Objects]<br />
<br />
The flag I set to trigger double buffering is described among the GLUT initialization methods, see [http://lambda.haskell.org/platform/doc/2011.4.0.0/packages/GLUT-2.1.2.1/doc/html/Graphics-UI-GLUT-Initialization.html Graphics.UI.GLUT.Initialization] for everything you can do there.<br />
<br />
[[Category:Graphics]]<br />
[[Category:How to]]<br />
[[Category:User interfaces]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Hac_%CF%86/Attendees&diff=41341Hac φ/Attendees2011-07-27T13:57:41Z<p>Jmcarthur: update when i'm arriving</p>
<hr />
<div>This is a partial list of attendees for [[Hac φ]]. Please refer to the [[Hac φ|main page]] for more information.<br />
<br />
= Attendees =<br />
<br />
Feel free to list yourself here -- though this is ''not'' registration. To register, see [[Hac φ/Register|this page]].<br />
<br />
{| class="wikitable"<br />
! Nickname<br />
! Real Name<br />
! Mobile #<br />
! Arriving<br />
! Departing<br />
! Accommodation<br />
|-<br />
| byorgey<br />
| Brent Yorgey<br />
| (202)-531-8646<br />
| -<br />
| -<br />
| lives in Philadelphia<br />
|-<br />
| dmwit<br />
| Daniel Wagner<br />
| (650)-353-1788<br />
| -<br />
| -<br />
| lives in Philadelphia<br />
|-<br />
| ccasin<br />
| Chris Casinghino<br />
| (603) 860-5301<br />
| -<br />
| -<br />
| lives in Philadelphia<br />
|-<br />
| ymasory<br />
| Yuvi Masory<br />
| ymasory@gmail.com<br />
| -<br />
| -<br />
| lives in Philadelphia, can host one guest for two nights (update: spots are taken).<br />
|-<br />
| yrlnry<br />
| [[Mark Dominus]]<br />
| mjd@plover.com<br />
| -<br />
| -<br />
| lives in Philadelphia<br />
|-<br />
| amindfv<br />
| Tom Murphy<br />
| amindfv@gmail.com<br />
| Thurs or Fri<br />
| Sunday<br />
| Found<br />
|-<br />
| fryguybob<br />
| Ryan Yates<br />
| fryguybob@gmail.com<br />
| Fri<br />
| Sunday<br />
| Unknown<br />
|-<br />
| copumpkin<br />
| Dan Peebles<br />
| (603) 738-1570<br />
| Unsure<br />
| Unsure<br />
| Unsure<br />
|-<br />
| brweber2<br />
| Bryan Weber<br />
| brweber2 yahoo<br />
| Fri<br />
| Sunday<br />
| done<br />
|- <br />
| lpsmith<br />
| Leon P Smith<br />
| leon.p.smith@gmail.com<br />
| Fri<br />
| Sun<br />
| done<br />
|-<br />
| jmcarthur<br />
| Jake McArthur<br />
| Jake.McArthur@gmail.com<br />
| Saturday<br />
| Sunday<br />
| unknown<br />
|-<br />
| acowley<br />
| Anthony Cowley<br />
| acowley@seas.upenn.edu<br />
| -<br />
| -<br />
| Jersey, New<br />
|- <br />
| thoughtpolice<br />
| Austin Seipp<br />
| as@hacks.yi.org<br />
| Fri<br />
| Sunday<br />
| unknown<br />
|-<br />
| dankna<br />
| Dan Knapp<br />
| dankna@gmail.com<br />
| Fri<br />
| Sun<br />
| With family<br />
|-<br />
| ludflu<br />
| Jim Snavely<br />
| ludflu@gmail.com<br />
| Sat<br />
| ?<br />
| Lives in philadelphia<br />
|-<br />
| swalck<br />
| Scott Walck<br />
| walck@lvc.edu<br />
| Fri<br />
| Sun<br />
| Club Quarters<br />
|-<br />
| djahandarie<br />
| Darius Jahandarie<br />
| djahandarie at gmail<br />
| ?<br />
| ?<br />
| ¯\(°_0)/¯<br />
|-<br />
| mightybyte<br />
| Doug Beardsley<br />
| <nickname> at gmail<br />
| <br />
| <br />
| unsure<br />
|-<br />
| synesthesia<br />
| Raeez Lorgat<br />
| (617)-470-5156<br />
| Fri<br />
| Sun<br />
| Uncertain<br />
|-<br />
| baguasquirrel<br />
| Arthur Chan<br />
| lambdasquirrel at google mail<br />
| Sat<br />
| Sun<br />
| will figure it out<br />
|}<br />
<br />
<br />
<br />
== Attendees in Berlin ==<br />
<br />
{| class="wikitable"<br />
! Nickname<br />
! Real Name<br />
! Mobile #<br />
! Arriving<br />
! Departing<br />
! Accommodation<br />
|-<br />
| <br />
| Matthias Fischmann<br />
| +49 179 7733223 / m.fischmann at gmail<br />
| Fri <br />
| Sun<br />
| <br />
|-<br />
|<br />
| Daniel van den Eijkel<br />
| dvde at gmx dot net<br />
| Fri<br />
| Sun<br />
|<br />
|-<br />
|<br />
| Sönke Hahn<br />
| shahn at cs.tu-berlin.de<br />
| Fri<br />
| Sun<br />
| lives in Berlin<br />
|<br />
|-<br />
|<br />
| Alexander Ulrich<br />
| alex at etc-network.de<br />
| Fri/Sat<br />
| Sun<br />
| <br />
|}<br />
<br />
= Additional Comments =<br />
<br />
Please use this section to leave comments for other attendees, e.g. for organizing accommodation.<br />
<br />
I'm an undergraduate student doing research this summer. I'm very interested in attending, but I doubt I could afford a hotel, so if anyone in Philly has a place I could stay please let me know. [[User:FmapE|FmapE]] 03:31, 16 June 2011 (UTC)</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Hac_%CF%86/Attendees&diff=40517Hac φ/Attendees2011-06-15T23:21:50Z<p>Jmcarthur: /* Attendees */</p>
<hr />
<div>This is a partial list of attendees for [[Hac φ]]. Please refer to the [[Hac φ|main page]] for more information.<br />
<br />
= Attendees =<br />
<br />
Feel free to list yourself here -- though this is ''not'' registration. To register, see [[Hac φ/Register|this page]].<br />
<br />
{| class="wikitable"<br />
! Nickname<br />
! Real Name<br />
! Mobile #<br />
! Arriving<br />
! Departing<br />
! Accommodation<br />
|-<br />
| byorgey<br />
| Brent Yorgey<br />
| (202)-531-8646<br />
| -<br />
| -<br />
| lives in Philadelphia<br />
|-<br />
| dmwit<br />
| Daniel Wagner<br />
| (650)-353-1788<br />
| -<br />
| -<br />
| lives in Philadelphia<br />
|-<br />
| ccasin<br />
| Chris Casinghino<br />
| (603) 860-5301<br />
| -<br />
| -<br />
| lives in Philadelphia<br />
|-<br />
| ymasory<br />
| Yuvi Masory<br />
| ymasory@gmail.com<br />
| -<br />
| -<br />
| lives in Philadelphia, can host one guest for two nights (update: spots are taken).<br />
|-<br />
| yrlnry<br />
| [[Mark Dominus]]<br />
| mjd@plover.com<br />
| -<br />
| -<br />
| lives in Philadelphia<br />
|-<br />
| amindfv<br />
| Tom Murphy<br />
| amindfv@gmail.com<br />
| Thurs or Fri<br />
| Sunday<br />
| working on it<br />
|-<br />
| fryguybob<br />
| Ryan Yates<br />
| fryguybob@gmail.com<br />
| Fri<br />
| Sunday<br />
| Unknown<br />
|-<br />
| copumpkin<br />
| Dan Peebles<br />
| (603) 738-1570<br />
| Unsure<br />
| Unsure<br />
| Unsure<br />
|-<br />
| brweber2<br />
| Bryan Weber<br />
| brweber2 yahoo<br />
| Fri<br />
| Sunday<br />
| done<br />
|- <br />
| lpsmith<br />
| Leon P Smith<br />
| leon.p.smith@gmail.com<br />
| Fri<br />
| Sun<br />
| done<br />
|-<br />
| jmcarthur<br />
| Jake McArthur<br />
| Jake.McArthur@gmail.com<br />
| Fri<br />
| Sunday<br />
| unknown<br />
|}<br />
<br />
= Additional Comments =<br />
<br />
Please use this section to leave comments for other attendees, e.g. for organizing accommodation.</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=38734Applications and libraries/Games2011-02-13T15:32:21Z<p>Jmcarthur: add Nikki and the Robots</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[https://github.com/yairchu/defend/tree Defend The King from Forces of Different]: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.maths.tcd.ie/~icecube/2008/11/endless-cavern/ Endless Cavern]: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hez, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/Hetris/ Hetris]<br />
:ASCII tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://www.cse.unsw.edu.au/~dons/code/contrib/hsChess hsChess]<br />
:Chess AI engine<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[https://github.com/kosmikus/LambdaHack LambdaHack]<br />
:A small roguelike game with a flexible engine. GTK and terminal front-ends.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071203 Hackage])<br />
<br />
;[http://d.hatena.ne.jp/authorNari/20080422/1208880928 Nario]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [http://fxp.hp.infoseek.co.jp/haskell/HSDL/arc/HSDL-0.2.0.zip]<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://haskell-tetris.pbwiki.com/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://www24.brinkster.com/srineet/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
;[http://ipwnstudios.com/node/4 Bloodknight]<br />
:An action RPG for mobile devices<br />
<br />
; [http://folk.uio.no/carljsv/game/game-1.0.tar.gz game-1.0.tar.gz]<br />
: An attempt on a "five-in-a-row"-program<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
;[http://joyridelabs.de/game/ Nikki and the Robots]<br />
:A puzzle, platformer game<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;FunGEn<br />
:FunGEn (Functional Game Engine) is a platform-independent 2D OpenGL-based BSD-licensed game engine. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [http://darcsden.com/simon/fungen/browse/examples/helloworld.hs simple] [http://darcsden.com/simon/fungen/browse/examples/pong/pong.hs 2D] [http://darcsden.com/simon/fungen/browse/examples/worms/worms.hs games], in Haskell.<br />
<br />
* [http://www.cin.ufpe.br/~haskell/fungen FunGEn] Andre Furtado's original 2002 release and project page with docs<br />
* [http://hackage.haskell.org/package/FunGEn FunGEn on hackage] Miloslav Raus's 2008 cabalised version, no repo<br />
* [http://darcsden.com/simon/fungen fungen] Simon Michael's 2008/2011 branch, cabalised and updated for GHC 6.12; forks and patches welcome<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://wiki.slembcke.net/main/published/Chipmunk Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://hackage.haskell.org/package/lambdacube-engine LambdaCube]<br />
:LambdaCube is a 3D rendering engine entirely written in Haskell. The main goal of this project is to provide a modern and feature rich graphical backend for various Haskell projects, and in the long run it is intended to be a practical solution even for serious purposes.<br />
<br />
;[https://github.com/simonmichael/graphics-drawingcombinators-example graphics-drawingcombinators-example]<br />
:An example of using [http://hackage.haskell.org/package/graphics-drawingcombinators graphics-drawingcombinators] on Mac OSX, to ease getting started on that platform.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=38733Applications and libraries/Games2011-02-13T15:31:03Z<p>Jmcarthur: add Bloodknight</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[https://github.com/yairchu/defend/tree Defend The King from Forces of Different]: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.maths.tcd.ie/~icecube/2008/11/endless-cavern/ Endless Cavern]: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hez, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/Hetris/ Hetris]<br />
:ASCII tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://www.cse.unsw.edu.au/~dons/code/contrib/hsChess hsChess]<br />
:Chess AI engine<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[https://github.com/kosmikus/LambdaHack LambdaHack]<br />
:A small roguelike game with a flexible engine. GTK and terminal front-ends.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071203 Hackage])<br />
<br />
;[http://d.hatena.ne.jp/authorNari/20080422/1208880928 Nario]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [http://fxp.hp.infoseek.co.jp/haskell/HSDL/arc/HSDL-0.2.0.zip]<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://haskell-tetris.pbwiki.com/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://www24.brinkster.com/srineet/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
;[http://ipwnstudios.com/node/4 Bloodknight]<br />
:An action RPG for mobile devices<br />
<br />
; [http://folk.uio.no/carljsv/game/game-1.0.tar.gz game-1.0.tar.gz]<br />
: An attempt on a "five-in-a-row"-program<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;FunGEn<br />
:FunGEn (Functional Game Engine) is a platform-independent 2D OpenGL-based BSD-licensed game engine. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [http://darcsden.com/simon/fungen/browse/examples/helloworld.hs simple] [http://darcsden.com/simon/fungen/browse/examples/pong/pong.hs 2D] [http://darcsden.com/simon/fungen/browse/examples/worms/worms.hs games], in Haskell.<br />
<br />
* [http://www.cin.ufpe.br/~haskell/fungen FunGEn] Andre Furtado's original 2002 release and project page with docs<br />
* [http://hackage.haskell.org/package/FunGEn FunGEn on hackage] Miloslav Raus's 2008 cabalised version, no repo<br />
* [http://darcsden.com/simon/fungen fungen] Simon Michael's 2008/2011 branch, cabalised and updated for GHC 6.12; forks and patches welcome<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://wiki.slembcke.net/main/published/Chipmunk Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://hackage.haskell.org/package/lambdacube-engine LambdaCube]<br />
:LambdaCube is a 3D rendering engine entirely written in Haskell. The main goal of this project is to provide a modern and feature rich graphical backend for various Haskell projects, and in the long run it is intended to be a practical solution even for serious purposes.<br />
<br />
;[https://github.com/simonmichael/graphics-drawingcombinators-example graphics-drawingcombinators-example]<br />
:An example of using [http://hackage.haskell.org/package/graphics-drawingcombinators graphics-drawingcombinators] on Mac OSX, to ease getting started on that platform.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=38732Applications and libraries/Games2011-02-13T15:29:38Z<p>Jmcarthur: unfinished games in alphabetical order</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[https://github.com/yairchu/defend/tree Defend The King from Forces of Different]: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.maths.tcd.ie/~icecube/2008/11/endless-cavern/ Endless Cavern]: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hez, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/Hetris/ Hetris]<br />
:ASCII tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://www.cse.unsw.edu.au/~dons/code/contrib/hsChess hsChess]<br />
:Chess AI engine<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[https://github.com/kosmikus/LambdaHack LambdaHack]<br />
:A small roguelike game with a flexible engine. GTK and terminal front-ends.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071203 Hackage])<br />
<br />
;[http://d.hatena.ne.jp/authorNari/20080422/1208880928 Nario]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [http://fxp.hp.infoseek.co.jp/haskell/HSDL/arc/HSDL-0.2.0.zip]<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://haskell-tetris.pbwiki.com/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://www24.brinkster.com/srineet/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
; [http://folk.uio.no/carljsv/game/game-1.0.tar.gz game-1.0.tar.gz]<br />
: An attempt on a "five-in-a-row"-program<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;FunGEn<br />
:FunGEn (Functional Game Engine) is a platform-independent 2D OpenGL-based BSD-licensed game engine. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [http://darcsden.com/simon/fungen/browse/examples/helloworld.hs simple] [http://darcsden.com/simon/fungen/browse/examples/pong/pong.hs 2D] [http://darcsden.com/simon/fungen/browse/examples/worms/worms.hs games], in Haskell.<br />
<br />
* [http://www.cin.ufpe.br/~haskell/fungen FunGEn] Andre Furtado's original 2002 release and project page with docs<br />
* [http://hackage.haskell.org/package/FunGEn FunGEn on hackage] Miloslav Raus's 2008 cabalised version, no repo<br />
* [http://darcsden.com/simon/fungen fungen] Simon Michael's 2008/2011 branch, cabalised and updated for GHC 6.12; forks and patches welcome<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://wiki.slembcke.net/main/published/Chipmunk Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://hackage.haskell.org/package/lambdacube-engine LambdaCube]<br />
:LambdaCube is a 3D rendering engine entirely written in Haskell. The main goal of this project is to provide a modern and feature rich graphical backend for various Haskell projects, and in the long run it is intended to be a practical solution even for serious purposes.<br />
<br />
;[https://github.com/simonmichael/graphics-drawingcombinators-example graphics-drawingcombinators-example]<br />
:An example of using [http://hackage.haskell.org/package/graphics-drawingcombinators graphics-drawingcombinators] on Mac OSX, to ease getting started on that platform.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=38728Applications and libraries/Games2011-02-13T02:42:30Z<p>Jmcarthur: added Hedgewars because it's server is written in Haskell</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[https://github.com/yairchu/defend/tree Defend The King from Forces of Different]: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.maths.tcd.ie/~icecube/2008/11/endless-cavern/ Endless Cavern]: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hez, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/Hetris/ Hetris]<br />
:ASCII tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://www.cse.unsw.edu.au/~dons/code/contrib/hsChess hsChess]<br />
:Chess AI engine<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[https://github.com/kosmikus/LambdaHack LambdaHack]<br />
:A small roguelike game with a flexible engine. GTK and terminal front-ends.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071203 Hackage])<br />
<br />
;[http://d.hatena.ne.jp/authorNari/20080422/1208880928 Nario]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [http://fxp.hp.infoseek.co.jp/haskell/HSDL/arc/HSDL-0.2.0.zip]<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://haskell-tetris.pbwiki.com/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://www24.brinkster.com/srineet/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
; [http://folk.uio.no/carljsv/game/game-1.0.tar.gz game-1.0.tar.gz]<br />
: An attempt on a "five-in-a-row"-program<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;FunGEn<br />
:FunGEn (Functional Game Engine) is a platform-independent 2D OpenGL-based BSD-licensed game engine. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [http://darcsden.com/simon/fungen/browse/examples/helloworld.hs simple] [http://darcsden.com/simon/fungen/browse/examples/pong/pong.hs 2D] [http://darcsden.com/simon/fungen/browse/examples/worms/worms.hs games], in Haskell.<br />
<br />
* [http://www.cin.ufpe.br/~haskell/fungen FunGEn] Andre Furtado's original 2002 release and project page with docs<br />
* [http://hackage.haskell.org/package/FunGEn FunGEn on hackage] Miloslav Raus's 2008 cabalised version, no repo<br />
* [http://darcsden.com/simon/fungen fungen] Simon Michael's 2008/2011 branch, cabalised and updated for GHC 6.12; forks and patches welcome<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://wiki.slembcke.net/main/published/Chipmunk Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://hackage.haskell.org/package/lambdacube-engine LambdaCube]<br />
:LambdaCube is a 3D rendering engine entirely written in Haskell. The main goal of this project is to provide a modern and feature rich graphical backend for various Haskell projects, and in the long run it is intended to be a practical solution even for serious purposes.<br />
<br />
;[https://github.com/simonmichael/graphics-drawingcombinators-example graphics-drawingcombinators-example]<br />
:An example of using [http://hackage.haskell.org/package/graphics-drawingcombinators graphics-drawingcombinators] on Mac OSX, to ease getting started on that platform.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=38668Applications and libraries/Games2011-02-10T22:35:55Z<p>Jmcarthur: move HsLife to the unfinished section</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
== Games ==<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
; [http://www.maths.tcd.ie/~icecube/2008/11/endless-cavern/ Endless Cavern]: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hez, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/Hetris/ Hetris]<br />
:ASCII tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://www.cse.unsw.edu.au/~dons/code/contrib/hsChess hsChess]<br />
:Chess AI engine<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[https://github.com/kosmikus/LambdaHack LambdaHack]<br />
:A small roguelike game with a flexible engine. GTK and terminal front-ends.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071203 Hackage])<br />
<br />
;[http://d.hatena.ne.jp/authorNari/20080422/1208880928 Nario]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [http://fxp.hp.infoseek.co.jp/haskell/HSDL/arc/HSDL-0.2.0.zip]<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://haskell-tetris.pbwiki.com/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://www24.brinkster.com/srineet/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
; [http://folk.uio.no/carljsv/game/game-1.0.tar.gz game-1.0.tar.gz]<br />
: An attempt on a "five-in-a-row"-program<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://wiki.slembcke.net/main/published/Chipmunk Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;FunGEn<br />
:FunGEn (Functional Game Engine) is a platform-independent 2d OpenGL-based BSD-licensed game engine. As of 2010 it's still the only pure haskell general-purpose game engine. The engine and examples work, but need updating for current GHC and OpenGL.<br />
* [http://www.cin.ufpe.br/~haskell/fungen FunGEn] Andre Furtado's original 0.1 release in 2002, with docs and examples<br />
* [http://hackage.haskell.org/package/FunGEn FunGEn on hackage] Cabalised/updated version from 2008, confusingly also 0.1, no docs/examples or repo<br />
* [http://joyful.com/darcsweb/darcsweb.cgi?r=fungen fungen darcs repo] A separate branch from 2008, with darcs repo<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=38666Applications and libraries/Games2011-02-10T22:34:40Z<p>Jmcarthur: remove broken repo link for hinvaders and make the main link the hackage page rather than a tarball</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
== Games ==<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
; [http://www.maths.tcd.ie/~icecube/2008/11/endless-cavern/ Endless Cavern]: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hez, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/Hetris/ Hetris]<br />
:ASCII tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://www.cse.unsw.edu.au/~dons/code/contrib/hsChess hsChess]<br />
:Chess AI engine<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife (not complete). It uses GLUT.<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[https://github.com/kosmikus/LambdaHack LambdaHack]<br />
:A small roguelike game with a flexible engine. GTK and terminal front-ends.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071203 Hackage])<br />
<br />
;[http://d.hatena.ne.jp/authorNari/20080422/1208880928 Nario]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [http://fxp.hp.infoseek.co.jp/haskell/HSDL/arc/HSDL-0.2.0.zip]<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://haskell-tetris.pbwiki.com/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://www24.brinkster.com/srineet/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
; [http://folk.uio.no/carljsv/game/game-1.0.tar.gz game-1.0.tar.gz]<br />
: An attempt on a "five-in-a-row"-program<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://wiki.slembcke.net/main/published/Chipmunk Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;FunGEn<br />
:FunGEn (Functional Game Engine) is a platform-independent 2d OpenGL-based BSD-licensed game engine. As of 2010 it's still the only pure haskell general-purpose game engine. The engine and examples work, but need updating for current GHC and OpenGL.<br />
* [http://www.cin.ufpe.br/~haskell/fungen FunGEn] Andre Furtado's original 0.1 release in 2002, with docs and examples<br />
* [http://hackage.haskell.org/package/FunGEn FunGEn on hackage] Cabalised/updated version from 2008, confusingly also 0.1, no docs/examples or repo<br />
* [http://joyful.com/darcsweb/darcsweb.cgi?r=fungen fungen darcs repo] A separate branch from 2008, with darcs repo<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:network game framework<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=38664Applications and libraries/Games2011-02-10T22:31:39Z<p>Jmcarthur: remove David Roundy's defunct bridge game (it's now being rewritten in Go anyway, apparently)</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
== Games ==<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
; [http://www.maths.tcd.ie/~icecube/2008/11/endless-cavern/ Endless Cavern]: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hez, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/Hetris/ Hetris]<br />
:ASCII tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://www.cs.mu.oz.au/~bjpop/code/HInvaders.tar.gz hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98. See also [http://hackage.haskell.org/packages/archive/pkg-list.html#cat:Game hackage] and [http://joyful.com/darcsweb/darcsweb.cgi?r=hinvaders;a=summary darcs].<br />
<br />
;[http://www.cse.unsw.edu.au/~dons/code/contrib/hsChess hsChess]<br />
:Chess AI engine<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife (not complete). It uses GLUT.<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[https://github.com/kosmikus/LambdaHack LambdaHack]<br />
:A small roguelike game with a flexible engine. GTK and terminal front-ends.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071203 Hackage])<br />
<br />
;[http://d.hatena.ne.jp/authorNari/20080422/1208880928 Nario]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [http://fxp.hp.infoseek.co.jp/haskell/HSDL/arc/HSDL-0.2.0.zip]<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://haskell-tetris.pbwiki.com/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://www24.brinkster.com/srineet/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
; [http://folk.uio.no/carljsv/game/game-1.0.tar.gz game-1.0.tar.gz]<br />
: An attempt on a "five-in-a-row"-program<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://wiki.slembcke.net/main/published/Chipmunk Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;FunGEn<br />
:FunGEn (Functional Game Engine) is a platform-independent 2d OpenGL-based BSD-licensed game engine. As of 2010 it's still the only pure haskell general-purpose game engine. The engine and examples work, but need updating for current GHC and OpenGL.<br />
* [http://www.cin.ufpe.br/~haskell/fungen FunGEn] Andre Furtado's original 0.1 release in 2002, with docs and examples<br />
* [http://hackage.haskell.org/package/FunGEn FunGEn on hackage] Cabalised/updated version from 2008, confusingly also 0.1, no docs/examples or repo<br />
* [http://joyful.com/darcsweb/darcsweb.cgi?r=fungen fungen darcs repo] A separate branch from 2008, with darcs repo<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Jmcarthurhttps://wiki.haskell.org/index.php?title=OpenGLTutorial2&diff=38533OpenGLTutorial22011-02-08T04:02:03Z<p>Jmcarthur: update code to fix a stack overflow that seems to occur on some systems</p>
<hr />
<div>''This tutorial [http://blog.mikael.johanssons.org/archive/2006/09/opengl-programming-in-haskell-a-tutorial-part-2/] was originally written by Mikael Vejdemo Johansson, and was copied here with permission.''<br />
<br />
As we left off the [[OpenGLTutorial1|last installment]], we were just about capable to open up a window, and draw some basic things in it by giving coordinate lists to the command renderPrimitive. The programs we built suffered under a couple of very infringing and ugly restraints when we wrote them - for one, they weren't really very modularized. The code would have been much clearer had we farmed out important subtasks on other modules. For another, we never even considered the fact that some manipulations would not necessarily be good to do on the entire picture.<br />
<br />
==Some modules==<br />
To deal with the first problem, let's break apart our program a little bit, forming several more or less independent code files linked together to form a whole.<br />
<br />
First off, HelloWorld.hs - containing a very generic program skeleton. We will use our module Bindings to setup everything else we might need, and tie them to the callbacks.<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Bindings<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
createWindow "Hello World"<br />
displayCallback $= display<br />
reshapeCallback $= Just reshape<br />
keyboardMouseCallback $= Just keyboardMouse<br />
mainLoop<br />
</haskell><br />
Then Bindings.hs - our switchboard<br />
<haskell><br />
module Bindings (display,reshape,keyboardMouse) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Display<br />
reshape s@(Size w h) = do <br />
viewport $= (Position 0 0, s)<br />
keyboardMouse key state modifiers position = return ()<br />
</haskell><br />
<br />
We're going to be hacking around a LOT with the display function, so let's isolate that one to a module of its own: Display.hs<br />
<haskell><br />
module Display (display) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Cube<br />
display = do <br />
clear [ColorBuffer]<br />
cube (0.2::GLfloat)<br />
flush<br />
</haskell><br />
And a first utility module, containing the gritty details of drawing the cube <math>[-w,w]^3</math>, called Cube.hs<br />
<haskell><br />
module Cube where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
cube w = do <br />
renderPrimitive Quads $ do<br />
vertex $ Vertex3 w w w<br />
vertex $ Vertex3 w w (-w)<br />
vertex $ Vertex3 w (-w) (-w)<br />
vertex $ Vertex3 w (-w) w<br />
vertex $ Vertex3 w w w<br />
vertex $ Vertex3 w w (-w)<br />
vertex $ Vertex3 (-w) w (-w)<br />
vertex $ Vertex3 (-w) w w<br />
vertex $ Vertex3 w w w<br />
vertex $ Vertex3 w (-w) w<br />
vertex $ Vertex3 (-w) (-w) w<br />
vertex $ Vertex3 (-w) w w<br />
vertex $ Vertex3 (-w) w w<br />
vertex $ Vertex3 (-w) w (-w)<br />
vertex $ Vertex3 (-w) (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) w<br />
vertex $ Vertex3 w (-w) w<br />
vertex $ Vertex3 w (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) w<br />
vertex $ Vertex3 w w (-w)<br />
vertex $ Vertex3 w (-w) (-w)<br />
vertex $ Vertex3 (-w) (-w) (-w)<br />
vertex $ Vertex3 (-w) w (-w)<br />
</haskell><br />
Now, compiling this entire section with the command <hask>ghc –make -package GLUT HelloWorld.hs -o HelloWorld</hask> compiles and links each module needed, and produces, in the end, an executable to be used. There we go! Much more modularized, much smaller and simpler bits and pieces. And - an added boon - we won't normally need to recompile as much for each change we do.<br />
<br />
This skeletal program will look like:<br />
<br />
[[image:OG-Skeleton.png]]<br />
<br />
==Local transformations==<br />
One of the core reasons I started to write this tutorial series was that I wanted to figure out why [http://www.tfh-berlin.de/~panitz/hopengl/skript.html Panitz' tutorial] didn't work for me. The core explanation is simple - the names of some of the functions used has changed since he wrote them. Thus, the matrixExcursion in his tutorial is nowadays named preservingMatrix. This may well change further - though I hope it won't - in which case this tutorial will be painfully out of date as well.<br />
<br />
The idea of preservingMatrix, however, is to take a small piece of drawing actions, and perform them independent of the transformations going on outside that small piece. For demonstration, let's draw a bunch of cubes, shall we?<br />
<br />
We'll change the rather boring display subroutine in Display.hs into one using preservingMatrix to modify each cube drawn individually, giving a new Display.hs:<br />
<haskell><br />
module Display (display) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Cube<br />
points :: [(GLfloat,GLfloat,GLfloat)]<br />
points = map (\k -> (sin(2*pi*k/12),cos(2*pi*k/12),0.0)) [1..12]<br />
display = do <br />
clear [ColorBuffer]<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 x y z<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) points<br />
flush<br />
</haskell><br />
Say... Those points on the unit circle might be something we'll want more of. Let's abstract some again! We'll break them out to a Points.hs. We'll have to juggle a bit with the typesystem to get things to work out, and in the end we get<br />
<haskell><br />
module Points where<br />
import Graphics.Rendering.OpenGL<br />
points :: Int -> [(GLfloat,GLfloat,GLfloat)]<br />
points n' = let n = fromIntegral n' in map (\k -> let t = 2*pi*k/n in (sin(t),cos(t),0.0)) [1..n]<br />
</haskell><br />
and then we get the Display.hs<br />
<haskell><br />
module Display (display) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Cube<br />
import Points<br />
display = do <br />
clear [ColorBuffer]<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
flush<br />
</haskell><br />
where we note that we need to renormalize our colours to get them within the interval [0,1] from the interval [-1,1] in order to get valid colour values. The program looks like<br />
<br />
[[image:OG-7circle.png]]<br />
<br />
The point of this yoga doesn't come apparent until you start adding some global transformations as well. So let's! We add the line<br />
<br />
<haskell>scale 0.7 0.7 (0.7::GLfloat)</haskell><br />
<br />
just after the <hask>clear [ColorBuffer]</hask>, in order to scale the entire picture. As a result, we get<br />
<br />
[[image:OG-7circlescaled.png]]<br />
<br />
We can do this with all sorts of transformations - we can rotate the picture, skew it, move the entire picture around. Using preservingMatrix, we make sure that the transformations “outside” apply in the way we'd expect them to.<br />
<br />
==Back to the callbacks==<br />
===Animation===<br />
A lot of the OpenGL programming is centered around the program being prepared to launch some sequence when some event occurs. Let's use this to build a rotating version of our bunch of points up there. In order to do things over time, we're going to be using the global callbacks idleCallback and timerCallback. So, we'll modify the structure of our files a bit - starting from the top.<br />
<br />
We'll need a new callback. And we'll also need a state variable of our own, which in turn needs to be fed to all functions that may need to use it. Incorporating these changes, we get a new HelloWorld.hs:<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Bindings<br />
import Data.IORef<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
createWindow "Hello World"<br />
reshapeCallback $= Just reshape<br />
keyboardMouseCallback $= Just keyboardMouse<br />
angle <- newIORef 0.0<br />
displayCallback $= (display angle)<br />
idleCallback $= Just (idle angle)<br />
mainLoop<br />
</haskell><br />
Note the addition of an angle, and an idle. We need to feed the value of angle both to idle and to display, in order for them to use it accordingly. Now, we need to define idle somewhere - and since we keep all the bits and pieces we modify a LOT in display, let's put it in there.<br />
<br />
Exporting it all the way requires us to change the first line of Bindings.hs to<br />
<haskell>module Bindings (idle,display,reshape,keyboardMouse) where</haskell><br />
<br />
Display.hs:<br />
<haskell><br />
module Display (display,idle) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Cube<br />
import Points<br />
display angle = do <br />
clear [ColorBuffer]<br />
a <- get angle<br />
rotate a $ Vector3 0 0 (1::GLfloat)<br />
scale 0.7 0.7 (0.7::GLfloat)<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
flush<br />
idle angle = do<br />
a <- get angle<br />
angle $=! a + 0.1<br />
postRedisplay Nothing -- Only required on Mac OS X, which double-buffers internally<br />
</haskell><br />
<br />
Now, running this program makes a couple of different things painfully obvious. One is that things flicker. (Note: Mac OS X double-buffers internally so it does not flicker). Another is that our ring is shrinking violently. The shrinking is due to our forgetting to reset all our transformations before we apply the next, and the flicker is because we're redrawing an entire picture step by step. Much smoother animation'll be had if we use a double buffering technique. Now, this isn't at all hard. We need to modify a few places - tell HOpenGL that we want to do doublebuffering and also when we want to swap the ready drawn canvas for the one on the screen. So, we modify, again, HelloWorld.hs:<br />
<br />
<haskell><br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Bindings<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
initialDisplayMode $= [DoubleBuffered]<br />
createWindow "Hello World"<br />
reshapeCallback $= Just reshape<br />
keyboardMouseCallback $= Just keyboardMouse<br />
angle <- newIORef 0.0<br />
idleCallback $= Just (idle angle)<br />
displayCallback $= (display angle)<br />
mainLoop<br />
</haskell><br />
and we also need to modify Display.hs to implement the bufferswapping. While we're at it, we add the command loadIdentity, which resets the modification matrix.<br />
<haskell><br />
module Display (display,idle) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Cube<br />
import Points<br />
display angle = do <br />
clear [ColorBuffer]<br />
loadIdentity<br />
a <- get angle<br />
rotate a $ Vector3 0 0 (1::GLfloat)<br />
scale 0.7 0.7 (0.7::GLfloat)<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
swapBuffers<br />
idle angle = do<br />
a <- get angle<br />
angle $=! a+0.1<br />
postRedisplay Nothing<br />
</haskell><br />
<br />
There we are! That looks pretty, doesn't it? Now, we could start adding control to the user, couldn't we? Let's add some keyboard interfaces. We'll start by letting the rotation direction change when we press spacebar, and let the arrows displace the whole figure and + and - increase/decrease the rotation speed.<br />
Again, we're adding states, so we need to modify HelloWorld.hs<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Bindings<br />
main = do<br />
(progname,_) <- getArgsAndInitialize<br />
initialDisplayMode $= [DoubleBuffered]<br />
createWindow "Hello World"<br />
reshapeCallback $= Just reshape<br />
angle <- newIORef (0.0::GLfloat)<br />
delta <- newIORef (0.1::GLfloat)<br />
position <- newIORef (0.0::GLfloat, 0.0)<br />
keyboardMouseCallback $= Just (keyboardMouse delta position)<br />
idleCallback $= Just (idle angle delta)<br />
displayCallback $= (display angle position)<br />
mainLoop<br />
<br />
Note that position is sent along to the keyboard as well as the display callbacks. And in Bindings.hs, we give the keyboard callback actual function<br />
<haskell><br />
module Bindings (idle,display,reshape,keyboardMouse) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Display<br />
reshape s@(Size w h) = do <br />
viewport $= (Position 0 0, s)<br />
keyboardAct a p (Char ' ') Down = do<br />
a' <- get a<br />
a $= -a'<br />
keyboardAct a p (Char '+') Down = do<br />
a' <- get a<br />
a $= 2*a'<br />
keyboardAct a p (Char '-') Down = do<br />
a' <- get a<br />
a $= a'/2<br />
keyboardAct a p (SpecialKey KeyLeft) Down = do<br />
(x,y) <- get p<br />
p $= (x-0.1,y)<br />
keyboardAct a p (SpecialKey KeyRight) Down = do<br />
(x,y) <- get p<br />
p $= (x+0.1,y)<br />
keyboardAct a p(SpecialKey KeyUp) Down = do<br />
(x,y) <- get p<br />
p $= (x,y+0.1)<br />
keyboardAct a p (SpecialKey KeyDown) Down = do<br />
(x,y) <- get p<br />
p $= (x,y-0.1)<br />
keyboardAct _ _ _ _ = return ()<br />
keyboardMouse angle pos key state modifiers position = do<br />
keyboardAct angle pos key state<br />
</haskell><br />
<br />
finally, in Display.hs we use the new information to accordingly redraw the scene, specifically the now changing amount to change the current angle with. Note that in order to avoid the placement of the circle to be pulled in with all the other modifications we're doing, we do the translation outside a preservingMatrix call.<br />
<br />
<haskell><br />
module Display (display,idle) where<br />
import Graphics.Rendering.OpenGL<br />
import Graphics.UI.GLUT<br />
import Data.IORef<br />
import Cube<br />
import Points<br />
display angle position = do <br />
clear [ColorBuffer]<br />
loadIdentity<br />
(x,y) <- get position<br />
translate $ Vector3 x y 0<br />
preservingMatrix $ do <br />
a <- get angle<br />
rotate a $ Vector3 0 0 (1::GLfloat)<br />
scale 0.7 0.7 (0.7::GLfloat)<br />
mapM_ (\(x,y,z) -> preservingMatrix $ do<br />
color $ Color3 ((x+1.0)/2.0) ((y+1.0)/2.0) ((z+1.0)/2.0)<br />
translate $ Vector3 x y z<br />
cube (0.1::GLfloat)<br />
) $ points 7<br />
swapBuffers<br />
idle angle delta = do<br />
a <- get angle<br />
d <- get delta<br />
angle $=! a+d<br />
postRedisplay Nothing<br />
</haskell><br />
<br />
==Summary==<br />
We now know how to modify only parts of a picture, and we also know how to use the idle and the keyboardMouse callback to support animations and keyboard input.<br />
<br />
In order to somewhat limit the amount of typing I need to do, I'll give links that give details on some of the themes we've touched upon.<br />
<br />
First of all, the callbacks are described in more detail and with call signatures at<br />
[http://haskell.org/ghc/docs/latest/html/libraries/GLUT/Graphics-UI-GLUT-Callbacks-Global.html] for the global callbacks (menu systems, and timing/idle callbacks)<br />
<br />
[http://haskell.org/ghc/docs/latest/html/libraries/GLUT/Graphics-UI-GLUT-Callbacks-Window.html] for the window-specific callbacks (display, reshape, keyboard&mouse, visibility changes, window closing, mouse movement, spaceballs, drawing tablets, joysticks and dial&button)<br />
<br />
Furthermore, the various primitives for drawing are listed at [http://haskell.org/ghc/docs/latest/html/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-BeginEnd.html].<br />
<br />
There are 3-dimensional primitives ready as well. These can be found at [http://haskell.org/ghc/docs/latest/html/libraries/GLUT/Graphics-UI-GLUT-Objects.html]<br />
<br />
The flag I set to trigger double buffering is described among the GLUT initialization methods, see [http://haskell.org/ghc/docs/latest/html/libraries/GLUT/Graphics-UI-GLUT-Initialization.html] for everything you can do there.<br />
<br />
(Note: if you can't find the references in [http://haskell.org/ghc/docs/latest/html/libraries/ http://haskell.org/ghc/docs/latest/html/libraries/...] just now, try [http://haskell.org/ghc/docs/6.8-latest/html/libraries/ http://haskell.org/ghc/docs/6.8-latest/html/libraries/...]. Hopefully, someone who knows what's what will be able to fix this properly before long.)<br />
<br />
Next time, I figure I'll get around to do Mouse callbacks and 3d graphics. We'll see.</div>Jmcarthur