Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Triangles exposing (..)
- import WebGL as GL exposing (..)
- import Math.Vector2 exposing (Vec2, vec2)
- import Math.Vector3 exposing (Vec3, vec3)
- import Math.Matrix4 exposing (..)
- import Html exposing (..)
- type alias Model =
- { rotation : Float
- }
- type alias Vertex =
- { position : Vec2
- , color : Vec3
- }
- type alias Varying =
- { vColor : Vec3
- }
- update : msg -> Model -> Model
- update e m = {m | rotation = m.rotation + 0.1}
- --main : Program Never {} {}
- main =
- Html.beginnerProgram
- { model =
- Model 1.0
- , view = view
- , update = update
- }
- view : Model -> Html msg
- view m =
- GL.toHtml
- []
- [ boxEntity m.rotation ]
- boxEntity : Float -> Entity
- boxEntity f =
- GL.entity
- vertexShader
- fragmentShader
- boxMesh
- { rotation = makeRotate f (vec3 1 1 1) }
- vertexShader : Shader { position : Vec2, color : Vec3 } { rotation : Mat4 } { vColor : Vec3 }
- vertexShader =
- [glsl|
- precision mediump float;
- attribute vec2 position;
- attribute vec3 color;
- uniform mat4 rotation;
- varying vec3 vColor;
- void main () {
- gl_Position = rotation * vec4(position, 0.0, 1.0);
- vColor = color;
- }
- |]
- fragmentShader : Shader {} { rotation : Mat4 } Varying
- fragmentShader =
- [glsl|
- precision mediump float;
- varying vec3 vColor;
- void main () {
- gl_FragColor = vec4(vColor, 1.);
- }
- |]
- boxMesh : Mesh Vertex
- boxMesh =
- GL.triangles
- [ ( (Vertex (vec2 -1 1) (vec3 1 0 0))
- , (Vertex (vec2 1 1) (vec3 0 1 0))
- , (Vertex (vec2 -1 -1) (vec3 0 0 1))
- )
- , ( (Vertex (vec2 -1 -1) (vec3 1 0 0))
- , (Vertex (vec2 1 -1) (vec3 0 1 0))
- , (Vertex (vec2 1 1) (vec3 0 0 1))
- )
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement