Code Monkey home page Code Monkey logo

h-raylib's Introduction

h-raylib's People

Contributors

anut-py avatar arden144 avatar capital-ex avatar futu2 avatar glocq avatar lonelyfloat avatar magicrb avatar ramirez7 avatar soupstraw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

h-raylib's Issues

drawTextEx not working properly

I tried drawing text using drawTextEx and it mostly won't work, and sometimes it shows for a frame or 2 then nothing again. Tried using this code with two different fonts I know are working from another project:

mainFontPath :: String
mainFontPath = "/path/to/font"

main :: IO ()
main = do
  initWindow screenWidth screenHeight "Font Test"
  setTargetFPS 75

  mainFont <- loadFont mainFontPath
  gameLoop mainFont

gameLoop :: Font -> IO ()
gameLoop mainFont = do
  beginDrawing
  clearBackground rayWhite

  drawTextEx mainFont "Testing drawTextEx" (Vector2 640.0 12.0) 20.0 1.0 black

  endDrawing

  shouldClose <- windowShouldClose
  unless shouldClose $ gameLoop mainFont

And the logs show the font loaded successfully

Add Lens instances for Raylib types

The types in Raylib.Types feature many nested records. It would be nice to be able to access them using lenses. If there is interest, I can try to do it myself.

Considering add some helper `bracket` functions to Util in order to avoid begin* and end* syntax

import Control.Monad.Catch (MonadMask, bracket_)
drawing :: (MonadIO m, MonadMask m) => m () -> m ()
drawing = bracket_ (liftIO beginDrawing) (liftIO endDrawing)

mode3D :: (MonadIO m, MonadMask m) => RL.Camera3D -> m () -> m ()
mode3D c = bracket_ (liftIO $ beginMode3D c) (liftIO endMode3D)

mode2D :: (MonadIO m, MonadMask m) => RL.Camera2D -> m () -> m ()
mode2D c = bracket_ (liftIO $ beginMode2D c) (liftIO endMode2D)

`5.1.1.0` release checklist

  • Documentation
    • Update README.md
    • Update DOCUMENTATION.md
    • Update CHANGELOG.md
    • Update CONTRIBUTING.md
    • Check Haddock documentation for completeness
  • Submodules
    • Update raylib
    • Update raygui
    • New submodules
      • Add to cabal config
      • Add to nix config
      • Add to devtools.js
      • Create example
    • New structures
      • Add to Raylib.Util.Lenses
  • General
    • Increment cabal version
    • Run devtools.js -u
    • New examples
      • Add to cabal config
      • Add to run-all-examples.sh
    • Prerelease
      • Check if GitHub actions is successful
      • Run devtools.js -p
  • Create release tag

Module ‘Raylib.Util’ does not export ‘raylibApplication’

Basically title.

My ghc version is ghc 9.2.8.

Other functions from Raylib.Util are there.

Template Haskell is enabled.

The cabal file is this:

common warnings
    ghc-options: -Wall

executable pokiclone
    -- Import common warning flags.
    import:           warnings

    -- .hs or .lhs file containing the Main module.
    main-is:          Main.hs

    -- Modules included in this executable, other than Main.
    -- other-modules:

    -- LANGUAGE extensions used by modules in this package.
    other-extensions: MultiWayIf

    -- Other library packages from which modules are imported.
    build-depends:    base ^>=4.16.4.0
                    , h-raylib
                    , lens

    -- Directories containing source files.
    hs-source-dirs:   app

    -- Base language which the package is written in.
    default-language: GHC2021

stb_vorbis.c is missing from sdist

After unpacking the hackage sdist for 4.5.1.0 raylib/src/external contains only:

cgltf.h    dr_mp3.h      glad.h     jar_xm.h     msf_gif.h     qoi.h        sinfl.h             stb_image_write.h  stb_truetype.h
dirent.h   dr_wav.h      glfw       m3d.h        par_shapes.h  rl_gputex.h  stb_image.h         stb_perlin.h       tinyobj_loader_c.h
dr_flac.h  glad_gles2.h  jar_mod.h  miniaudio.h  qoa.h         sdefl.h      stb_image_resize.h  stb_rect_pack.h    vox_loader.h

Does not seem to work under Windows

Hello,

When I run the following program with cabal run under Windows nothing happens.

hello-raylib> cabal run
hello-raylib>

hello-raylib.cabal

cabal-version:      3.4
name:               hello-raylib
version:            0.1.0.0

common warnings
    ghc-options: -Wall

executable hello-raylib
    import:             warnings
    main-is:            Main.hs
    build-depends:      base ^>=4.16.0.0
                      , h-raylib
    hs-source-dirs:     app
    default-language:   Haskell2010

app/Main.hs

module Main where

import Control.Monad (unless)
import qualified Raylib.Core as Raylib

main :: IO ()
main = do
  w <- Raylib.initWindow 480 320 "Hello, Raylib!"
  let loop = do
        shouldClose <- Raylib.windowShouldClose
        unless shouldClose loop
  loop
  Raylib.closeWindow w

I tried updating my NVidia drivers. No change.
I installed raylib and successfully ran one of their examples in C so I suspect there's something wrong with this package or something I've done or missed in the code posted above.

Thank you and kind regards
Björn

More abstraction for WindowResources passed to load/unload* functions?

When using loadModel or unloadModel, WindowResources has to be passed as final parameter. Because of that, pasting code around could be annoying, for some codes using win while the other using w or wr.

Here's solution using monad reader

inWindow :: (MonadIO m, MonadMask m) => Int -> Int -> String -> Int -> ReaderT WindowResources m b -> m b
inWindow w h title fps =  bracket (liftIO $ initWindow w h title <* setTargetFPS fps) (liftIO . closeWindow) . runReaderT

loadModelFile :: (MonadIO m, MonadMask m, MonadReader WindowResources m) => FilePath -> m Model
loadModelFile file = ask >>= liftIO . loadModel file 

and also some bracket functions for unload

withModel :: (MonadIO m, MonadMask m, MonadReader WindowResources m) => FilePath -> (RL.Model -> m b) -> m b
withModel file = bracket (ask >>= liftIO . loadModel file) (\m -> ask >>= liftIO . unloadModel m)

withModels :: (MonadIO m, MonadMask m, MonadReader WindowResources m) => [FilePath] -> ([RL.Model] -> m b) -> m b
withModels [] f = f []
withModels (file:files) f = withModel file $ \m -> withModels files $ \ms -> f (m:ms)

a side effect of using monad reader is that the abstraction require using lift for simplest program

mainGame :: IO ()
mainGame =
  inWindow 1920 1080 "MyApp" 90 $ do
    lift $ -- init something ...
    withModels ["./res/ship1.obj", "./res/ship2.obj"] $ \[m1, m2] -> lift $ do
       -- main loop with some real drawing code ...

defaultWindowResources is undocumented

Hello and thank you for creating these bindings!

I wanted to report that the defaultWindowResources function defined here isn't visible in the documentation. I had to click on Source for WindowResources and that's how I found it.

On a related note, I'm trying to get loadTexture to work which requires WindowResources. Would you happen to have an example of using loadTexture? Thanks!

isKeyDown and isKeyUp always True

I used the window example as base and started playing around with inputs, just printing text to see if they work. isKeyPressed and isKeyReleased are working fine, but isKeyDown and isKeyUp just return True. Heres the code i used:

gameLoop :: IO ()
gameLoop = do
  wDown <- isKeyDown key'w
  wUp <- isKeyUp key'w
  if wDown then print "W down" else print "W not down"
  if wUp then print "W up" else print "W not up"

  beginDrawing

  clearBackground rayWhite
  drawText "Basic raylib window" 30 40 18 lightGray


  endDrawing

  shouldClose <- windowShouldClose
  unless shouldClose gameLoop

The output prints both "W down" and "W up" no matter the input

Windows - GCC missing libs error

When I've included this package into Stack build project, I've got error : * Missing (or bad) C libraries: gcc_eh

Can we please include into documentation these steps to resolve it?

This errors occurs when haskell stack can't find gcc libs. To fix this follow these steps:

  1. Run stack exec -- pacman -Syu, stack exec -- pacman -S gcc
  2. Then "stack exec -- gcc -print-libgcc-file-name"
  3. Copy the path without libgcc.a and paste it inside extra-lib-dirs stack.yaml

Remove usage of unsafeIO from getRayCollision functions

Hello, and first of all thank you for these bindings - I've been enjoying using them!

However, I think I've found a bug. I am currently working on a project and for some reason I'm getting wildly different behaviours when getRayCollisionXXX is involved. Here's a snippet (which you can find here)

checkBoard :: PlayerAimComponent -> (BoardComponent, PositionComponent) -> System World BoardComponent
checkBoard (Aim ray) (_, p) = do
  hit <- liftIO $ isHit ray p
  if hit then
    pure $ Board Filled Filled Filled Filled Filled Filled Filled Filled Filled
  else
    pure $ Board Empty Empty Empty Empty Empty Empty Empty Empty Empty


isHit :: RL.Ray -> PositionComponent -> IO Bool
isHit ray (Position p) = do
  let hitInfo = RL.getRayCollisionBox ray $ RL.BoundingBox from to
  -- liftIO $ print "Hello" -- <- uncomment to make this work?
  pure $ RL.raycollision'hit hitInfo > 0
  where from = addVectors p $ Vector3 (-1.5) (-1.5) (-0.05)
        to = addVectors p $ Vector3 1.5 1.5 0.05

So this function is WiP, but it tries to detect if the ray shooting from the camera is hitting one of the game boards, and if it does I'm just flagging every cell so that we can see it. Here's the weird thing though: This function only seems to work if you print something inside it. I have no idea what this signifies, but after digging down into h-raylib's source code I've found that getRayCollisionBox along with lots of other physics functions are unsafe IO functions.

I have no experience in FFI or making bindings to C, but while this fact remains true I can't help but wonder if it's the cause. All the other raylib functions I've used I've had to do liftIO to access them, and they've all worked really well with no issues this far.

Would it be difficult to make your collision functions also operate within IO? At least then if this is still an issue we can conclude its not the bindings?

Alternatively, if you have any suggestions of what the issue could be, please let me know as I'm blocked by this.

Thanks again for the great library!

Clues

Here's some debugging work I've done:

Not printing anything

Here's what it looks like if we don't print anything. The boards light up if hit is true, which is true when raycollision'hit hitInfo > 0. When we don't print anything, all of them are permanently lit even if we don't look at any of them.

image

Print "hello" or other random things

Uncommenting the comment so that we print hello in this function actually fixes it, all three boards are unlit until we look at them:

image

image

Printing raycollision'hit hitInfo

This one is an exception - if I print this value, I get the following:

  • One board lights up - its hitInfo hit value is 6749696 - a memory address maybe?
  • The second board lights up if I hit it, its hit value is 1 if I look at it, and 0 otherwise
  • The last board also lights up if I look at it, value is 1 if looked at and 0 otherwise
  • Finally, if I look at the first board with the weird number, it's value increases by 1 to 6749697

image

image

image

Invoking getFontDefault twice will cause a core dump

getFontDefault seems to cause Raylib's text utilities to suddenly break measureText. Additionally, I've found that invoking getFontDefault twice will crash Haskell citing a double free error or memory corruption as a cause. I'm not to sure what the cause is, but my guess is the original font is somehow getting destroyed as it is passed to Haskell.

Minimum repoduction:

main :: IO ()
main = do
  _ <- initWindow 1 1 ""
  defaultFont <- getFontDefault
  defaultFont <- getFontDefault
  return ()

Web build support

Set up h-raylib to work with emscripten and support building to WebAssembly.

`clamp` function in Raylib.Util.Math can be more haskellish

Haskell-styled function should be good at combination.

e.g. clamp

clamp has to be used in this way

clamp Value_to_clamp Lower_bound Upper_bound

more haskellish args ord should be

clamp Lower_bound Upper_bound Value_to_clamp 

if change the order of args the endo-function will change
from (\x -> clamp x (-40) 40)
to clamp (-40) 40
which makes this function combine easily with other Float -> Float function

Same thing goes:

cabal file does not specify dependency on X11/extensions/Xge.h

I saw that the Xext dependency was removed recently 5a09c28

But when building 4.5.0.7 with macaroni.nix, it fails due to that dependency not being declared:

Configuring library for h-raylib-4.5.0.7..
building
Preprocessing library for h-raylib-4.5.0.7..
Building library for h-raylib-4.5.0.7..
[1 of 4] Compiling Raylib.Types     ( src/Raylib/Types.hs, dist/build/Raylib/Types.o, dist/build/Raylib/Types.dyn_o )
[2 of 4] Compiling Raylib.Colors    ( src/Raylib/Colors.hs, dist/build/Raylib/Colors.o, dist/build/Raylib/Colors.dyn_o )
[3 of 4] Compiling Raylib.Util      ( src/Raylib/Util.hs, dist/build/Raylib/Util.o, dist/build/Raylib/Util.dyn_o )
[4 of 4] Compiling Raylib           ( src/Raylib.hs, dist/build/Raylib.o, dist/build/Raylib.dyn_o )
In file included from raylib/src/external/glfw/src/x11_platform.h:48,
                 from raylib/src/external/glfw/src/platform.h:62,
                 from raylib/src/external/glfw/src/internal.h:331,
                 from raylib/src/external/glfw/src/init.c:30,

                 from raylib/src/rglfw.c:61:0: error: 

/nix/store/r0pzhgq3l9mfhc67gxc7aarv15pjshql-libXi-1.8-dev/include/X11/extensions/XInput2.h:32:10: error:
     fatal error: X11/extensions/Xge.h: No such file or directory
       32 | #include <X11/extensions/Xge.h>
          |          ^~~~~~~~~~~~~~~~~~~~~~
   |
32 | #include <X11/extensions/Xge.h>
   |          ^
compilation terminated.
`cc' failed in phase `C Compiler'. (Exit code: 1)
error: builder for '/nix/store/w7yzb3cdb5lvkr57llyvy2i28ay8z1j0-h-raylib-lib-h-raylib-4.5.0.7.drv' failed with exit code 1;
       last 10 log lines:
       >
       > /nix/store/r0pzhgq3l9mfhc67gxc7aarv15pjshql-libXi-1.8-dev/include/X11/extensions/XInput2.h:32:10: error:
       >      fatal error: X11/extensions/Xge.h: No such file or directory
       >        32 | #include <X11/extensions/Xge.h>
       >           |          ^~~~~~~~~~~~~~~~~~~~~~
       >    |
       > 32 | #include <X11/extensions/Xge.h>
       >    |          ^
       > compilation terminated.
       > `cc' failed in phase `C Compiler'. (Exit code: 1)
       For full logs, run 'nix log /nix/store/w7yzb3cdb5lvkr57llyvy2i28ay8z1j0-h-raylib-lib-h-raylib-4.5.0.7.drv'.
error: 1 dependencies of derivation '/nix/store/q9mawhklkbnpi65h7r88va5672fdwgbd-h-raylib-minimal-exe-h-raylib-minimal-0.1.0.0.drv' failed to build
make: *** [Makefile:2: build] Error 1

For now, 4.5.0.3 seems to build fine.

Drag and drop does not work as expected

Trying to drag and drop files fails. Particularly using the function loadDroppedFiles will seg fault while trying to free an invalid pointer to the file path:

free(): invalid pointer
Aborted (core dumped)

Or it will try to double free:

free(): double free detected in tcache 2
Aborted (core dumped)

It does that on the next frame or the frame after. I'm not sure if this is user error, because I don't know what I should or should not free manually and how. This is a basic version of what I tried:

mainloop :: AppState -> IO AppState
mainloop appState = do
  fileIsDropped <- isFileDropped
  when fileIsDropped $
    print =<< loadDroppedFiles
  endDrawing
  return appState''

main = whileWindowOpen_ mainloop =<< initApp

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.