aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2020-12-27 00:35:57 +0000
committerYann Herklotz <git@yannherklotz.com>2020-12-27 00:35:57 +0000
commit421843e7e426c3b34aa828b04af7dd4b2f9d81ea (patch)
tree9abf3a5725d92b22ce6a0e47f24e7afe6c9c4a33 /src
parent1c0c68b5e2f79f3cd4d4398a0ee087d5f3eaa3f9 (diff)
downloadVivant-421843e7e426c3b34aa828b04af7dd4b2f9d81ea.tar.gz
Vivant-421843e7e426c3b34aa828b04af7dd4b2f9d81ea.zip
Compile with shaders added to data
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs26
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