aboutsummaryrefslogtreecommitdiff
path: root/Graphics/SDL
diff options
context:
space:
mode:
Diffstat (limited to 'Graphics/SDL')
-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)