GLFW-0.3: A binding for GLFW, An OpenGL FrameworkSource codeContentsIndex
Graphics.UI.GLFW
Contents
Data Types
Initialization and Window functions
Event Handling functions
Callbacks
Window Callbacks
Event Callbacks
Other functions
Texture Loading functions
Text Rendering function (not in GLFW C library)
GLFW Thread Support functions are omitted purposely
Description

Interface to GLFW - An OpenGL Framework.

It provides an alternative to GLUT for OpenGL based Haskell programs, and currently supports GLFW API version 2.6 http://glfw.sourceforge.net.

Synopsis
type Version = (Int, Int, Int)
data DisplayBits
= DisplayRGBBits !Int !Int !Int
| DisplayAlphaBits !Int
| DisplayDepthBits !Int
| DisplayStencilBits !Int
data WindowMode
= Window
| FullScreen
data WindowHint
= RefreshRate
| AccumRedBits
| AccumGreenBits
| AccumBlueBits
| AccumAlphaButs
| AuxBuffers
| Stereo
| NoResize
| FSAASamples
data WindowParam
= Opened
| Active
| Iconified
| Accelerated
| RedBits
| GreenBits
| BlueBits
| AlphaBits
| DepthBits
| StencilBits
data VideoMode = VideoMode {
videoWidth :: !Int
videoHeight :: !Int
videoRedBits :: !Int
videoBlueBits :: !Int
videoGreenBits :: !Int
}
data KeyButtonState
= Release
| Press
data Key
= CharKey Char
| SpecialKey SpecialKey
data SpecialKey
= UNKNOWN
| ESC
| F1
| F2
| F3
| F4
| F5
| F6
| F7
| F8
| F9
| F10
| F11
| F12
| F13
| F14
| F15
| F16
| F17
| F18
| F19
| F20
| F21
| F22
| F23
| F24
| F25
| UP
| DOWN
| LEFT
| RIGHT
| LSHIFT
| RSHIFT
| LCTRL
| RCTRL
| LALT
| RALT
| TAB
| ENTER
| BACKSPACE
| INSERT
| DEL
| PAGEUP
| PAGEDOWN
| HOME
| END
| KP_0
| KP_1
| KP_2
| KP_3
| KP_4
| KP_5
| KP_6
| KP_7
| KP_8
| KP_9
| KP_DIVIDE
| KP_MULTIPLY
| KP_SUBTRACT
| KP_ADD
| KP_DECIMAL
| KP_EQUAL
| KP_ENTER
data MouseButton
= ButtonLeft
| ButtonRight
| ButtonMiddle
| ButtonNo Int
newtype Joystick = Joystick Int
data JoystickParam
= Present
| Axes
| Buttons
data SpecialFeature
= MouseCursor
| StickyKey
| StickyMouseButton
| SystemKey
| KeyRepeat
| AutoPollEvent
data TextureFlag
= NoRescale
| OriginUL
| BuildMipMaps
| AlphaMap
data BitmapFont = Fixed8x16
type WindowCloseCallback = IO ()
type WindowSizeCallback = Size -> IO ()
type WindowRefreshCallback = IO ()
type KeyCallback = Key -> KeyButtonState -> IO ()
type CharCallback = Char -> KeyButtonState -> IO ()
type MouseButtonCallback = MouseButton -> KeyButtonState -> IO ()
type MousePosCallback = Position -> IO ()
type MouseWheelCallback = Int -> IO ()
initialize :: IO Bool
terminate
videoModes :: GettableStateVar [VideoMode]
desktopMode :: GettableStateVar VideoMode
version :: GettableStateVar Version
openWindow :: Size -> [DisplayBits] -> WindowMode -> IO Bool
openWindowHint :: SettableStateVar (WindowHint, Int)
closeWindow :: IO ()
windowTitle :: SettableStateVar String
windowSize :: StateVar Size
iconifyWindow :: IO ()
restoreWindow :: IO ()
swapBuffers :: IO ()
swapInterval :: SettableStateVar Int
windowParam :: WindowParam -> GettableStateVar Int
joystickParam :: Joystick -> JoystickParam -> GettableStateVar Int
pollEvents :: IO ()
waitEvents :: IO ()
getKey :: Enum a => a -> IO KeyButtonState
getMouseButton :: MouseButton -> IO KeyButtonState
mousePos :: StateVar Position
mouseWheel :: StateVar Int
joystickPos :: Joystick -> GettableStateVar [Int]
joystickButtons :: Joystick -> GettableStateVar [KeyButtonState]
windowSizeCallback :: SettableStateVar WindowSizeCallback
windowCloseCallback :: SettableStateVar WindowCloseCallback
windowRefreshCallback :: SettableStateVar WindowRefreshCallback
keyCallback :: SettableStateVar KeyCallback
charCallback :: SettableStateVar CharCallback
mouseButtonCallback :: SettableStateVar MouseButtonCallback
mousePosCallback :: SettableStateVar MousePosCallback
mouseWheelCallback :: SettableStateVar MouseWheelCallback
time :: StateVar Double
sleep :: Double -> IO ()
extensionSupported :: String -> IO Bool
enableSpecial :: SpecialFeature -> IO ()
disableSpecial :: SpecialFeature -> IO ()
loadTexture2D :: String -> [TextureFlag] -> IO Bool
loadMemoryTexture2D :: String -> [TextureFlag] -> IO Bool
renderString :: BitmapFont -> String -> IO ()
Data Types
type Version = (Int, Int, Int)Source
Version is represented by (major, minor, revision), used in gettable variable version.
data DisplayBits Source
Bit depth of GL display buffers, used in openWindow.
Constructors
DisplayRGBBits !Int !Int !Int
DisplayAlphaBits !Int
DisplayDepthBits !Int
DisplayStencilBits !Int
show/hide Instances
data WindowMode Source
Window or Fullscreen mode, used in openWindow.
Constructors
Window
FullScreen
show/hide Instances
data WindowHint Source
Window hints, used in settable variable openWindowHint.
Constructors
RefreshRate
AccumRedBits
AccumGreenBits
AccumBlueBits
AccumAlphaButs
AuxBuffers
Stereo
NoResize
FSAASamples
show/hide Instances
data WindowParam Source
Window parameters used in gettable variable windowParam.
Constructors
Opened
Active
Iconified
Accelerated
RedBits
GreenBits
BlueBits
AlphaBits
DepthBits
StencilBits
show/hide Instances
data VideoMode Source
Video modes used in gettable variables videoModes and desktopMode.
Constructors
VideoMode
videoWidth :: !Int
videoHeight :: !Int
videoRedBits :: !Int
videoBlueBits :: !Int
videoGreenBits :: !Int
show/hide Instances
data KeyButtonState Source
Key or button state.
Constructors
Release
Press
show/hide Instances
data Key Source
Key is represented by either a character key or a special key.
Constructors
CharKey Char
SpecialKey SpecialKey
show/hide Instances
data SpecialKey Source
Special key is a key not represented in the 32 - 127 printable ASCII range.
Constructors
UNKNOWN
ESC
F1
F2
F3
F4
F5
F6
F7
F8
F9
F10
F11
F12
F13
F14
F15
F16
F17
F18
F19
F20
F21
F22
F23
F24
F25
UP
DOWN
LEFT
RIGHT
LSHIFT
RSHIFT
LCTRL
RCTRL
LALT
RALT
TAB
ENTER
BACKSPACE
INSERT
DEL
PAGEUP
PAGEDOWN
HOME
END
KP_0
KP_1
KP_2
KP_3
KP_4
KP_5
KP_6
KP_7
KP_8
KP_9
KP_DIVIDE
KP_MULTIPLY
KP_SUBTRACT
KP_ADD
KP_DECIMAL
KP_EQUAL
KP_ENTER
show/hide Instances
data MouseButton Source
Mouse button is represented by left, right, middle or a number from 0 to 7 (note the difference from the GLFW C library).
Constructors
ButtonLeft
ButtonRight
ButtonMiddle
ButtonNo Int
show/hide Instances
newtype Joystick Source
Joystick is represent a number from 0 to 15 (note the difference from the GLFW C library).
Constructors
Joystick Int
show/hide Instances
data JoystickParam Source
Joystick parameters
Constructors
Present
Axes
Buttons
show/hide Instances
data SpecialFeature Source
Special features used in enableSpecial and disableSpecial.
Constructors
MouseCursor
StickyKey
StickyMouseButton
SystemKey
KeyRepeat
AutoPollEvent
show/hide Instances
data TextureFlag Source
Texture flag used in loadTexture2D and loadMemoryTexture2D.
Constructors
NoRescale
OriginUL
BuildMipMaps
AlphaMap
show/hide Instances
data BitmapFont Source
Build-in bitmap font used in renderString.
Constructors
Fixed8x168x16 fixed width font.
show/hide Instances
type WindowCloseCallback = IO ()Source
Callback type for windowCloseCallback.
type WindowSizeCallback = Size -> IO ()Source
Callback type for windowSizeCallback.
type WindowRefreshCallback = IO ()Source
Callback type for windowRefreshCallback.
type KeyCallback = Key -> KeyButtonState -> IO ()Source
Callback type for keyCallback.
type CharCallback = Char -> KeyButtonState -> IO ()Source
Callback type for charCallback.
type MouseButtonCallback = MouseButton -> KeyButtonState -> IO ()Source
Callback type for mouseButtonCallback.
type MousePosCallback = Position -> IO ()Source
Callback type for mousePosCallback.
type MouseWheelCallback = Int -> IO ()Source
Callback type for mouseWheelCallback.
Initialization and Window functions
initialize :: IO BoolSource

Initialize GLFW library before use, returns True if successful or False otherwise.

Before any GLFW functions can be used, GLFW must be initialized to ensure proper functionality.

terminate
videoModes :: GettableStateVar [VideoMode]Source
Get a list of deteced VideoModes, the max number of which is limited to 256 for now.
desktopMode :: GettableStateVar VideoModeSource
Get the VideoMode of current desktop.
version :: GettableStateVar VersionSource
Returns the supported GLFW C library version numbers.
openWindow :: Size -> [DisplayBits] -> WindowMode -> IO BoolSource

Open the Window of the given size and other parameters, returns True if successful or False otherwise.

GLFW applications can only open one Window, which is assumed to be the default place where renderings take place.

openWindowHint :: SettableStateVar (WindowHint, Int)Source
Set the Window hints, i.e., additional Window properties, before openWindow.
closeWindow :: IO ()Source
Close the open Window and destroys the associated OpenGL context.
windowTitle :: SettableStateVar StringSource
Set the title of the opened Window.
windowSize :: StateVar SizeSource
Get or set the size of the opened Window.
iconifyWindow :: IO ()Source
Iconify the Window which can later by retored.
restoreWindow :: IO ()Source
Restore the Window after iconification.
swapBuffers :: IO ()Source
Swap the back and front color buffers of the Window. If AutoPollEvent is enabled by enableSpecial (which is the default), it also polls for new events before the swapping.
swapInterval :: SettableStateVar IntSource
Set the minimum number of monitor retraces between each each buffer swap performed by swapBuffers. If set to zero, buffer swaps will not be synchronized to the vertical refresh of the monitor.
windowParam :: WindowParam -> GettableStateVar IntSource
Get the value of Window parameters.
joystickParam :: Joystick -> JoystickParam -> GettableStateVar IntSource
Get joystick parameters.
Event Handling functions
pollEvents :: IO ()Source
Poll events, such as user input and window events. Upon calling this function, all window states, keyboard states and mouse states are updated. If any related callback functions are registered, these are called during the call of pollEvents.
waitEvents :: IO ()Source
Wait for events, such as user input and window events. The calling thread will be put to sleep until any event appears in the event queue. When events are ready, the events will be processed just as they are processed by pollEvents.
getKey :: Enum a => a -> IO KeyButtonStateSource
Return a KeyButtonState, either Release or Press, of the indicated key.
getMouseButton :: MouseButton -> IO KeyButtonStateSource
Return a KeyButtonState, either Release or Press, of the indicated mouse button.
mousePos :: StateVar PositionSource
Set or get the mouse position.
mouseWheel :: StateVar IntSource
Set or get the mouse wheel position.
joystickPos :: Joystick -> GettableStateVar [Int]Source
Get joystick positions. The returned list contains the positions for all available axes for the given joystick.
joystickButtons :: Joystick -> GettableStateVar [KeyButtonState]Source
Get joystick button states. The returned list contains the states for all available buttons for the given joystick.
Callbacks
Window Callbacks
windowSizeCallback :: SettableStateVar WindowSizeCallbackSource
Set the callback function that will be called every time the Window size changes.
windowCloseCallback :: SettableStateVar WindowCloseCallbackSource
Set the callback function that will be called when the Window is closed.
windowRefreshCallback :: SettableStateVar WindowRefreshCallbackSource
Set the callback function that will be called when the Window client area needs to be refreshed, which occurs when any part of the window client area is damaged and needs to be repainted (for instance, if a part of the window that was previously occluded by another window has become visible).
Event Callbacks
keyCallback :: SettableStateVar KeyCallbackSource
Set the callback function that will be called when there is a key event, i.e., everytime the state of a single key is changed. The reported keys are unaffected by any modifiers (such as SHIFT or ALT).
charCallback :: SettableStateVar CharCallbackSource
Set the callback function that will be called when there is a character event, i.e., everytime a key that results in a printable Unicode character is pressed or released. Characters are affected by modifiers (such as SHIFT or ALT).
mouseButtonCallback :: SettableStateVar MouseButtonCallbackSource
Set the callback function that will be called when there is a mouse button event, i.e., everytime a mouse button is pressed or released.
mousePosCallback :: SettableStateVar MousePosCallbackSource
Set the callback function that will be called when there is a mouse motion event, i.e., everytime they mouse is moved.
mouseWheelCallback :: SettableStateVar MouseWheelCallbackSource
Set the callback function that will be called when there is a mouse wheel event, i.e., everytime the mouse wheel is turned.
Other functions
time :: StateVar DoubleSource

Get or set the value of the high precision timer. The time is measured in seconds as a double precision floasting point number.

Unless the timer has been set by the programmer, the time is measured as the number of seconds that have passed since initialize was called.

sleep :: Double -> IO ()Source

Put the calling thread to sleep for the requested period of time in seconds.

The time is generally in the range 1ms to 20ms, depending on thread scheduling time slot intervals etc.

extensionSupported :: String -> IO BoolSource
Return True if the extension is supported, otherwise False.
enableSpecial :: SpecialFeature -> IO ()Source
Enable a SpecialFeature.
disableSpecial :: SpecialFeature -> IO ()Source
Disable a SpecialFeature.
Texture Loading functions
loadTexture2D :: String -> [TextureFlag] -> IO BoolSource

Read an image from a file specified by the given string and upload the image to OpenGL texture memory.

If BuildMipMaps flag is given, all mipmap levels for the loaded texture are generated and uploaded to texture memory.

Unless the OriginUL flag is given, the origin of the texture is the lower left corner of the loaded image. If OriginUL is given, however, the first pixel is the upper left corner.

For single component images (i.e. gray scale), the texture is uploaded as an alpha mask if the flag AlphaMap is set, otherwise it's uploaded as a luminance texture.

It only supports the Truevision Targa verson 1 file (.tga). Supported pixel formats are: 8-bit gray scale, 8-bit paletted (24/32-bit color), 24-bit true color and 32-bit true color + alpha.

Paletted images are translated into true color or tru color + alpha pixel formats.

The read texture is always rescaled to the nearest larger 2^m x 2^n resolution using bilinear interpolation if necessary.

loadMemoryTexture2D :: String -> [TextureFlag] -> IO BoolSource
Read an image from the memory buffer (the given byte string) and upload the image to OpenGL texture memory. The rest is similar to loadTexture2D.
Text Rendering function (not in GLFW C library)
renderString :: BitmapFont -> String -> IO ()Source

Render a text string using the given BitmapFont.

Text is rendered through texture, and is only possible with alpha enabled.

GLFW Thread Support functions are omitted purposely
Produced by Haddock version 2.4.2