aboutsummaryrefslogtreecommitdiffstats
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
parent1c0c68b5e2f79f3cd4d4398a0ee087d5f3eaa3f9 (diff)
downloadVivant-421843e7e426c3b34aa828b04af7dd4b2f9d81ea.tar.gz
Vivant-421843e7e426c3b34aa828b04af7dd4b2f9d81ea.zip
Compile with shaders added to data
-rw-r--r--learnopengl-haskell.cabal12
-rw-r--r--src/Main.hs26
2 files changed, 13 insertions, 25 deletions
diff --git a/learnopengl-haskell.cabal b/learnopengl-haskell.cabal
index c8e0ab9..807395b 100644
--- a/learnopengl-haskell.cabal
+++ b/learnopengl-haskell.cabal
@@ -8,19 +8,23 @@ version: 0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
--- license:
+license: GPL-3
license-file: LICENSE
author: Yann Herklotz
maintainer: git@yannherklotz.com
-- copyright:
-- category:
build-type: Simple
-extra-source-files: CHANGELOG.md
+extra-source-files: CHANGELOG.md,
+ README.md
+
+data-files: shaders/*.vert,
+ shaders/*.frag
executable learnopengl-haskell
main-is: Main.hs
- -- other-modules:
- -- other-extensions:
+ other-modules: Paths_learnopengl_haskell
+ default-extensions: OverloadedStrings
build-depends: base >=4.14 && <4.15,
sdl2 >=2.5.3.0 && <2.6,
OpenGL >=3.0.3.0 && <3.1,
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