fwgl-0.1.3.1: Game engine

Safe HaskellNone
LanguageHaskell2010

FWGL

Contents

Description

The main module. You should also import a backend:

  • FWGL.Backend.JavaScript: GHCJS/WebGL backend (contained in fwgl-javascript)
  • FWGL.Backend.GLFW.GL20: GLFW/OpenGL 2.0 backend (contained in fwgl-glfw)

And a graphics system:

FWGL.Shader contains the EDSL to make custom shaders.

Import FWGL.Internal.GL if you want to use the raw GL commands.

Synopsis

Documentation

module FWGL.Input

module FRP.Yampa

fwgl :: BackendIO => FWGL () -> IO () Source

Initialize the FWGL backend, run the action and terminate it.

mapIO :: (IO a -> IO b) -> FWGL a -> FWGL b Source

Useful for functions like forkIO and forkOS.

FRP interface

data Output Source

The general output.

run Source

Arguments

:: BackendIO 
=> SF (Input ()) Output

Main signal

-> FWGL () 

Run a FWGL program on a new canvas/window.

run' Source

Arguments

:: BackendIO 
=> IO inp

An IO effect generating the custom inputs.

-> SF (Input inp) Output 
-> FWGL () 

Run a FWGL program, using custom inputs.

runTo Source

Arguments

:: BackendIO 
=> String

Destination canvas (eg. "#myCanvasId"). This has meaning only in the JavaScript backend.

-> IO inp

An IO effect generating the custom inputs.

-> SF (Input inp) Output 
-> FWGL () 

Run a FWGL program, using custom inputs and a specified canvas.

draw :: BackendIO => [Layer] -> Output Source

Draw some layers. Short for:

drawM . mapM_ drawLayer

File loading

loadOBJ :: BackendIO => FilePath -> IO (Either String (Geometry Geometry3D)) Source

Load a model from an OBJ file.

loadOBJAsync Source

Arguments

:: BackendIO 
=> FilePath

Path or URL.

-> (Either String (Geometry Geometry3D) -> IO ())

Callback.

-> IO () 

Load a model from an OBJ file asynchronously.

loadTextFileAsync Source

Arguments

:: BackendIO 
=> FilePath

Path or URL.

-> (Either String String -> IO ())

Callback.

-> IO () 

Load a file asynchronously.

Effect monad

eff :: Effect () -> Output Source

Perform an effect.

drawEff :: BackendIO => [Layer] -> Effect () -> Output Source

Draw some layers and perform an effect.

drawMEff :: Draw a -> (a -> Effect ()) -> Output Source

Run a Draw action and perform an effect.

fastStep :: Effect () -> Output Source

Use this instead of eff when you want the next sample to be performed immediately (e.g. when you need to produce some computationally expensive effectful input at the request of the signal function).

Lifting functions

liftIO :: MonadIO m => forall a. IO a -> m a

Lift a computation from the IO monad.

liftDraw :: Draw a -> Effect a Source

Perform a Draw effect. Note that (eff . liftDraw) is different from drawM: you have to use drawM to actually draw something on the screen. liftDraw should be used to modify the state of the context, to get some information from it, to render a Layer on a Texture, ecc.

Window/Canvas

setSize Source

Arguments

:: BackendIO 
=> Int

Width

-> Int

Height

-> Effect () 

Set canvas/window size.

setTitle :: BackendIO => String -> Effect () Source

Set window title.

Draw monad (for advanced use)

data Draw a Source

A state monad on top of GL.

drawM :: Draw () -> Output Source

Run a Draw action.

Drawing

drawLayer :: (GLES, BackendIO) => Layer -> Draw () Source

Draw a Layer.

drawGroup :: (GLES, BackendIO) => Group gs is -> Draw () Source

Draw a Group.

drawObject :: (GLES, BackendIO) => Object gs is -> Draw () Source

Draw an Object.

setProgram :: (GLES, BackendIO) => Program g i -> Draw () Source

Set the program.

renderLayer :: BackendIO => RenderLayer a -> Draw (a, [Texture]) Source

Realize a RenderLayer. It returns the list of allocated Textures so that you can free them if you want.

resizeViewport Source

Arguments

:: GLES 
=> Int

Width.

-> Int

Height.

-> Draw () 

Viewport.

gl :: GL a -> Draw a Source

Perform a GL action in the Draw monad.

Texture functions

textureUniform :: (GLES, BackendIO) => Texture -> Draw ActiveTexture Source

This helps you set the uniforms of type Sampler2D.

textureSize :: (GLES, BackendIO, Num a) => Texture -> Draw (a, a) Source

Get the dimensions of a Texture.

Resources

removeGeometry :: (GLES, BackendIO) => Geometry is -> Draw Bool Source

Delete a Geometry from the GPU.

removeTexture :: BackendIO => Texture -> Draw Bool Source

Delete a Texture from the GPU.

removeProgram :: (GLES, BackendIO) => Program gs is -> Draw Bool Source

Delete a Program from the GPU.

IO interface

runIO Source

Arguments

:: BackendIO 
=> (Double -> Input () -> IO Output)

Loop function

-> FWGL () 

Run a non-reactive FWGL program.

runToIO Source

Arguments

:: BackendIO 
=> String

Destination canvas (eg. "#myCanvasId"). This only has

-> (Int -> Int -> IO ())

Initialization function

-> (Double -> Input () -> IO Output)

Loop function

-> FWGL () 

Run a non-reactive FWGL program in a specified canvas.