Skip to content

Instantly share code, notes, and snippets.

@szabba
Last active June 9, 2016 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szabba/13a90267523f122d259a16fe9c5954be to your computer and use it in GitHub Desktop.
Save szabba/13a90267523f122d259a16fe9c5954be to your computer and use it in GitHub Desktop.
Elm WebGL -- nothing gets rendered without AnimationFrame being involved.
{
"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"
}
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