finished episode 8

This commit is contained in:
nek0 2020-05-17 10:59:15 +02:00
parent d7773af8b6
commit 4acc1dd84e
4 changed files with 26 additions and 23 deletions

View file

@ -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.

8
res/shaders/frag.shader Normal file
View file

@ -0,0 +1,8 @@
#version 330 core
out vec4 color;
void main()
{
color = vec4(0.0, 1.0, 0.0, 0.5);
}

8
res/shaders/vert.shader Normal file
View file

@ -0,0 +1,8 @@
#version 330 core
layout(location = 0) in vec4 position;
void main()
{
gl_Position = position;
}

View file

@ -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