Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Raylib.Util
Description
Utility functions that may be useful for an h-raylib application
Synopsis
- withWindow :: (MonadIO m, MonadMask m) => Int -> Int -> String -> Int -> (WindowResources -> m b) -> m b
- drawing :: (MonadIO m, MonadMask m) => m b -> m b
- mode2D :: (MonadIO m, MonadMask m) => Camera2D -> m b -> m b
- mode3D :: (MonadIO m, MonadMask m) => Camera3D -> m b -> m b
- textureMode :: (MonadIO m, MonadMask m) => RenderTexture -> m b -> m b
- shaderMode :: (MonadIO m, MonadMask m) => Shader -> m b -> m b
- blendMode :: (MonadIO m, MonadMask m) => BlendMode -> m b -> m b
- scissorMode :: (MonadIO m, MonadMask m) => Int -> Int -> Int -> Int -> m b -> m b
- vrStereoMode :: (MonadIO m, MonadMask m) => VrStereoConfig -> m b -> m b
- raylibApplication :: Name -> Name -> Name -> Name -> DecsQ
- whileWindowOpen :: MonadIO m => (a -> m a) -> a -> m a
- whileWindowOpen_ :: MonadIO m => (a -> m a) -> a -> m ()
- whileWindowOpen0 :: MonadIO m => m () -> m ()
- data WindowResources
- class Closeable a where
- managed :: Closeable a => WindowResources -> IO a -> IO a
- cameraDirectionRay :: Camera3D -> Ray
- setMaterialShader :: Model -> Int -> Shader -> Model
- inGHCi :: Bool
- inWeb :: Bool
- class Freeable a where
Bracket functions
Arguments
:: (MonadIO m, MonadMask m) | |
=> Int | Window width |
-> Int | Window height |
-> String | Window title |
-> Int | Target FPS |
-> (WindowResources -> m b) | |
-> m b |
NOTE: Only for native targets. If your program is intended to
run on the web, use raylibApplication
instead.
textureMode :: (MonadIO m, MonadMask m) => RenderTexture -> m b -> m b Source #
vrStereoMode :: (MonadIO m, MonadMask m) => VrStereoConfig -> m b -> m b Source #
Game loop functions
Arguments
:: Name | The startup function, should be of type |
-> Name | The mainLoop function, should be of type |
-> Name | The shouldClose function, should be of type |
-> Name | The teardown function, should be of type |
-> DecsQ |
Creates a raylib application using the given program functions. Supports
both native and web targets, so it is recommended for all programs. If
your program is intended only for native use, you may manually write a
main
function.
On a native (non-web) target, it simply creates a main
function that
uses the startup, mainLoop, shouldClose, and teardown functions. When
building with platform-web
enabled, it creates four foreign export
statements (startup
, mainLoop
, shouldClose
, and teardown
), which
will be called through the browser.
See raygui-suite
for an example of how to use it.
Arguments
:: MonadIO m | |
=> (a -> m a) | The game loop. Its only argument should be the current application state, and it should return a new state. |
-> a | The initial application state. |
-> m a | The application state after the last frame. |
Calls the game loop every frame as long as the window is open. For larger projects, instead of using this function, consider making a custom game loop for flexibility.
NOTE: Only for native targets. If your program is intended to
run on the web, use raylibApplication
instead.
whileWindowOpen_ :: MonadIO m => (a -> m a) -> a -> m () Source #
Same as whileWindowOpen
, but discards the final state.
whileWindowOpen0 :: MonadIO m => m () -> m () Source #
Same as whileWindowOpen
, but without application state.
Resource management
data WindowResources Source #
Tracks all raylib resources which cannot be immediately freed.
Each field is an IORef
to a list, and the list contains the data to be
tracked. Typically, data allocated on the GPU is stored here.
class Closeable a where Source #
Typeclass to conveniently release resources
Minimal complete definition
Methods
Release a resource; this is only necessary when using an unmanaged resource
WARNING: Do not use this on a managed resource, doing so will cause it to be freed twice
Instances
managed :: Closeable a => WindowResources -> IO a -> IO a Source #
Use this when loading a resource for automatic memory management
Miscellaneous
cameraDirectionRay :: Camera3D -> Ray Source #
Gets the direction of a camera as a ray.
Arguments
:: Model | The model to operate on |
-> Int | The index of the material |
-> Shader | The shader to use |
-> Model | The modified model |
Sets the shader of a material at a specific index (WARNING: This will fail if the index provided is out of bounds).
class Freeable a where Source #
A typeclass used internally to free complex data types. You will most
likely not have to use this directly. If you do need to implement it, you
can probably just stick with the default definitions of rlFree
and
rlFreeDependents
.
Minimal complete definition
Nothing
Methods
rlFreeDependents :: a -> Ptr a -> IO () Source #
Frees the data "dependent" on a pointer, which usually means dynamic C arrays, i.e. more pointers
rlFree :: a -> Ptr a -> IO () Source #
Receives a pointer and frees all of the data associated with it, including the pointer itself