diff options
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/src/Main.hs b/src/Main.hs index 6937ba6..f5100e3 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -13,8 +13,6 @@ GNU General Public License for more details. -} -{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} module Main where import Control.Monad @@ -29,6 +27,8 @@ import SDL (($=)) import qualified SDL import qualified Graphics.Rendering.OpenGL as GL +import Paths_learnopengl_haskell (getDataDir) + screenWidth, screenHeight :: CInt (screenWidth, screenHeight) = (640, 480) @@ -67,8 +67,10 @@ main = do initResources :: IO (GL.Program, GL.AttribLocation) initResources = do + datadir <- getDataDir -- compile vertex shader vs <- GL.createShader GL.VertexShader + vsSource <- BS.readFile $ datadir <> "/shaders/triangle.vert" GL.shaderSourceBS vs $= vsSource GL.compileShader vs vsOK <- GL.get $ GL.compileStatus vs @@ -78,6 +80,7 @@ initResources = do -- Do it again for the fragment shader fs <- GL.createShader GL.FragmentShader + fsSource <- BS.readFile $ datadir <> "/shaders/triangle.frag" GL.shaderSourceBS fs $= fsSource GL.compileShader fs fsOK <- GL.get $ GL.compileStatus fs @@ -116,25 +119,6 @@ draw program attrib = do GL.drawArrays GL.Triangles 0 3 -- 3 is the number of vertices GL.vertexAttribArray attrib $= GL.Disabled -vsSource, fsSource :: BS.ByteString -vsSource = BS.intercalate "\n" - [ - "attribute vec2 coord2d; " - , "" - , "void main(void) { " - , " gl_Position = vec4(coord2d, 0.0, 1.0); " - , "}" - ] - -fsSource = BS.intercalate "\n" - [ - "" - , "#version 120" - , "void main(void) {" - , "gl_FragColor = vec4((gl_FragCoord.x/640), (gl_FragCoord.y/480), 0, 1);" - , "}" - ] - vertices :: V.Vector Float vertices = V.fromList [ 0.0, 0.8 , -0.8, -0.8 |