Last active
August 5, 2016 02:14
-
-
Save quephird/30d45c7a657af2733778 to your computer and use it in GitHub Desktop.
Trying to get a minimal example of GLSL in PureScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Example.HelloGlsl where | |
import Prelude (Unit(..) | |
,($) | |
,bind) | |
import Control.Monad.Eff (Eff(..)) | |
import Control.Monad.Eff.Alert (Alert(..) | |
,alert) | |
import Control.Monad.Eff.Console (CONSOLE(..) | |
,log) | |
import Data.Matrix4 (Mat4(..)) | |
import Data.Vector3 (Vec3(..)) | |
import Graphics.WebGL (Attribute(..) | |
,Capacity(..) | |
,Mask(..) | |
,Shaders(..) | |
,Uniform(..) | |
,clear | |
,clearColor | |
,enable | |
,getCanvasHeight | |
,getCanvasWidth | |
,runWebGL | |
,viewport | |
,withShaders) | |
type Bindings = (aVertexPosition :: Attribute Vec3 | |
,uPMatrix :: Uniform Mat4 | |
,uMVMatrix:: Uniform Mat4) | |
shaders :: Shaders (Object Bindings) | |
shaders = Shaders | |
""" | |
precision mediump float; | |
void main(void) { | |
gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0); | |
} | |
""" | |
""" | |
attribute vec3 aVertexPosition; | |
uniform mat4 uMVMatrix; | |
uniform mat4 uPMatrix; | |
void main(void) { | |
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); | |
} | |
""" | |
main :: Eff (console :: CONSOLE, alert :: Alert) Unit | |
main = do | |
runWebGL "hello-glsl" (\s -> alert s) | |
\context -> do | |
log "WebGL started..." | |
withShaders shaders (\s -> alert s) | |
\bindings -> do | |
log "Shaders and bindings ready..." | |
clearColor 0.0 0.0 0.0 1.0 | |
enable DEPTH_TEST | |
canvasWidth <- getCanvasWidth context | |
canvasHeight <- getCanvasHeight context | |
viewport 0 0 canvasWidth canvasHeight | |
clear [COLOR_BUFFER_BIT, DEPTH_BUFFER_BIT] | |
log "WebGL completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment