Last active
June 9, 2016 23:05
-
-
Save szabba/13a90267523f122d259a16fe9c5954be to your computer and use it in GitHub Desktop.
Elm WebGL -- nothing gets rendered without AnimationFrame being involved.
This file contains 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
{ | |
"version": "1.0.0", | |
"summary": "RUN!", | |
"repository": "https://github.com/user/repo.git", | |
"license": "MIT", | |
"source-directories": [ | |
"." | |
], | |
"exposed-modules": [], | |
"dependencies": { | |
"elm-community/elm-linear-algebra": "2.0.2 <= v < 3.0.0", | |
"elm-community/elm-webgl": "3.0.0 <= v < 4.0.0", | |
"elm-lang/animation-frame": "1.0.0 <= v < 2.0.0", | |
"elm-lang/core": "4.0.1 <= v < 5.0.0", | |
"elm-lang/html": "1.0.0 <= v < 2.0.0" | |
}, | |
"elm-version": "0.17.0 <= v < 0.18.0" | |
} |
This file contains 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 Main exposing (main) | |
import Math.Vector3 as Vec3 exposing (Vec3) | |
import Html as H exposing (Html) | |
import Html.App as App | |
import Html.Attributes as HA | |
import Time | |
import WebGL | |
import AnimationFrame | |
main : Program Never | |
main = | |
App.program | |
{ init = () ! [] | |
, subscriptions = | |
\_ -> | |
if False then | |
AnimationFrame.diffs identity | |
else if False then | |
Time.every (5 * Time.second) identity | |
else | |
Sub.none | |
, update = \_ _ -> () ! [] | |
, view = view | |
} | |
view : a -> Html msg | |
view model = | |
WebGL.toHtml | |
[ HA.width 400 | |
, HA.height 300 | |
] | |
[ WebGL.render vertexShader fragmentShader heroVertices {} ] | |
type alias Vertex = | |
{ pos : Vec3 } | |
heroVertices : WebGL.Drawable Vertex | |
heroVertices = | |
WebGL.Triangle | |
[ ( { pos = Vec3.vec3 0 0 0 } | |
, { pos = Vec3.vec3 1 1 0 } | |
, { pos = Vec3.vec3 1 -1 0 } | |
) | |
] | |
|> Debug.log "triangle" | |
vertexShader : WebGL.Shader Vertex {} {} | |
vertexShader = | |
[glsl| | |
precision mediump float; | |
attribute vec3 pos; | |
void main() { | |
gl_Position = vec4(0.5 * pos, 1); | |
} |] | |
fragmentShader : WebGL.Shader {} {} {} | |
fragmentShader = | |
[glsl| | |
precision mediump float; | |
void main() { | |
gl_FragColor = vec4(0, 0, 1, 1); | |
} |] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment