initializeApp :: String -> UserApp a -> IO (AppVar a)
initializeApp title uApp = do
    mWin <- initGLFW title
    case mWin of
        Nothing  -> do putStrLn "Could not create a window."
                       exitFailure

        Just win -> do makeContextCurrent mWin
                       time <- getTime
                       mvar <- newEmptyMVar

                       -- When True this gives us a moment
                       -- to attach an OGL profiler.
                       when False $ do
                           putStrLn "Waiting for any button press..."
                           void getChar
                           return ()

                       -- Register our resize window function.
                       setWindowSizeCallback win $ Just (\win' w h -> do
                           app <- readMVar mvar
                           let input     = flip execState (_userInput app) $ do
                                               inputEvents %= (WindowSizeChangedTo (w,h):)
                                               inputState.windowSize .= (w,h)
                               userData' = (app^.userApp.onInput) input (app^.userApp.userData)
                           renderUserApp win' $ app^.userApp & userData .~ userData')

                       let clock' = tickClock time emptyClock
                           app    = App { _userApp    = uApp
                                        , _userInput  = emptyInput
                                        , _clock      = clock'
                                        , _window     = Just win
                                        }
                       putMVar mvar app
                       return mvar
initializeApp :: String -> UserApp a -> IO (AppVar a)
initializeApp title uApp = do
    mWin <- initGLFW title
    case mWin of
        Nothing  -> do putStrLn "Could not create a window."
                       exitFailure

        Just win -> do makeContextCurrent mWin
                       time <- getTime
                       mvar <- newEmptyMVar

                       -- When True this gives us a moment
                       -- to attach an OGL profiler.
                       when False $ do
                           putStrLn "Waiting for any button press..."
                           void getChar
                           return ()

                       -- Register our resize window function.
                       setWindowSizeCallback win $ Just (\win' w h -> do
                           app <- readMVar mvar
                           let input     = flip execState (_userInput app) $ do
                                               inputEvents %= (WindowSizeChangedTo (w,h):)
                                               inputState.windowSize .= (w,h)
                               userData' = (app^.userApp.onInput) input (app^.userApp.userData)
                           renderUserApp win' $ app^.userApp & userData .~ userData')

                       let clock' = tickClock time emptyClock
                           app    = App { _userApp    = uApp
                                        , _userInput  = emptyInput
                                        , _clock      = clock'
                                        , _window     = Just win
                                        }
                       putMVar mvar app
                       return mvar
initializeApp title uApp = do
    mWin <- initGLFW title
    case mWin of
        Nothing  -> do putStrLn "Could not create a window."
                       exitFailure

        Just win -> do makeContextCurrent mWin
                       time <- getTime
                       mvar <- newEmptyMVar

                       -- When True this gives us a moment
                       -- to attach an OGL profiler.
                       when False $ do
                           putStrLn "Waiting for any button press..."
                           void getChar
                           return ()

                       -- Register our resize window function.
                       setWindowSizeCallback win $ Just (\win' w h -> do
                           app <- readMVar mvar
                           let input     = flip execState (_userInput app) $ do
                                               inputEvents %= (WindowSizeChangedTo (w,h):)
                                               inputState.windowSize .= (w,h)
                               userData' = (app^.userApp.onInput) input (app^.userApp.userData)
                           renderUserApp win' $ app^.userApp & userData .~ userData')

                       let clock' = tickClock time emptyClock
                           app    = App { _userApp    = uApp
                                        , _userInput  = emptyInput
                                        , _clock      = clock'
                                        , _window     = Just win
                                        }
                       putMVar mvar app
                       return mvar