hunk ./src/Graphics/Formats/Mtl/Contents.hs 26 +import Foreign hiding (newArray) + +import Data.Array.Unboxed + hunk ./src/Graphics/Formats/Mtl/Contents.hs 117 +{- Andy Gill's hacky texture loading code -} +buildTexture :: UArray (Int,Int,Int) Word8 -> IO TextureObject +buildTexture arr = + do let (width,height,mindepth) = + case bounds arr of + ((mw,mh,md),(w,h,_)) -> (w + 1 - mw,h + 1 - mh, md) + p <- mallocBytes (width * height * 4) + sequence_ + [ do pokeElemOff p (off+0) (arr ! (w,h,mindepth )) + pokeElemOff p (off+1) (arr ! (w,h,mindepth+1)) + pokeElemOff p (off+2) (arr ! (w,h,mindepth+2)) + pokeElemOff p (off+3) (arr ! (w,h,mindepth+3)) + | (off,(w,h)) <- zip [0,4 ..] [ (w,h) | w <- [ 0 .. width - 1 ] + , h <- [ 0 .. height - 1 ]] + ] + + texName <- liftM head (genObjectNames 1) + textureBinding Texture2D $= Just texName + textureFilter Texture2D $= ((Linear', Nothing), Linear') + + textureWrapMode Texture2D S $= (Repeated, Repeat) + textureWrapMode Texture2D T $= (Repeated, Repeat) + + let pd = PixelData RGBA UnsignedByte p + texImage2D Nothing + NoProxy + 0 + RGBA' + (TextureSize2D (fromIntegral width) (fromIntegral height)) + 0 + pd + return texName + hunk ./obj.cabal 3 -Version: 0.1.1 +Version: 0.1.2