diff --git a/examples/example02.hs b/examples/example02.hs index e4993e8..1fe808c 100644 --- a/examples/example02.hs +++ b/examples/example02.hs @@ -108,6 +108,7 @@ draw = do } process (nodeGraph M.! "sink") present (GeglRectangle 0 0 800 600) foreground True + render Nothing Nothing update :: Double -> Affection UserData () update dt = do diff --git a/examples/example03.hs b/examples/example03.hs index 6214f51..120b6ee 100644 --- a/examples/example03.hs +++ b/examples/example03.hs @@ -100,6 +100,7 @@ draw = do (G.GeglRectangle 0 0 800 600) foreground True + render Nothing Nothing update :: Double -> Affection UserData () update dt = do diff --git a/src/Affection.hs b/src/Affection.hs index 165ac2d..2152e59 100644 --- a/src/Affection.hs +++ b/src/Affection.hs @@ -78,19 +78,24 @@ withAffection AffectionConfig{..} = do renderer SDL.ABGR8888 SDL.TextureAccessStreaming - (SDL.windowInitialSize windowConfig) + (case canvasSize of + Just (cw, ch) -> (SDL.V2 + (CInt $ fromIntegral cw) + (CInt $ fromIntegral ch) + ) + Nothing -> + SDL.windowInitialSize windowConfig + ) -- make draw surface - surface <- SDL.createRGBSurface - (SDL.windowInitialSize windowConfig) - SDL.ABGR8888 - let (SDL.Surface ptr _) = surface - pixelFormat <- liftIO $ peek . Raw.surfaceFormat =<< peek ptr - SDL.V2 (CInt rw) (CInt rh) <- liftIO $ SDL.surfaceDimensions surface - let (w, h) = (fromIntegral rw, fromIntegral rh) - stride = fromIntegral (Raw.pixelFormatBytesPerPixel pixelFormat) * w - pixels <- SDL.surfacePixels surface - let bablFormat = B.PixelFormat B.RGBA B.CFu8 + -- pixelFormat <- liftIO $ peek . Raw.surfaceFormat =<< peek ptr + let SDL.V2 (CInt rw) (CInt rh) = windowInitialSize windowConfig + (w, h) = case canvasSize of + Just (cw, ch) -> (cw, ch) + Nothing -> (fromIntegral rw, fromIntegral rh) + -- stride = fromIntegral (Raw.pixelFormatBytesPerPixel pixelFormat) * w + bablFormat = B.PixelFormat B.RGBA B.CFu8 cpp = B.babl_components_per_pixel bablFormat + !stride = cpp * w format <- B.babl_format bablFormat initContainer <- (\x -> AffectionData { quitEvent = False @@ -100,8 +105,10 @@ withAffection AffectionConfig{..} = do -- , drawSurface = surface , drawTexture = texture , drawFormat = format - , drawPixels = pixels - , drawDimensions = (w, h) + -- , drawPixels = pixels + , drawDimensions = case canvasSize of + Just (cw, ch) -> (cw, ch) + Nothing -> (w, h) , drawStride = stride , drawCPP = cpp , drawStack = []