dynamic-graph-0.1.0.4: Draw and update graphs in real time with OpenGL

Safe HaskellNone
LanguageHaskell2010

Graphics.DynamicGraph.TextureLine

Description

Draw and update line graphs with OpenGL.

Based on: https://en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_02

Example usage:

import Control.Monad
import Control.Monad.Trans.Either
import Control.Concurrent
import Pipes
import qualified Pipes.Prelude as P
import System.Random
import Graphics.Rendering.OpenGL

import Graphics.DynamicGraph.TextureLine

randomVect :: Producer [GLfloat] IO ()
randomVect =  P.repeatM $ do
    res <- replicateM 1000 randomIO
    threadDelay 10000
    return res

main = eitherT putStrLn return $ do
    setupGLFW
    lineGraph <- textureLineWindow 1024 480 1000 1024 

    lift $ runEffect $ randomVect >-> lineGraph

Synopsis

Documentation

textureLineWindow :: forall a. IsPixelData a => Int -> Int -> Int -> Int -> EitherT String IO (Consumer a IO ()) Source

(textureLineWindow windowWidth windowHeight samples xResolution) creates a window of width windowWidth and height windowHeight for displaying a line graph.

A function is returned for dynamically updating the line graph. It takes an instance of IsPixelData of length samples as the y values and draws a line graph with xResolution vertices.

renderTextureLine :: IsPixelData a => Int -> Int -> IO (a -> IO ()) Source

(renderTextureLine samples xResolution) returns a function that renders a line graph into the current OpenGL context. The function takes an instance of IsPixelData of length samples and draws a line graph with xResolution vertices.

All OpenGL based initialization of the rendering function (loading of shaders, etc) is performed before the function is returned.

setupGLFW :: EitherT String IO () Source

Utility function to setup GLFW for graph drawing