Giter Site home page Giter Site logo

sdl2-gfx's People

Contributors

sbidin avatar skykanin avatar spikeyarmaku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sdl2-gfx's Issues

Not building on Windows

Just like withe the other sdl2 libraries the following code has to be added to the .cabal file or it won't install on Windows.

if os(windows) 
    cpp-options: -D_SDL_main_h

Make a release?

Nice to meet you!

Would you please consider releasing the current source to Hackage? #2 has already been fixed in the master but not in the latest release 0.2.

How do you rotate a primitive?

Hello! I'm trying to learn sdl-gfx via these bindings and I'm having difficulty combining primitives with rotozoom.

In the C library, the primitives take an SDL_Surface*, but here, they take a Renderer. How then are you meant to, say, rotate a polygon? Thanks.

lts-16.27: Couldn't match type ‘SDL.V4 GHC.Word.Word8’ with ‘V4 GHC.Word.Word8’

How to make sdl2-gfx-0.2 from Stackage lts-16.27 work?

I am getting this error when I try to build my project:

$ stack build
sdl2-gfx> configure
sdl2-gfx> Configuring sdl2-gfx-0.2...
sdl2-gfx> build
sdl2-gfx> Preprocessing library for sdl2-gfx-0.2..
sdl2-gfx> Building library for sdl2-gfx-0.2..
sdl2-gfx> [ 1 of 10] Compiling SDL.ExceptionHelper
sdl2-gfx> [ 2 of 10] Compiling SDL.Raw.Helper
sdl2-gfx> [ 3 of 10] Compiling SDL.Raw.Framerate
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Framerate.hsc:41:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern FPS_DEFAULT :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 41 | pattern FPS_DEFAULT     = (#const FPS_DEFAULT)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Framerate.hsc:42:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern FPS_LOWER_LIMIT :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 42 | pattern FPS_LOWER_LIMIT = (#const FPS_LOWER_LIMIT)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Framerate.hsc:43:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern FPS_UPPER_LIMIT :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 43 | pattern FPS_UPPER_LIMIT = (#const FPS_UPPER_LIMIT)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx> [ 4 of 10] Compiling SDL.Framerate
sdl2-gfx> [ 5 of 10] Compiling SDL.Raw.ImageFilter
sdl2-gfx> [ 6 of 10] Compiling SDL.ImageFilter
sdl2-gfx> [ 7 of 10] Compiling SDL.Raw.Primitive
sdl2-gfx> [ 8 of 10] Compiling SDL.Primitive
sdl2-gfx> [ 9 of 10] Compiling SDL.Raw.Rotozoom
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Rotozoom.hsc:39:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern SMOOTHING_OFF :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 39 | pattern SMOOTHING_OFF = (#const SMOOTHING_OFF)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Rotozoom.hsc:40:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern SMOOTHING_ON :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 40 | pattern SMOOTHING_ON  = (#const SMOOTHING_ON)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx> [10 of 10] Compiling SDL.Rotozoom
sdl2-gfx> Preprocessing executable 'sdl2-gfx-example' for sdl2-gfx-0.2..
sdl2-gfx> Building executable 'sdl2-gfx-example' for sdl2-gfx-0.2..
sdl2-gfx> [1 of 1] Compiling Main
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/example/Example.hs:56:7: error:
sdl2-gfx>     • Couldn't match type ‘SDL.V4 GHC.Word.Word8’
sdl2-gfx>                      with ‘V4 GHC.Word.Word8’
sdl2-gfx>       NB: ‘V4’ is defined in ‘Linear.V4’ in package ‘linear-1.21.3’
sdl2-gfx>           ‘SDL.V4’
sdl2-gfx>             is defined in ‘SDL.Internal.Vect’ in package ‘sdl2-2.5.3.0’
sdl2-gfx>         arising from a functional dependency between:
sdl2-gfx>           constraint ‘StateVar-1.2:Data.StateVar.HasSetter
sdl2-gfx>                         (StateVar-1.2:Data.StateVar.StateVar (SDL.V4 GHC.Word.Word8))
sdl2-gfx>                         SDL.Primitive.Color’
sdl2-gfx>             arising from a use of ‘$=’
sdl2-gfx>           instance ‘StateVar-1.2:Data.StateVar.HasSetter
sdl2-gfx>                       (StateVar-1.2:Data.StateVar.StateVar a) a’
sdl2-gfx>             at <no location info>
sdl2-gfx>     • In a stmt of a 'do' block: SDL.rendererDrawColor r $= black
sdl2-gfx>       In the expression:
sdl2-gfx>         do frames <- fromIntegral `fmap` SDL.Framerate.count fpsm
sdl2-gfx>            SDL.rendererDrawColor r $= black
sdl2-gfx>            SDL.clear r
sdl2-gfx>            SDL.Primitive.pixel r (V2 (100 + frames) 100) green
sdl2-gfx>            ....
sdl2-gfx>       In an equation for ‘loop'’:
sdl2-gfx>           loop'
sdl2-gfx>             = do frames <- fromIntegral `fmap` SDL.Framerate.count fpsm
sdl2-gfx>                  SDL.rendererDrawColor r $= black
sdl2-gfx>                  SDL.clear r
sdl2-gfx>                  ....
sdl2-gfx>    |
sdl2-gfx> 56 |       SDL.rendererDrawColor r $= black
sdl2-gfx>    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Progress 1/2

stack.yaml

resolver: lts-16.27

flags:
    sdl2:
        no-linear: true

package.yaml (part)

dependencies:
    - sdl2
    - sdl2-gfx

Don't use TH for writing bindings?

There is a Helper.hs module that I feel is obfuscating what could be straightforward/simple bindings:

-- | Given a name @fname@, a name of a C function @cname@ and the desired
-- Haskell type @ftype@, this function generates:
--
-- * A foreign import of @cname@, named as @fname'@.
-- * An always-inline MonadIO version of @fname'@, named @fname@.
liftF :: String -> String -> Q Type -> Q [Dec]
liftF fname cname ftype = do
  let f' = mkName $ fname ++ "'" -- Direct binding.
  let f  = mkName fname          -- Lifted.
  t' <- ftype                    -- Type of direct binding.

  -- The generated function accepts n arguments.
  args <- replicateM (countArgs t') $ newName "x"

  -- If the function has no arguments, then we just liftIO it directly.
  -- However, this fails to typecheck without an explicit type signature.
  -- Therefore, we include one. TODO: Can we get rid of this?
  sigd <- case args of
            [] -> ((:[]) . SigD f) `fmap` liftType t'
            _  -> return []

  return $ concat
    [
      [ ForeignD $ ImportF CCall Safe cname f' t'
      , PragmaD $ InlineP f Inline FunLike AllPhases
      ]
    , sigd
    , [ FunD f
        [ Clause
            (map VarP args)
            (NormalB $ 'liftIO `applyTo` [f' `applyTo` map VarE args])
            []
        ]
      ]
    ]

-- | How many arguments does a function of a given type take?
countArgs :: Type -> Int
countArgs = count 0
  where
    count !n = \case
      (AppT (AppT ArrowT _) t) -> count (n+1) t
      (ForallT _ _ t) -> count n t
      (SigT t _)      -> count n t
      _               -> n

-- | An expression where f is applied to n arguments.
applyTo :: Name -> [Exp] -> Exp
applyTo f [] = VarE f
applyTo f es = loop (tail es) . AppE (VarE f) $ head es
  where
    loop as e = foldl AppE e as

-- | Fuzzily speaking, converts a given IO type into a MonadIO m one.
liftType :: Type -> Q Type
liftType = \case
  AppT _ t -> do
    m <- newName "m"
    return $
      ForallT
        [PlainTV m]
        [AppT (ConT ''MonadIO) $ VarT m]
        (AppT (VarT m) t)
  t -> return t

I suggest each function just be written by hand, and all this TH deleted. I'm happy to provide a patch if you agree!

sdl2-gfx build failure on Stackage nightly

> /tmp/stackage-build13$ stack unpack sdl2-gfx-0.2
Unpacked sdl2-gfx-0.2 to /tmp/stackage-build13/sdl2-gfx-0.2/
> /tmp/stackage-build13/sdl2-gfx-0.2$ ghc -clear-package-db -global-package-db -package-db=/var/stackage/work/builds/nightly/pkgdb Setup
[1 of 1] Compiling Main             ( Setup.hs, Setup.o )
Linking Setup ...
> /tmp/stackage-build13/sdl2-gfx-0.2$ ./Setup configure --package-db=clear --package-db=global --package-db=/var/stackage/work/builds/nightly/pkgdb --libdir=/var/stackage/work/builds/nightly/lib --bindir=/var/stackage/work/builds/nightly/bin --datadir=/var/stackage/work/builds/nightly/share --libexecdir=/var/stackage/work/builds/nightly/libexec --sysconfdir=/var/stackage/work/builds/nightly/etc --docdir=/var/stackage/work/builds/nightly/doc/sdl2-gfx-0.2 --htmldir=/var/stackage/work/builds/nightly/doc/sdl2-gfx-0.2 --haddockdir=/var/stackage/work/builds/nightly/doc/sdl2-gfx-0.2 --flags=
Configuring sdl2-gfx-0.2...
Setup: The pkg-config package 'SDL2_gfx' version >=1.0.1 is required but it
could not be found.

lts-16.27: "Couldn't match type ‘SDL.V4 GHC.Word.Word8’ with ‘V4 GHC.Word.Word8’

How do I get sdl2-gfx-0.2 work on macOS 10.15.7 with Stackage lts-16.27?

I am getting this error when try to build my project:

$ stack build
sdl2-gfx> configure
sdl2-gfx> Configuring sdl2-gfx-0.2...
sdl2-gfx> build
sdl2-gfx> Preprocessing library for sdl2-gfx-0.2..
sdl2-gfx> Building library for sdl2-gfx-0.2..
sdl2-gfx> [ 1 of 10] Compiling SDL.ExceptionHelper
sdl2-gfx> [ 2 of 10] Compiling SDL.Raw.Helper
sdl2-gfx> [ 3 of 10] Compiling SDL.Raw.Framerate
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Framerate.hsc:41:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern FPS_DEFAULT :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 41 | pattern FPS_DEFAULT     = (#const FPS_DEFAULT)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Framerate.hsc:42:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern FPS_LOWER_LIMIT :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 42 | pattern FPS_LOWER_LIMIT = (#const FPS_LOWER_LIMIT)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Framerate.hsc:43:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern FPS_UPPER_LIMIT :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 43 | pattern FPS_UPPER_LIMIT = (#const FPS_UPPER_LIMIT)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx> [ 4 of 10] Compiling SDL.Framerate
sdl2-gfx> [ 5 of 10] Compiling SDL.Raw.ImageFilter
sdl2-gfx> [ 6 of 10] Compiling SDL.ImageFilter
sdl2-gfx> [ 7 of 10] Compiling SDL.Raw.Primitive
sdl2-gfx> [ 8 of 10] Compiling SDL.Primitive
sdl2-gfx> [ 9 of 10] Compiling SDL.Raw.Rotozoom
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Rotozoom.hsc:39:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern SMOOTHING_OFF :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 39 | pattern SMOOTHING_OFF = (#const SMOOTHING_OFF)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/src/SDL/Raw/Rotozoom.hsc:40:1: warning: [-Wmissing-pattern-synonym-signatures]
sdl2-gfx>     Pattern synonym with no type signature:
sdl2-gfx>       pattern SMOOTHING_ON :: forall a. (Eq a, Num a) => a
sdl2-gfx>    |
sdl2-gfx> 40 | pattern SMOOTHING_ON  = (#const SMOOTHING_ON)
sdl2-gfx>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
sdl2-gfx> [10 of 10] Compiling SDL.Rotozoom
sdl2-gfx> Preprocessing executable 'sdl2-gfx-example' for sdl2-gfx-0.2..
sdl2-gfx> Building executable 'sdl2-gfx-example' for sdl2-gfx-0.2..
sdl2-gfx> [1 of 1] Compiling Main
sdl2-gfx>   
sdl2-gfx> /private/var/folders/qk/vw0nqkz90cz52plb04b416fh0000gn/T/stack-fbaed1c2c0989e24/sdl2-gfx-0.2/example/Example.hs:56:7: error:
sdl2-gfx>     • Couldn't match type ‘SDL.V4 GHC.Word.Word8’
sdl2-gfx>                      with ‘V4 GHC.Word.Word8’
sdl2-gfx>       NB: ‘V4’ is defined in ‘Linear.V4’ in package ‘linear-1.21.3’
sdl2-gfx>           ‘SDL.V4’
sdl2-gfx>             is defined in ‘SDL.Internal.Vect’ in package ‘sdl2-2.5.3.0’
sdl2-gfx>         arising from a functional dependency between:
sdl2-gfx>           constraint ‘StateVar-1.2:Data.StateVar.HasSetter
sdl2-gfx>                         (StateVar-1.2:Data.StateVar.StateVar (SDL.V4 GHC.Word.Word8))
sdl2-gfx>                         SDL.Primitive.Color’
sdl2-gfx>             arising from a use of ‘$=’
sdl2-gfx>           instance ‘StateVar-1.2:Data.StateVar.HasSetter
sdl2-gfx>                       (StateVar-1.2:Data.StateVar.StateVar a) a’
sdl2-gfx>             at <no location info>
sdl2-gfx>     • In a stmt of a 'do' block: SDL.rendererDrawColor r $= black
sdl2-gfx>       In the expression:
sdl2-gfx>         do frames <- fromIntegral `fmap` SDL.Framerate.count fpsm
sdl2-gfx>            SDL.rendererDrawColor r $= black
sdl2-gfx>            SDL.clear r
sdl2-gfx>            SDL.Primitive.pixel r (V2 (100 + frames) 100) green
sdl2-gfx>            ....
sdl2-gfx>       In an equation for ‘loop'’:
sdl2-gfx>           loop'
sdl2-gfx>             = do frames <- fromIntegral `fmap` SDL.Framerate.count fpsm
sdl2-gfx>                  SDL.rendererDrawColor r $= black
sdl2-gfx>                  SDL.clear r
sdl2-gfx>                  ....
sdl2-gfx>    |
sdl2-gfx> 56 |       SDL.rendererDrawColor r $= black
sdl2-gfx>    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Progress 1/2

stack.yaml

resolver: lts-16.27

flags:
    sdl2:
        no-linear: true

package.yaml (part)

executables:
  game-exe:

dependencies:
    - sdl2
    - sdl2-gfx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.