From 1da8a6502844525fc53cd5e2ad3c1f2711b21352 Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 31 Jan 2019 00:11:39 +0100 Subject: [PATCH] minimal window(s) --- ibis.cabal | 2 ++ shell.nix | 8 ++++---- src/Main.hs | 13 +++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ibis.cabal b/ibis.cabal index 529e891..450b4bb 100644 --- a/ibis.cabal +++ b/ibis.cabal @@ -26,6 +26,8 @@ executable ibis , poppler , sdl2 , linear + , monad-loops + , OpenGL , text hs-source-dirs: src default-language: Haskell2010 diff --git a/shell.nix b/shell.nix index 2338bff..843268c 100644 --- a/shell.nix +++ b/shell.nix @@ -26,8 +26,8 @@ let inherit (nixpkgs) pkgs; - f = { mkDerivation, base, linear, optparse-applicative, poppler, stdenv, - text + f = { mkDerivation, base, linear, monad-loops, optparse-applicative, OpenGL, + poppler, stdenv, text }: mkDerivation { pname = "ibis"; @@ -35,8 +35,8 @@ let src = ./.; isLibrary = false; isExecutable = true; - executableHaskellDepends = [ base linear sdl2 optparse-applicative - poppler text ]; + executableHaskellDepends = [ base linear sdl2 monad-loops + OpenGL optparse-applicative poppler text ]; description = "A pdf presenter"; license = stdenv.lib.licenses.gpl3; }; diff --git a/src/Main.hs b/src/Main.hs index 3e0e7d7..429d5b2 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -4,11 +4,16 @@ import qualified SDL import qualified SDL.Raw.Video as SDL (glSetAttribute) import qualified SDL.Raw.Enum as SDL +import qualified Graphics.Rendering.OpenGL as GL (clear, flush, ClearBuffer(..)) + import Linear import Options.Applicative import Control.Monad +import Control.Monad.Loops + +import Control.Concurrent.MVar import qualified Data.Text as T @@ -48,3 +53,11 @@ main = do void $ SDL.glSetAttribute SDL.SDL_GL_SHARE_WITH_CURRENT_CONTEXT 1 contexts <- zip (map fst wins) <$> mapM (SDL.glCreateContext . snd) wins mapM_ (SDL.showWindow . snd) wins + run <- newMVar True + whileM_ (readMVar run) (do + GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer] + GL.flush + mapM_ (SDL.glSwapWindow . snd) wins + ) + mapM_ (SDL.glDeleteContext . snd) contexts + mapM_ (SDL.destroyWindow . snd) wins