OpenGL-2.2.3.1: A binding for the OpenGL graphics system

Portability | portable
Stability | stable
Maintainer | sven.panne@aedion.de
Safe Haskell | None

Graphics.Rendering.OpenGL.GL.CoordTrans

Contents

- Controlling the Viewport
- Matrices
- Normal Transformation
- Generating Texture Coordinates

Description

This module corresponds to section 2.11 (Coordinate Transformations) of the OpenGL 2.1 specs.

Synopsis

- depthRange :: StateVar (GLclampd, GLclampd)
- data Position = Position !GLint !GLint
- data Size = Size !GLsizei !GLsizei
- viewport :: StateVar (Position, Size)
- maxViewportDims :: GettableStateVar Size
- data MatrixMode
  - = Modelview GLsizei
  - | Projection
  - | Texture
  - | Color
  - | MatrixPalette
- matrixMode :: StateVar MatrixMode
- newtype Vector1 a = Vector1 a
- data Vector2 a = Vector2 !a !a
- data Vector3 a = Vector3 !a !a !a
- data Vector4 a = Vector4 !a !a !a !a
- data MatrixOrder
  - = ColumnMajor
  - | RowMajor
- class Storable c => MatrixComponent c where
  - rotate :: c -> Vector3 c -> IO ()
  - translate :: Vector3 c -> IO ()
  - scale :: c -> c -> c -> IO ()
- class Matrix m where
  - withNewMatrix :: MatrixComponent c => MatrixOrder -> (Ptr c -> IO ()) -> IO (m c)
  - withMatrix :: MatrixComponent c => m c -> (MatrixOrder -> Ptr c -> IO a) -> IO a
  - newMatrix :: MatrixComponent c => MatrixOrder -> [c] -> IO (m c)
  - getMatrixComponents :: MatrixComponent c => MatrixOrder -> m c -> IO [c]
- currentMatrix :: (Matrix m, MatrixComponent c) => StateVar (m c)
- matrix :: (Matrix m, MatrixComponent c) => Maybe MatrixMode -> StateVar (m c)
- multMatrix :: (Matrix m, MatrixComponent c) => m c -> IO ()
- data GLmatrix a
- loadIdentity :: IO ()
- ortho :: GLdouble -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> IO ()
- frustum :: GLdouble -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> IO ()
- depthClamp :: StateVar Capability
- activeTexture :: StateVar TextureUnit
- preservingMatrix :: IO a -> IO a
- unsafePreservingMatrix :: IO a -> IO a
- stackDepth :: Maybe MatrixMode -> GettableStateVar GLsizei
- maxStackDepth :: MatrixMode -> GettableStateVar GLsizei
- rescaleNormal :: StateVar Capability
- normalize :: StateVar Capability
- data Plane a = Plane !a !a !a !a
- data TextureCoordName
  - = S
  - | T
  - | R
  - | Q
- data TextureGenMode
  - = EyeLinear (Plane GLdouble)
  - | ObjectLinear (Plane GLdouble)
  - | SphereMap
  - | NormalMap
  - | ReflectionMap
- textureGenMode :: TextureCoordName -> StateVar (Maybe TextureGenMode)

# Controlling the Viewport

depthRange :: StateVar (GLclampd, GLclampd)

After clipping and division by w, depth coordinates range from -1 to 1, corresponding to the near and far clipping planes. `depthRange` specifies a linear mapping of the normalized depth coordinates in this range to window depth coordinates. Regardless of the actual depth buffer implementation, window coordinate depth values are treated as though they range from 0 through 1 (like color components). Thus, the values accepted by `depthRange` are both clamped to this range before they are accepted.

The initial setting of (0, 1) maps the near plane to 0 and the far plane to 1. With this mapping, the depth buffer range is fully utilized.

It is not necessary that the near value be less than the far value. Reverse mappings such as (1, 0) are acceptable.

data Position

A 2-dimensional position, measured in pixels.

Constructors

Position !GLint !GLint |

Instances

Eq Position |
Ord Position |
Show Position |

data Size

A 2-dimensional size, measured in pixels.

Constructors

Size !GLsizei !GLsizei |

Instances

Eq Size |
Ord Size |
Show Size |

viewport :: StateVar (Position, Size)

Controls the affine transformation from normalized device coordinates to window coordinates. The viewport state variable consists of the coordinates (x, y) of the lower left corner of the viewport rectangle, (in pixels, initial value (0,0)), and the size (width, height) of the viewport. When a GL context is first attached to a window, width and height are set to the dimensions of that window.

Let (xnd, ynd) be normalized device coordinates. Then the window coordinates (xw, yw) are computed as follows:

xw = (xnd + 1) (width / 2) + x

yw = (ynd + 1) (heigth / 2) + y

Viewport width and height are silently clamped to a range that depends on the implementation, see `maxViewportDims`.

maxViewportDims :: GettableStateVar Size

The implementation-dependent maximum viewport width and height.

# Matrices

data MatrixMode

A matrix stack.

Constructors

Modelview GLsizei | The modelview matrix stack of the specified vertex unit.
Projection | The projection matrix stack.
Texture | The texture matrix stack.
Color | The color matrix stack.
MatrixPalette | The matrix palette stack.

Instances

Eq MatrixMode |
Ord MatrixMode |
Show MatrixMode |

matrixMode :: StateVar MatrixMode

Controls which matrix stack is the target for subsequent matrix operations. The initial value is (`Modelview` 0).

newtype Vector1 a

A one-dimensional vector.

Constructors

Vector1 a |

Instances

Functor Vector1 |
Typeable1 Vector1 |
Applicative Vector1 |
Foldable Vector1 |
Traversable Vector1 |
Bounded a => Bounded (Vector1 a) |
Eq a => Eq (Vector1 a) |
Ord a => Ord (Vector1 a) |
Read a => Read (Vector1 a) |
Show a => Show (Vector1 a) |
Ix a => Ix (Vector1 a) |
Typeable a => Typeable (Vector1 a) |
Storable a => Storable (Vector1 a) |
VertexAttribComponent a => VertexAttrib (Vector1 a) |

data Vector2 a

A two-dimensional vector.

Constructors

Vector2 !a !a |

Instances

Functor Vector2 |
Typeable1 Vector2 |
Applicative Vector2 |
Foldable Vector2 |
Traversable Vector2 |
Bounded a => Bounded (Vector2 a) |
Eq a => Eq (Vector2 a) |
Ord a => Ord (Vector2 a) |
Read a => Read (Vector2 a) |
Show a => Show (Vector2 a) |
Ix a => Ix (Vector2 a) |
Typeable a => Typeable (Vector2 a) |
Storable a => Storable (Vector2 a) |
VertexAttribComponent a => VertexAttrib (Vector2 a) |

data Vector3 a

A three-dimensional vector.

Constructors

Vector3 !a !a !a |

Instances

Functor Vector3 |
Typeable1 Vector3 |
Applicative Vector3 |
Foldable Vector3 |
Traversable Vector3 |
Bounded a => Bounded (Vector3 a) |
Eq a => Eq (Vector3 a) |
Ord a => Ord (Vector3 a) |
Read a => Read (Vector3 a) |
Show a => Show (Vector3 a) |
Ix a => Ix (Vector3 a) |
Typeable a => Typeable (Vector3 a) |
Storable a => Storable (Vector3 a) |
VertexAttribComponent a => VertexAttrib (Vector3 a) |

data Vector4 a

A four-dimensional vector.

Constructors

Vector4 !a !a !a !a |

Instances

Functor Vector4 |
Typeable1 Vector4 |
Applicative Vector4 |
Foldable Vector4 |
Traversable Vector4 |
Bounded a => Bounded (Vector4 a) |
Eq a => Eq (Vector4 a) |
Ord a => Ord (Vector4 a) |
Read a => Read (Vector4 a) |
Show a => Show (Vector4 a) |
Ix a => Ix (Vector4 a) |
Typeable a => Typeable (Vector4 a) |
Storable a => Storable (Vector4 a) |
VertexAttribComponent a => VertexAttrib (Vector4 a) |

data MatrixOrder

Constructors

ColumnMajor |
RowMajor |

Instances

Eq MatrixOrder |
Ord MatrixOrder |
Show MatrixOrder |

class Storable c => MatrixComponent c where

Methods

rotate :: c -> Vector3 c -> IO ()

translate :: Vector3 c -> IO ()

scale :: c -> c -> c -> IO ()

Instances

MatrixComponent Double |
MatrixComponent Float |

class Matrix m where

Methods

withNewMatrix :: MatrixComponent c => MatrixOrder -> (Ptr c -> IO ()) -> IO (m c)

Create a new matrix of the given order (containing undefined elements) and call the action to fill it with 4x4 elements.

withMatrix :: MatrixComponent c => m c -> (MatrixOrder -> Ptr c -> IO a) -> IO a

Call the action with the given matrix. Note: The action is not allowed to modify the matrix elements!

newMatrix :: MatrixComponent c => MatrixOrder -> [c] -> IO (m c)

getMatrixComponents :: MatrixComponent c => MatrixOrder -> m c -> IO [c]

Instances

Matrix GLmatrix |

currentMatrix :: (Matrix m, MatrixComponent c) => StateVar (m c)

Deprecated: use `matrix' instead

matrix :: (Matrix m, MatrixComponent c) => Maybe MatrixMode -> StateVar (m c)

multMatrix :: (Matrix m, MatrixComponent c) => m c -> IO ()

data GLmatrix a

Instances

Matrix GLmatrix |
Eq (GLmatrix a) |
Ord (GLmatrix a) |
Show (GLmatrix a) |

loadIdentity :: IO ()

ortho :: GLdouble -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> IO ()

frustum :: GLdouble -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> IO ()

depthClamp :: StateVar Capability

activeTexture :: StateVar TextureUnit

preservingMatrix :: IO a -> IO a

Push the current matrix stack down by one, duplicating the current matrix, excute the given action, and pop the current matrix stack, replacing the current matrix with the one below it on the stack (i.e. restoring it to its previous state). The returned value is that of the given action. Note that a round-trip to the server is probably required. For a more efficient version, see `unsafePreservingMatrix`.

unsafePreservingMatrix :: IO a -> IO a

A more efficient, but potentially dangerous version of `preservingMatrix`: The given action is not allowed to throw an exception or change the current matrix mode permanently.

stackDepth :: Maybe MatrixMode -> GettableStateVar GLsizei

maxStackDepth :: MatrixMode -> GettableStateVar GLsizei

# Normal Transformation

rescaleNormal :: StateVar Capability

If `rescaleNormal` contains `Enabled`, normal vectors specified with `normal` are scaled by a scaling factor derived from the modelview matrix. `rescaleNormal` requires that the originally specified normals were of unit length, and that the modelview matrix contains only uniform scales for proper results. The initial value of `rescaleNormal` is `Disabled`.

normalize :: StateVar Capability

If `normalize` contains `Enabled`, normal vectors specified with `normal` are scaled to unit length after transformation. The initial value of `normalize` is `Disabled`.

# Generating Texture Coordinates

data Plane a

Constructors

Plane !a !a !a !a |

Instances

Eq a => Eq (Plane a) |
Ord a => Ord (Plane a) |
Show a => Show (Plane a) |
Storable a => Storable (Plane a) |

data TextureCoordName

Constructors

S |
T |
R |
Q |

Instances

Eq TextureCoordName |
Ord TextureCoordName |
Show TextureCoordName |

data TextureGenMode

Constructors

EyeLinear (Plane GLdouble) |
ObjectLinear (Plane GLdouble) |
SphereMap |
NormalMap |
ReflectionMap |

Instances

Eq TextureGenMode |
Ord TextureGenMode |
Show TextureGenMode |

textureGenMode :: TextureCoordName -> StateVar (Maybe TextureGenMode)