nehe-tuts 0.2.1 → 0.2.2
raw patch · 8 files changed
+44/−46 lines, 8 files
Files
- lesson06.hs +4/−4
- lesson07.hs +3/−4
- lesson08.hs +3/−4
- lesson09.hs +3/−4
- lesson10.hs +14/−13
- lesson11.hs +3/−4
- lesson12.hs +3/−4
- nehe-tuts.cabal +11/−9
lesson06.hs view
@@ -14,8 +14,8 @@ import Data.IORef ( IORef, newIORef, readIORef, writeIORef ) import Foreign ( withForeignPtr, plusPtr, peek, alloca ) import qualified Data.ByteString.Internal as BSI-import System.Directory ( getCurrentDirectory, setCurrentDirectory ) import Util ( Image(..), bitmapLoad )+import Paths_nehe_tuts initGL :: IO GLuint initGL = do@@ -30,7 +30,9 @@ loadGLTextures :: IO GLuint loadGLTextures = do- Just (Image w h pd) <- bitmapLoad "Data/NeHe.bmp"+ fp <- getDataFileName "NeHe.bmp"+ putStrLn $ "loading texture: " ++ fp+ Just (Image w h pd) <- bitmapLoad fp putStrLn $ "Image width = " ++ show w putStrLn $ "Image height = " ++ show h tex <- alloca $ \p -> do@@ -155,9 +157,7 @@ main :: IO () main = do- cd <- getCurrentDirectory True <- GLFW.initialize- setCurrentDirectory cd -- select type of display mode: -- Double buffer -- RGBA color
lesson07.hs view
@@ -17,8 +17,8 @@ import Foreign.Storable ( Storable ) import Foreign.Marshal.Array ( newArray, allocaArray, peekArray ) import qualified Data.ByteString.Internal as BSI-import System.Directory ( getCurrentDirectory, setCurrentDirectory ) import Util ( Image(..), bitmapLoad )+import Paths_nehe_tuts newArray' :: Storable a => [a] -> IO (ForeignPtr a) newArray' xs = (newArray xs) >>= newForeignPtr_@@ -47,7 +47,8 @@ loadGLTextures :: IO [GLuint] loadGLTextures = do- Just (Image w h pd) <- bitmapLoad "Data/Crate.bmp"+ fp <- getDataFileName "Crate.bmp"+ Just (Image w h pd) <- bitmapLoad fp let numTextures = 3 texs <- allocaArray numTextures $ \p -> do glGenTextures (fromIntegral numTextures) p@@ -231,9 +232,7 @@ main :: IO () main = do- cd <- getCurrentDirectory True <- GLFW.initialize- setCurrentDirectory cd -- select type of display mode: -- Double buffer -- RGBA color
lesson08.hs view
@@ -17,8 +17,8 @@ import Foreign.Storable ( Storable ) import Foreign.Marshal.Array ( newArray, allocaArray, peekArray ) import qualified Data.ByteString.Internal as BSI-import System.Directory ( getCurrentDirectory, setCurrentDirectory ) import Util ( Image(..), bitmapLoad )+import Paths_nehe_tuts newArray' :: Storable a => [a] -> IO (ForeignPtr a) newArray' xs = (newArray xs) >>= newForeignPtr_@@ -48,7 +48,8 @@ loadGLTextures :: IO [GLuint] loadGLTextures = do- Just (Image w h pd) <- bitmapLoad "Data/glass.bmp"+ fp <- getDataFileName "glass.bmp"+ Just (Image w h pd) <- bitmapLoad fp let numTextures = 3 texs <- allocaArray numTextures $ \p -> do glGenTextures (fromIntegral numTextures) p@@ -240,9 +241,7 @@ main :: IO () main = do- cd <- getCurrentDirectory True <- GLFW.initialize- setCurrentDirectory cd -- select type of display mode: -- Double buffer -- RGBA color
lesson09.hs view
@@ -18,9 +18,9 @@ import Foreign.Storable ( Storable ) import Foreign.Marshal.Array ( newArray ) import qualified Data.ByteString.Internal as BSI-import System.Directory ( getCurrentDirectory, setCurrentDirectory ) import Util ( Image(..), bitmapLoad ) import System.Random ( getStdRandom, randomR )+import Paths_nehe_tuts data Star = Star { starColor :: !(GLubyte, GLubyte, GLubyte) , starDist :: !GLfloat @@ -60,7 +60,8 @@ loadGLTextures :: IO GLuint loadGLTextures = do- Just (Image w h pd) <- bitmapLoad "Data/Star.bmp"+ fp <- getDataFileName "Star.bmp"+ Just (Image w h pd) <- bitmapLoad fp tex <- alloca $ \p -> do glGenTextures 1 p peek p@@ -185,9 +186,7 @@ main :: IO () main = do- cd <- getCurrentDirectory True <- GLFW.initialize- setCurrentDirectory cd -- select type of display mode: -- Double buffer -- RGBA color
lesson10.hs view
@@ -16,9 +16,9 @@ import Foreign.Storable ( Storable ) import Foreign.Marshal.Array ( allocaArray, peekArray, newArray ) import qualified Data.ByteString.Internal as BSI-import System.Directory ( getCurrentDirectory, setCurrentDirectory ) import Util ( Image(..), bitmapLoad ) import Control.Monad ( when, forM_, forever )+import Paths_nehe_tuts type Sector = [Tri] @@ -78,14 +78,16 @@ readRef r = r >>= readIORef setupWorld :: IO Sector-setupWorld = do h <- openFile "Data/world.txt" ReadMode- ls <- (fmap (filter ignorable) ((fmap lines . hGetContents) h))- let numtris = read ((head . tail . words . head) ls)- let tris = readTris (tail ls)- when (length tris /= numtris) $ do- putStrLn "error reading world.txt"- exitWith (ExitFailure 1)- return tris+setupWorld = do+ fp <- getDataFileName "world.txt"+ h <- openFile fp ReadMode+ ls <- (fmap (filter ignorable) ((fmap lines . hGetContents) h))+ let numtris = read ((head . tail . words . head) ls)+ tris = readTris (tail ls)+ when (length tris /= numtris) $ do+ putStrLn "error reading world.txt"+ exitWith (ExitFailure 1)+ return tris where readTris :: [String] -> [Tri] readTris (l1:l2:l3:ls) = (Tri (readVert (words l1))@@ -104,7 +106,7 @@ ignorable ('/':'/':_) = False ignorable [] = False ignorable _ = True- + initGL :: IO [GLuint] initGL = do glEnable gl_TEXTURE_2D@@ -128,7 +130,8 @@ loadTextures :: IO [GLuint] loadTextures = do- Just (Image w h pd) <- bitmapLoad "Data/mud.bmp"+ fp <- getDataFileName "mud.bmp"+ Just (Image w h pd) <- bitmapLoad fp let numTexs = 3 :: Int texs <- allocaArray (fromIntegral numTexs) $ \p -> do glGenTextures (fromIntegral numTexs) p@@ -275,9 +278,7 @@ main :: IO () main = do- cd <- getCurrentDirectory True <- GLFW.initialize- setCurrentDirectory cd sector <- setupWorld -- select type of display mode: -- Double buffer
lesson11.hs view
@@ -16,7 +16,7 @@ import Util ( Image(..), bitmapLoad ) import Data.Array.IO ( readArray, IOArray, newListArray ) import Control.Applicative ( (<$>), (<*>) )-import System.Directory ( getCurrentDirectory, setCurrentDirectory )+import Paths_nehe_tuts type Points = IOArray (Int, Int, Int) GLfloat @@ -38,7 +38,8 @@ loadGLTextures :: IO GLuint loadGLTextures = do- Just (Image w h pd) <- bitmapLoad "Data/tim.bmp"+ fp <- getDataFileName "tim.bmp"+ Just (Image w h pd) <- bitmapLoad fp putStrLn $ "Image w = " ++ show w putStrLn $ "Image h = " ++ show h tex <- alloca $ \p -> do@@ -138,9 +139,7 @@ main :: IO () main = do- cd <- getCurrentDirectory True <- GLFW.initialize- setCurrentDirectory cd -- select type of display mode: -- Double buffer -- RGBA color
lesson12.hs view
@@ -15,7 +15,7 @@ import Foreign ( withForeignPtr, plusPtr, alloca, peek ) import qualified Data.ByteString.Internal as BSI import Util ( Image(..), bitmapLoad )-import System.Directory ( getCurrentDirectory, setCurrentDirectory )+import Paths_nehe_tuts boxcol :: [(GLfloat, GLfloat, GLfloat)] boxcol = [(1, 0, 0), (1, 0.5, 0), (1, 1, 0), @@ -83,7 +83,8 @@ loadTextures :: IO GLuint loadTextures = do- Just (Image w h pd) <- bitmapLoad "Data/cube.bmp"+ fp <- getDataFileName "cube.bmp"+ Just (Image w h pd) <- bitmapLoad fp putStrLn $ "Image w = " ++ show w putStrLn $ "Image h = " ++ show h tex <- alloca $ \p -> do@@ -154,9 +155,7 @@ main :: IO () main = do- cd <- getCurrentDirectory True <- GLFW.initialize- setCurrentDirectory cd -- select type of display mode: -- Double buffer -- RGBA color
nehe-tuts.cabal view
@@ -1,5 +1,5 @@ Name: nehe-tuts-Version: 0.2.1+Version: 0.2.2 Synopsis: Port of the NeHe OpenGL tutorials to Haskell. Description: Port of the NeHe OpenGL tutorials to Haskell; so far only lessons 1-12 have been ported. Author: Jason Dagit@@ -9,7 +9,9 @@ Category: Graphics Cabal-Version: >= 1.8 Build-type: Simple-Extra-Source-Files: README, Data/Crate.bmp, Data/Star.bmp, Data/glass.bmp, Data/tim.bmp, Data/NeHe.bmp, Data/cube.bmp, Data/mud.bmp, Data/world.txt+Extra-Source-Files: README+data-dir: Data+data-files: *.bmp, *.txt source-repository head type: git location: https://github.com/dagit/nehe-tuts@@ -46,7 +48,7 @@ GHC-Options: -Wall Executable lesson06 Main-is: lesson06.hs- Other-modules: Util+ Other-modules: Util, Paths_nehe_tuts Build-Depends: base >= 3 && < 5, OpenGLRaw == 1.1.*, GLURaw == 1.1.*, GLFW-b == 0.0.*, bytestring == 0.9.*, cereal == 0.3.*,@@ -54,7 +56,7 @@ GHC-Options: -Wall Executable lesson07 Main-is: lesson07.hs- Other-modules: Util+ Other-modules: Util, Paths_nehe_tuts Build-Depends: base >= 3 && < 5, OpenGLRaw == 1.1.*, GLURaw == 1.1.*, GLFW-b == 0.0.*, bytestring == 0.9.*, cereal == 0.3.*,@@ -62,7 +64,7 @@ GHC-Options: -Wall Executable lesson08 Main-is: lesson08.hs- Other-modules: Util+ Other-modules: Util, Paths_nehe_tuts Build-Depends: base >= 3 && < 5, OpenGLRaw == 1.1.*, GLURaw == 1.1.*, GLFW-b == 0.0.*, bytestring == 0.9.*, cereal == 0.3.*,@@ -70,7 +72,7 @@ GHC-Options: -Wall Executable lesson09 Main-is: lesson09.hs- Other-modules: Util+ Other-modules: Util, Paths_nehe_tuts Build-Depends: base >= 3 && < 5, OpenGLRaw == 1.1.*, GLURaw == 1.1.*, GLFW-b == 0.0.*, bytestring == 0.9.*, cereal == 0.3.*,@@ -78,7 +80,7 @@ GHC-Options: -Wall Executable lesson10 Main-is: lesson10.hs- Other-modules: Util+ Other-modules: Util, Paths_nehe_tuts Build-Depends: base >= 3 && < 5, OpenGLRaw == 1.1.*, GLURaw == 1.1.*, GLFW-b == 0.0.*, bytestring == 0.9.*, cereal == 0.3.*,@@ -86,7 +88,7 @@ GHC-Options: -Wall Executable lesson11 Main-is: lesson11.hs- Other-modules: Util+ Other-modules: Util, Paths_nehe_tuts Build-Depends: base >= 3 && < 5, OpenGLRaw == 1.1.*, GLURaw == 1.1.*, GLFW-b == 0.0.*, bytestring == 0.9.*, cereal == 0.3.*,@@ -94,7 +96,7 @@ GHC-Options: -Wall Executable lesson12 Main-is: lesson12.hs- Other-modules: Util+ Other-modules: Util, Paths_nehe_tuts Build-Depends: base >= 3 && < 5, OpenGLRaw == 1.1.*, GLURaw == 1.1.*, GLFW-b == 0.0.*, bytestring == 0.9.*, cereal == 0.3.*,