Note: There are two GLFW hackage packages {{HackagePackage|id=GLFW}} and {{HackagePackage|id=GLFW-b}}. This article is about GLFW (except for bottom paragraph).

== About ==

== About ==

−

This is a Haskell module for [http://glfw.sourceforge.net GLFW OpenGL framework]. It provides an alternative to GLUT for OpenGL based Haskell programs.

+

This is a Haskell module for [http://www.glfw.org/ GLFW OpenGL framework]. It provides an alternative to GLUT for OpenGL based Haskell programs.

== Status ==

== Status ==

−

The library is being used by the [http://www.haskell.org/soe Haskell School of Expression (SOE)] code to render Graphics in a cross-platform manner. It currently interfaces with GLFW version 2.6, works on Windows, Linux (i386) and Mac OS X (both intel and ppc).

+

The library is being used by the [http://www.cs.yale.edu/homes/hudak/SOE/ Haskell School of Expression (SOE)] code to render Graphics in a cross-platform manner. It currently interfaces with GLFW version 2.7.2, works on Windows, Linux (i386) and Mac OS X.

Current version is [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/GLFW-0.3 GLFW-0.3]. It's a repackage to work with Cabal 1.2 or later. It now compiles GLFW C source code as part of the building process, please report to the package maintainer if you have build problems.

+

Current version is [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/GLFW GLFW-0.5.0.0]. It works with Cabal 1.10 or later. It compiles GLFW C source code as part of the building process, please report to the package maintainer if you have build problems.

A number of famous [http://nehe.gamedev.net/ NeHe OpenGL tutorials] have been translated into Haskell using [http://hackage.haskell.org/package/GLFW-b GLFW-b] (instead of GLFW) and made available in the [http://hackage.haskell.org/package/nehe-tuts nehe-tuts package] by Jason Dagit. Code as well as executables are available via the package page.

Revision as of 16:22, 14 July 2012

Note: There are two GLFW hackage packages GLFW and GLFW-b. This article is about GLFW (except for bottom paragraph).

Contents

1 About

This is a Haskell module for GLFW OpenGL framework. It provides an alternative to GLUT for OpenGL based Haskell programs.

2 Status

The library is being used by the Haskell School of Expression (SOE) code to render Graphics in a cross-platform manner. It currently interfaces with GLFW version 2.7.2, works on Windows, Linux (i386) and Mac OS X.

Not all functions are fully tested, and there are still a
few GLFW C functions missing from the Haskell module, namely
the image loading functions. They are excluded because image
handling is a separate issue, and low level buffer manipulation
would obscure their use further. Texture loading from TGA
format is supported both from file and from memory (via a
string buffer)..

The Haskell module also provides basic text rendering while
GLFW doesn't. It comes from a free 8x16 font which is made
into a TGA texture, stored as a Haskell string in the file
GLFW.hs. Text rendering
is only possible with Alpha enabled. Again, see SOE.hs from
the SOE package for sample usage.

GLFW may not work well with GHC threads, forkIO or threadDelay.
So avoid them if you can.

3 Download

Current version is GLFW-0.5.0.0. It works with Cabal 1.10 or later. It compiles GLFW C source code as part of the building process, please report to the package maintainer if you have build problems.

Another way to structure the main loop is to register event callbacks and use

waitEvents

. This way we don't have to put the program to sleep every 1ms because it'll not be using any CPU cycle when there is no event to handle.
One reminder in this approach is that

swapBuffers

must be handled with care, because it by default invokes

pollEvents

, which in turn invokes all callback functions. So if

swapBuffers

is used inside a callback, it'll create infinite loop and hang the program. To avoid it, we should disable the

AutoPollEvent

behavior using

disableSpecial

.

Another optimization we can do is to use a dirty marker to remember whether the screen really needs to be redrawn. This'll not only save CPU cycles but also speed up event processing to avoid piling up events in the event queue. Similar tricks can be done to optimize the active polling approach.

6 More examples and external links

A number of famous NeHe OpenGL tutorials have been translated into Haskell using GLFW-b (instead of GLFW) and made available in the nehe-tuts package by Jason Dagit. Code as well as executables are available via the package page.