Mesh


Setup

This example contains a game object with a mesh component in the shape of a triangle. The triangle is defined in triangle.buffer as the three points of the triangle in the position stream. The triangle also defines the colors at each point. The colors get mixed automatically when the triangle is drawn by the shader.

[
    {
        "name": "position",
        "type": "float32",
        "count": 3,
        "data": [
            -0.5, -0.5, 0,
            0.5, -0.5, 0,
            0.0, 0.5, 0
        ]
    },
    {
        "name": "color0",
        "type": "float32",
        "count": 4,
        "data": [
            0, 1, 0, 1,
            1, 0, 0, 1,
            0, 0, 1, 1
        ]
    }
]

Scripts

mesh.fp

varying mediump vec4 var_color;

void main()
{
    gl_FragColor = var_color;
}

mesh.vp

uniform mediump mat4 mtx_worldview;
uniform mediump mat4 mtx_proj;

attribute mediump vec4 position;
attribute mediump vec4 color0;

varying mediump vec4 var_color;

void main()
{
    gl_Position = mtx_proj * mtx_worldview * vec4(position.xyz, 1.0);
    var_color = color0;
}

If you want to play with these examples, you can get the project on Github.

Do you want to see more examples? Why not write a few yourself and submit a pull request? We love contributions.

GITHUB