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
]
}
]
mesh.fp
#version 140
in mediump vec4 var_color;
out vec4 out_fragColor;
void main()
{
out_fragColor = var_color;
}mesh.vp
#version 140
uniform vs_uniforms {
mediump mat4 mtx_worldview;
mediump mat4 mtx_proj;
};
in mediump vec4 position;
in mediump vec4 color0;
out mediump vec4 var_color;
void main()
{
gl_Position = mtx_proj * mtx_worldview * vec4(position.xyz, 1.0);
var_color = color0;
}This example was created by Defold Foundation.
Download ⤓
Do you want to see more examples? Why not write a few yourself and submit a pull request? We love contributions.
Add example ↗