add hs-glsl library, remove shader files

This commit is contained in:
mtgmonkey
2025-11-30 19:13:44 +01:00
parent 117eb61428
commit 0cff550c23
6 changed files with 42 additions and 27 deletions

View File

@@ -8,15 +8,18 @@ module IO (openWindow, shutdownWindow, view) where
import qualified Graphics.Rendering.OpenGL as GL
import Graphics.Rendering.OpenGL (($=))
import qualified Graphics.UI.GLFW as GLFW
import qualified Language.GLSL as GLSL
import Control.Exception
import Control.Monad
import Data.Text (unpack)
import Foreign.Ptr
import Foreign.Marshal.Array
import Foreign.Storable
import LoadShaders
import Relude
import Shaders
import Types
-- VIEW --
@@ -100,8 +103,8 @@ initResources = do
-- load shaders
program <- loadShaders
[ ShaderInfo GL.VertexShader (FileSource "vert.glsl")
, ShaderInfo GL.FragmentShader (FileSource "frag.glsl")
[ ShaderInfo GL.VertexShader (StringSource $ unpack $ GLSL.generateGLSL vertShader)
, ShaderInfo GL.FragmentShader (StringSource $ unpack $ GLSL.generateGLSL fragShader)
]
GL.currentProgram $= Just program

35
src/Shaders.hs Normal file
View File

@@ -0,0 +1,35 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Shaders (fragShader, vertShader) where
-- IMPORTS --
import Relude
import Language.GLSL
fragShader :: Program
fragShader =
[ VersionDeclaration 450 Core
, VariableDeclaration Nothing In fragColorOut
, VariableDeclaration Nothing Out fragColor
, MainStart
, VariableAssignment fragColor fragColorOut
]
vertShader :: Program
vertShader =
[ VersionDeclaration 450 Core
, VariableDeclaration (Just $ Location 0) In vertexPosition
, VariableDeclaration (Just $ Location 1) In vertexColor
, VariableDeclaration Nothing Out fragColorOut
, MainStart
, VariableAssignment GL_POSITION vertexPosition
, VariableAssignment fragColorOut vertexColor
]
fragColor = Variable "fragColor" $ GLSLVec4 GLSLFloat
fragColorOut = Variable "fragColorOut" $ GLSLVec4 GLSLFloat
vertexPosition = Variable "vertexPosition" $ GLSLVec4 GLSLFloat
vertexColor = Variable "vertexColor" $ GLSLVec4 GLSLFloat