diff --git a/README.md b/README.md index 0cd49c5..ec6fc01 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ OpenGL tutorial by The Cherno There are some major deviations from the tutorial setup here as follows: * Code base is entirely written in Haskell, not C++ -* instead of GLFW with GLEW I use SDL2 out of familiarity +* Instead of GLFW with GLEW I use SDL2 out of familiarity +* Shaders are actually split into files per type, since IÄmnot willing to + unleash Haskell list magic I leave as many helpful comments as possible throughout the code, so feel free to peruse it. diff --git a/res/shaders/frag.shader b/res/shaders/frag.shader new file mode 100644 index 0000000..037ef95 --- /dev/null +++ b/res/shaders/frag.shader @@ -0,0 +1,8 @@ +#version 330 core + +out vec4 color; + +void main() +{ + color = vec4(0.0, 1.0, 0.0, 0.5); +} diff --git a/res/shaders/vert.shader b/res/shaders/vert.shader new file mode 100644 index 0000000..52acfe6 --- /dev/null +++ b/res/shaders/vert.shader @@ -0,0 +1,8 @@ +#version 330 core + +layout(location = 0) in vec4 position; + +void main() +{ + gl_Position = position; +} diff --git a/src/Main.hs b/src/Main.hs index 960fc50..30e87ce 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -23,6 +23,9 @@ import Foreign.Storable import Data.Word import qualified Data.ByteString as B +import qualified Data.ByteString.Char8 as B8 + +import qualified Data.List as L import System.Random (randomRIO) @@ -105,29 +108,11 @@ main = do -- -- SHADERS - -- define shader source code (usually these are separate files) - let vertexShader = mconcat - [ "#version 330 core\n" - , "\n" - , "layout(location = 0) in vec4 position;\n" - , "\n" - , "void main()\n" - , "{\n" - , " gl_Position = position;\n" - , "}\n" - ] :: B.ByteString - fragmentShader = mconcat - [ "#version 330 core\n" - , "\n" - , "out vec4 color;\n" - , "\n" - , "void main()\n" - , "{\n" - , " color = vec4(0.0, 1.0, 0.0, 0.5);\n" - , "}\n" - ] :: B.ByteString + -- read in shaders from source file + vertSrc <- B.readFile "./res/shaders/vert.shader" + fragSrc <- B.readFile "./res/shaders/frag.shader" - sp <- createShaderProgram vertexShader fragmentShader + sp <- createShaderProgram vertSrc fragSrc GL.currentProgram $= Just sp -- -- EVENTING AND DRAWING