|
type alias Attribute = { position : Vec3, color : Vec3 }
triangle : Drawable Attribute
triangle =
Triangle
[ ( Attribute (vec3 0 1 0) (vec3 1 0 0)
, Attribute (vec3 -1 -1 0) (vec3 0 1 0)
, Attribute (vec3 1 -1 0) (vec3 0 0 1)
)
]
type alias Attribute = { position : Vec3, color : Vec3 }
type alias Uniform = { rotation : Mat4 }
type alias Varying = { vColor : Vec3 }
vertexShader : Shader Attribute Uniform Varying
vertexShader = [glsl|
attribute vec3 position;
attribute vec3 color;
varying vec3 vColor;
uniform mat4 rotation;
void main () {
gl_Position = rotation * vec4(position, 1.0);
vColor = color;
}
|]
type alias Uniform = { rotation : Mat4 }
type alias Varying = { vColor : Vec3 }
fragmentShader : Shader {} Uniform Varying
fragmentShader = [glsl|
precision mediump float;
varying vec3 vColor;
void main () {
gl_FragColor = vec4(vColor, 1.0);
}
|]
view : Model -> Html a
view angle =
WebGL.toHtml
[ width 300
, height 300
, style [("display", "block")]
]
[ WebGL.render
vertexShader
fragmentShader
triangle
{ rotation = makeRotate angle (vec3 0 1 0) }
]