aboutsummaryrefslogtreecommitdiff
path: root/Graphics/SDL/SDLHelp.hs
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-12-03 01:35:22 -0700
committerJosh Rahm <joshuarahm@gmail.com>2022-12-03 01:35:22 -0700
commitd7fb5d4551a93b4756db62f494b761c0cef2fda7 (patch)
treedaa035d2abe0154c31eb9286212a5707a19c078e /Graphics/SDL/SDLHelp.hs
parent1fdb567d8fcd6a46f8c38791249a416e4c198599 (diff)
downloadterralloc-d7fb5d4551a93b4756db62f494b761c0cef2fda7.tar.gz
terralloc-d7fb5d4551a93b4756db62f494b761c0cef2fda7.tar.bz2
terralloc-d7fb5d4551a93b4756db62f494b761c0cef2fda7.zip
Figured out what the problem was and fixed it.
It was using the wrong numebr of bytes per pixel. That was solved by writing a routine to determine it. It looks like there are some branches that add snow and first person to the application. I'll see about merging those in.
Diffstat (limited to 'Graphics/SDL/SDLHelp.hs')
-rw-r--r--Graphics/SDL/SDLHelp.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/Graphics/SDL/SDLHelp.hs b/Graphics/SDL/SDLHelp.hs
index 62bb640..9c65c83 100644
--- a/Graphics/SDL/SDLHelp.hs
+++ b/Graphics/SDL/SDLHelp.hs
@@ -18,6 +18,8 @@ import Data.Bits
import System.IO.Unsafe
import System.Endian
import System.Exit
+import SDL.Raw (getSurfaceColorMod)
+import qualified SDL.Raw.Types
data TextureData = TextureData {
textureSize :: (Int,Int),
@@ -31,7 +33,7 @@ data TextureData3D = TextureData3D {
bindSurfaceToTexture :: SDL.Surface -> TextureObject -> IO TextureData
bindSurfaceToTexture surf to = do
textureBinding Texture2D $= Just to
- bbp <- return 4 -- liftM fromIntegral (pixelFormatGetBytesPerPixel $ SDL.surfacePixels surf)
+ bbp <- fromIntegral <$> getSurfaceBytesPerPixel surf
ptr <- SDL.surfacePixels surf
(V2 w h) <- SDL.surfaceDimensions surf
@@ -67,7 +69,7 @@ makeTexture = do
getPixel :: Int -> Int -> SDL.Surface -> IO Word32
getPixel x y surf = do
- bpp <- return 3 -- liftM fromIntegral (pixelFormatGetBytesPerPixel $ surfaceGetPixelFormat surf)
+ bpp <- fromIntegral <$> getSurfaceBytesPerPixel surf
ptr <- (surfacePixels surf >>= return.castPtr) :: IO (Ptr Word8)
(V2 w h) <- SDL.surfaceDimensions surf
let newPtr = ptr `plusPtr` (y * bpp * fromIntegral w) `plusPtr` (x * bpp)
@@ -169,3 +171,8 @@ setupTexturing3D (TextureData3D _ to) tu unit = do
activeTexture $= TextureUnit (fromIntegral unit)
textureBinding Texture3D $= Just to
uniform tu $= Index1 (fromIntegral unit::GLint)
+
+getSurfaceBytesPerPixel :: SDL.Surface -> IO Word8
+getSurfaceBytesPerPixel (SDL.Surface ptr _) = do
+ SDL.Raw.Types.pixelFormatBytesPerPixel <$>
+ (peek . SDL.Raw.Types.surfaceFormat =<< peek ptr)