diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-12-03 01:35:22 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-12-03 01:35:22 -0700 |
commit | d7fb5d4551a93b4756db62f494b761c0cef2fda7 (patch) | |
tree | daa035d2abe0154c31eb9286212a5707a19c078e | |
parent | 1fdb567d8fcd6a46f8c38791249a416e4c198599 (diff) | |
download | terralloc-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.
-rw-r--r-- | Final.hs | 5 | ||||
-rw-r--r-- | Graphics/SDL/SDLHelp.hs | 11 |
2 files changed, 14 insertions, 2 deletions
@@ -4,6 +4,7 @@ module Main where +import Text.Printf import Graphics.Rendering.OpenGL as GL import SDL.Image as SDLImg import SDL @@ -41,6 +42,10 @@ import qualified SDL -} buildArray :: SDL.Surface -> SDL.Surface -> IO (Array (Int,Int) Tile) buildArray terrain height = do + bpp <- fromIntegral <$> (getSurfaceBytesPerPixel terrain) :: IO Int + printf "Terrain BBP: %d\n" bpp + + (V2 (fromIntegral -> w) (fromIntegral -> h)) <- SDL.surfaceDimensions terrain {- Pick the minimum width and height between the two images -} let {- Function that returns a Tile for an x y coordinate -} 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) |