Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cabal-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
ghc-version: ["9.8", "9.6", "9.2"]
ghc-version: ["9.12", "9.6", "9.2"]
exclude:
- os: macos-latest
ghc-version: "9.2"
Expand Down
2 changes: 0 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
packages: *.cabal

optimization: 2

package h-raylib
flags: +examples
34 changes: 22 additions & 12 deletions examples/basic-audio/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Control.Concurrent (forkOS)
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
import Foreign (ForeignPtr)
import Paths_h_raylib (getDataFileName)
import Raylib.Core (clearBackground, initWindow, setTargetFPS, windowShouldClose, closeWindow)
import Raylib.Core (clearBackground, closeWindow, initWindow, setTargetFPS, windowShouldClose)
import Raylib.Core.Audio (closeAudioDevice, initAudioDevice, loadMusicStream, playMusicStream, updateMusicStream)
import Raylib.Core.Text (drawText)
import Raylib.Util (drawing, managed, WindowResources, raylibApplication)
import Raylib.Util.Colors (lightGray, rayWhite)
import Raylib.Types (Music)
import Raylib.Util (WindowResources, drawing, managed, raylibApplication)
import Raylib.Util.Colors (lightGray, rayWhite)

type AppState = (WindowResources, Music)
type AppState = (WindowResources, IORef (Maybe (ForeignPtr Music)))

musicPath :: String
musicPath = "examples/basic-audio/assets/mini1111.xm"
Expand All @@ -18,20 +22,26 @@ startup :: IO AppState
startup = do
window <- initWindow 650 400 "raylib [audio] example - basic audio"
setTargetFPS 60
initAudioDevice

music <- managed window $ loadMusicStream =<< getDataFileName musicPath

playMusicStream music
-- Multithreaded to avoid pause on startup when initAudioDevice is called
mref <- newIORef Nothing
_ <- forkOS $ do
initAudioDevice
music <- managed window $ loadMusicStream =<< getDataFileName musicPath
playMusicStream music
writeIORef mref (Just music)

return (window, music)
return (window, mref)

mainLoop :: AppState -> IO AppState
mainLoop state@(_, music) = do
mainLoop state@(_, mref) = do
music <- readIORef mref
drawing $ do
clearBackground rayWhite
drawText "You should hear music playing!" 20 20 20 lightGray
updateMusicStream music
case music of
Nothing -> drawText "Music is loading..." 20 20 20 lightGray
Just _ -> drawText "You should hear music playing!" 20 20 20 lightGray
maybe (return ()) updateMusicStream music
return state

shouldClose :: AppState -> IO Bool
Expand Down
8 changes: 5 additions & 3 deletions examples/basic-callbacks/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Paths_h_raylib (getDataFileName)
import Raylib.Core (clearBackground, initWindow, setTargetFPS, windowShouldClose, closeWindow, setLoadFileTextCallback, setTraceLogCallback, loadFileText)
import Raylib.Core (clearBackground, closeWindow, initWindow, loadFileText, setLoadFileTextCallback, setTargetFPS, setTraceLogCallback, windowShouldClose)
import Raylib.Core.Text (drawText)
import Raylib.Util (drawing, raylibApplication, WindowResources)
import Raylib.Util (WindowResources, drawing, raylibApplication)
import Raylib.Util.Colors (black, rayWhite)

filePath :: String
Expand All @@ -28,7 +29,8 @@ mainLoop (text, window) =
clearBackground rayWhite
drawText "File contents:" 30 40 24 black
drawText text 30 70 24 black
) >> return (text, window)
)
>> return (text, window)

shouldClose :: AppState -> IO Bool
shouldClose _ = windowShouldClose
Expand Down
11 changes: 6 additions & 5 deletions examples/basic-images/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE PatternSynonyms #-}

module Main where

import Paths_h_raylib (getDataFileName)
Expand All @@ -12,8 +13,8 @@ import Raylib.Core.Textures
loadRenderTexture,
loadTextureFromImage,
)
import Raylib.Types (Rectangle (Rectangle), RenderTexture (renderTexture'texture), pattern Vector2)
import Raylib.Util (drawing, textureMode, whileWindowOpen0, withWindow, managed)
import Raylib.Types (Image, Rectangle (Rectangle), RenderTexture (renderTexture'texture), Texture, pattern Vector2)
import Raylib.Util (drawing, managed, textureMode, whileWindowOpen0, withWindow)
import Raylib.Util.Colors (black, lightGray, orange, white)

logoPath :: String
Expand All @@ -27,9 +28,9 @@ main = do
"raylib [textures] example - basic images"
60
( \window -> do
texture <- managed window $ loadTextureFromImage =<< genImagePerlinNoise 600 450 20 20 2
logo <- managed window $ loadTextureFromImage =<< loadImage =<< getDataFileName logoPath
rt <- managed window $ loadRenderTexture 200 200
texture <- managed window $ loadTextureFromImage =<< (genImagePerlinNoise 600 450 20 20 2 :: IO Image) :: IO Texture
logo <- managed window $ loadTextureFromImage =<< (loadImage =<< getDataFileName logoPath :: IO Image) :: IO Texture
rt <- managed window $ loadRenderTexture 200 200 :: IO RenderTexture

whileWindowOpen0
( drawing
Expand Down
13 changes: 7 additions & 6 deletions examples/basic-models/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

module Main where

import Foreign (ForeignPtr)
import Paths_h_raylib (getDataFileName)
import Raylib.Core (clearBackground, disableCursor)
import Raylib.Core.Camera (updateCamera)
import Raylib.Core.Models (drawGrid, drawModel, genMeshCube, loadModel, loadModelFromMesh)
import Raylib.Types (Camera3D (Camera3D), CameraMode (CameraModeFirstPerson), CameraProjection (CameraPerspective), pattern Vector3)
import Raylib.Util (drawing, mode3D, whileWindowOpen_, withWindow, managed)
import Raylib.Core.Models (drawGrid, drawModel, genMeshCube, loadModel, loadModelFromMeshManaged)
import Raylib.Types (Camera3D (Camera3D), CameraMode (CameraModeFirstPerson), CameraProjection (CameraPerspective), Mesh, Model, pattern Vector3)
import Raylib.Util (drawing, managed, mode3D, whileWindowOpen_, withWindow)
import Raylib.Util.Colors (orange, white)

modelPath :: String
Expand All @@ -23,9 +24,9 @@ main = do
( \window -> do
disableCursor

mesh <- managed window $ genMeshCube 2 3 4
cubeModel <- managed window $ loadModelFromMesh mesh
customModel <- managed window $ loadModel =<< getDataFileName modelPath
mesh <- managed window $ genMeshCube 2 3 4 :: IO (ForeignPtr Mesh)
cubeModel <- loadModelFromMeshManaged mesh window :: IO (ForeignPtr Model)
customModel <- managed window $ loadModel =<< getDataFileName modelPath :: IO (ForeignPtr Model)

let camera = Camera3D (Vector3 3 2 3) (Vector3 0 0 0) (Vector3 0 1 0) 70 CameraPerspective

Expand Down
2 changes: 1 addition & 1 deletion examples/basic-rlgl/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Raylib.Core (clearBackground)
import Raylib.Core.Models (drawGrid)
import Raylib.Core.Textures (loadTexture)
import Raylib.Types (Camera3D (Camera3D), CameraProjection (CameraPerspective), Color (Color), RLDrawMode (RLQuads), Rectangle (Rectangle), Texture (texture'height, texture'id, texture'width), Vector3, pattern Vector3)
import Raylib.Util (drawing, mode3D, whileWindowOpen0, withWindow, managed)
import Raylib.Util (drawing, managed, mode3D, whileWindowOpen0, withWindow)
import Raylib.Util.Colors (rayWhite, white)
import Raylib.Util.RLGL (rlBegin, rlColor4ub, rlEnd, rlNormal3f, rlPopMatrix, rlPushMatrix, rlRotatef, rlScalef, rlSetTexture, rlTexCoord2f, rlTranslatef, rlVertex3f)
import Prelude hiding (length)
Expand Down
30 changes: 17 additions & 13 deletions examples/basic-shaders/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

module Main where

import Paths_h_raylib (getDataFileName)
import Control.Monad (when)
import Foreign (ForeignPtr)
import Numeric (showFFloat)
import Paths_h_raylib (getDataFileName)
import Raylib.Core
( beginDrawing,
beginMode3D,
Expand All @@ -21,13 +22,16 @@ import Raylib.Core
setTargetFPS,
)
import Raylib.Core.Camera (updateCamera)
import Raylib.Core.Models (drawModel, drawSphereWires, genMeshCube, genMeshPlane, genMeshSphere, loadModelFromMesh)
import Raylib.Core.Models (drawModel, drawSphereWires, genMeshCube, genMeshPlane, genMeshSphere, loadModelFromMeshManaged)
import Raylib.Core.Text (drawText)
import Raylib.Types
( Camera3D (Camera3D, camera3D'position),
CameraMode (CameraModeFirstPerson),
CameraProjection (CameraPerspective),
KeyboardKey (KeyH, KeyJ, KeyU, KeyY),
Mesh,
Model,
Shader,
ShaderUniformData
( ShaderUniformFloat,
ShaderUniformVec3,
Expand All @@ -38,7 +42,7 @@ import Raylib.Types
pattern Vector3,
pattern Vector4,
)
import Raylib.Util (setMaterialShader, whileWindowOpen_, managed)
import Raylib.Util (managed, setMaterialShader, whileWindowOpen_)
import Raylib.Util.Colors (black, blue, lightGray, orange, white)

assetsPath :: String
Expand All @@ -54,7 +58,7 @@ main = do

vert <- getDataFileName (assetsPath ++ "lighting.vert")
frag <- getDataFileName (assetsPath ++ "lighting.frag")
shader <- managed window $ loadShader (Just vert) (Just frag)
shader <- managed window $ loadShader (Just vert) (Just frag) :: IO (ForeignPtr Shader)

let pointLightPosition = Vector3 0 3 2
let pointLightColor = Vector4 1 1 1 1
Expand All @@ -70,17 +74,17 @@ main = do
setShaderValue shader "ambientLightColor" (ShaderUniformVec4 ambientLightColor) window
setShaderValue shader "ambientStrength" (ShaderUniformFloat ambientStrength) window

cubeMesh <- managed window $ genMeshCube 2 2 2
cubeModel' <- managed window $ loadModelFromMesh cubeMesh
let cubeModel = setMaterialShader cubeModel' 0 shader
cubeMesh <- managed window $ genMeshCube 2 2 2 :: IO (ForeignPtr Mesh)
cubeModel <- loadModelFromMeshManaged cubeMesh window :: IO (ForeignPtr Model)
_ <- setMaterialShader cubeModel 0 shader

sphereMesh <- managed window $ genMeshSphere 0.5 32 32
sphereModel' <- managed window $ loadModelFromMesh sphereMesh
let sphereModel = setMaterialShader sphereModel' 0 shader
sphereMesh <- managed window $ genMeshSphere 0.5 32 32 :: IO (ForeignPtr Mesh)
sphereModel <- loadModelFromMeshManaged sphereMesh window :: IO (ForeignPtr Model)
_ <- setMaterialShader sphereModel 0 shader

planeMesh <- managed window $ genMeshPlane 100 100 20 20
planeModel' <- managed window $ loadModelFromMesh planeMesh
let planeModel = setMaterialShader planeModel' 0 shader
planeMesh <- managed window $ genMeshPlane 100 100 20 20 :: IO (ForeignPtr Mesh)
planeModel <- loadModelFromMeshManaged planeMesh window :: IO (ForeignPtr Model)
_ <- setMaterialShader planeModel 0 shader

whileWindowOpen_
( \(c, ls, ss) -> do
Expand Down
8 changes: 5 additions & 3 deletions examples/basic-window/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Raylib.Core (clearBackground, initWindow, setTargetFPS, windowShouldClose, closeWindow)
import Raylib.Core (clearBackground, closeWindow, initWindow, setTargetFPS, windowShouldClose)
import Raylib.Core.Text (drawText)
import Raylib.Util (drawing, raylibApplication, WindowResources)
import Raylib.Util (WindowResources, drawing, raylibApplication)
import Raylib.Util.Colors (lightGray, rayWhite)

startup :: IO WindowResources
Expand All @@ -18,7 +19,8 @@ mainLoop window =
( do
clearBackground rayWhite
drawText "Basic raylib window" 30 40 18 lightGray
) >> return window
)
>> return window

shouldClose :: WindowResources -> IO Bool
shouldClose _ = windowShouldClose
Expand Down
Loading