gloss-rendering-1.9.2.1: Gloss picture data types and rendering functions.

Safe Haskell | None
Language | Haskell2010

Graphics.Gloss.Rendering

Contents

- Picture data type
- Colors
- Bitmaps
- Rendering

Synopsis

- data Picture
  - = Blank
  - | Polygon Path
  - | Line Path
  - | Circle Float
  - | ThickCircle Float Float
  - | Arc Float Float Float
  - | ThickArc Float Float Float Float
  - | Text String
  - | Bitmap Int Int BitmapData Bool
  - | Color Color Picture
  - | Translate Float Float Picture
  - | Rotate Float Picture
  - | Scale Float Float Picture
  - | Pictures [Picture]
- type Point = (Float, Float)
- type Vector = Point
- type Path = [Point]
- data Color
- makeColor :: Float -> Float -> Float -> Float -> Color
- makeColorI :: Int -> Int -> Int -> Int -> Color
- makeRawColor :: Float -> Float -> Float -> Float -> Color
- makeRawColorI :: Int -> Int -> Int -> Int -> Color
- rgbaOfColor :: Color -> (Float, Float, Float, Float)
- clampColor :: Color -> Color
- data BitmapData
- bitmapOfForeignPtr :: Int -> Int -> ForeignPtr Word8 -> Bool -> Picture
- bitmapOfByteString :: Int -> Int -> ByteString -> Bool -> Picture
- bitmapOfBMP :: BMP -> Picture
- loadBMP :: FilePath -> IO Picture
- displayPicture :: (Int, Int) -> Color -> State -> Float -> Picture -> IO ()
- renderPicture :: State -> Float -> Picture -> IO ()
- withModelview :: (Int, Int) -> IO () -> IO ()
- withClearBuffer :: Color -> IO () -> IO ()
- initState :: IO State

# Picture data type

data Picture

A 2D picture

Constructors

Blank | A blank picture, with nothing in it.
Polygon Path | A convex polygon filled with a solid color.
Line Path | A line along an arbitrary path.
Circle Float | A circle with the given radius.
ThickCircle Float Float | A circle with the given thickness and radius. If the thickness is 0 then this is equivalent to `Circle`.
Arc Float Float Float | A circular arc drawn counter-clockwise between two angles (in degrees) at the given radius.
ThickArc Float Float Float Float | A circular arc drawn counter-clockwise between two angles (in degrees), with the given radius and thickness. If the thickness is 0 then this is equivalent to `Arc`.
Text String | Some text to draw with a vector font.
Bitmap Int Int BitmapData Bool | A bitmap image with a width, height and some 32-bit RGBA bitmap data. The boolean flag controls whether Gloss should cache the data between frames for speed. If you are programatically generating the image for each frame then use `False`. If you have loaded it from a file then use `True`.
Color Color Picture | A picture drawn with this color.
Translate Float Float Picture | A picture translated by the given x and y coordinates.
Rotate Float Picture | A picture rotated clockwise by the given angle (in degrees).
Scale Float Float Picture | A picture scaled by the given x and y factors.
Pictures [Picture] | A picture consisting of several others.

Instances

Eq Picture |
Data Picture |
Show Picture |
Monoid Picture |
Typeable * Picture |

type Point = (Float, Float)

A point on the x-y plane.

type Vector = Point

A vector can be treated as a point, and vis-versa.

type Path = [Point]

A path through the x-y plane.

# Colors

data Color

An abstract color value. We keep the type abstract so we can be sure that the components are in the required range. To make a custom color use `makeColor`.

Instances

Eq Color |
Data Color |
Num Color |
Show Color |
Typeable * Color |

makeColor

Arguments

:: Float | Red component.
-> Float | Green component.
-> Float | Blue component.
-> Float | Alpha component.
-> Color |

Make a custom color. All components are clamped to the range [0..1].

makeColorI :: Int -> Int -> Int -> Int -> Color

Make a custom color. All components are clamped to the range [0..255].

makeRawColor :: Float -> Float -> Float -> Float -> Color

Make a custom color.

Using this function over `makeColor` avoids clamping the components, which saves time. However, if the components are out of range then this will result in integer overflow at rendering time, and the actual picture you get will be implementation dependent.

You'll only need to use this function when using the `gloss-raster` package that builds a new color for every pixel. If you're just working with the Picture data type then it there is no need for raw colors.

makeRawColorI :: Int -> Int -> Int -> Int -> Color

Make a custom color, taking pre-clamped components.

rgbaOfColor :: Color -> (Float, Float, Float, Float)

Take the RGBA components of a color.

clampColor :: Color -> Color

Clamp components of a raw color into the required range.

# Bitmaps

data BitmapData

Abstract 32-bit RGBA bitmap data.

Instances

Eq BitmapData |
Data BitmapData |
Show BitmapData |
Typeable * BitmapData |

bitmapOfForeignPtr :: Int -> Int -> ForeignPtr Word8 -> Bool -> Picture

O(1). Use a `ForeignPtr` of RGBA data as a bitmap with the given width and height.

bitmapOfByteString :: Int -> Int -> ByteString -> Bool -> Picture

O(size). Copy a `ByteString` of RGBA data into a bitmap with the given width and height.

The boolean flag controls whether Gloss should cache the data between frames for speed. If you are programatically generating the image for each frame then use `False`. If you have loaded it from a file then use `True`.

bitmapOfBMP :: BMP -> Picture

O(size). Copy a `BMP` file into a bitmap.

loadBMP :: FilePath -> IO Picture

Load an uncompressed 24 or 32bit RGBA BMP file as a bitmap.

# Rendering

displayPicture

Arguments

:: (Int, Int) | Window width and height.
-> Color | Color to clear the window with.
-> State | Current rendering state.
-> Float | View port scale, which controls the level of detail. Use 1.0 to start with.
-> Picture | Picture to draw.
-> IO () |

Set up the OpenGL context, clear the buffer, and render the given picture into it.

This is the same as `renderPicture` composed with `withModelview` and `withClearBuffer`. If you want to manage your own OpenGL context then you can just call `renderPicture`.

Using this function assumes that you've already opened a window and set that to the active context. If you don't want to do your own window management then use the `gloss` package instead.

renderPicture

Arguments

:: State | Current rendering state.
-> Float | View port scale, which controls the level of detail. Use 1.0 to start with.
-> Picture | Picture to render.
-> IO () |

Render a picture into the current OpenGL context.

Assumes that the OpenGL matrix mode is set to `Modelview`

withModelview

Arguments

:: (Int, Int) | Width and height of window.
-> IO () | Action to perform.
-> IO () |

Set up the OpenGL rendering context for orthographic projection and run an action to draw the model.

withClearBuffer

Arguments

:: Color | Background color
-> IO () | Action to perform
-> IO () |

Clear the OpenGL buffer with the given background color and run an action to draw the model.

initState :: IO State

A mutable render state holds references to the textures currently loaded into the OpenGL context. To ensure that textures are cached in GPU memory, pass the same `State` each time you call `displayPicture` or `renderPicture`.