how to draw a pink rectangle
const geometry = new PIXI.Geometry();
geometry.addAttribute("position", [0, 0, 1, 0, 1, 1, 0, 1], 2);
geometry.addIndex([0, 1, 2, 0, 2, 3]);
reads:
1 - create a Vertex Buffer Object that contains 4, 2D points ( a unit square with top left corner at 0,0 ) as a flat array.
2 - create an Index Buffer Object that describes 2 faces.
face 1 links vertices 0=>1=>2 and face 2 links vertices 0=>2=>3
precision highp float; // magic, don't touch
// the attribute values passed from the CPU
attribute vec2 position;
// the program itself
void main() {
//transform or project the coordinates onto a bi-unit square
gl_Position = vec4( position, 0.0, 1.0);
// when using gl.POINTS we should set the point size:
gl_PointSize = 3.;
}
gl_Positions
precision highp float; // magic, don't touch
void main() {
// paint each pixel grey
gl_FragColor = vec4(0.5, 0.5, 0.5, 1.);
}
// VERTEX
attribute vec2 position;
// a color attribute, associated with each vertex
attribute vec3 color;
// a varying to pass the color to the fragment shader
varying vec3 vColor;
void main() {
// this is a color value associated to each vertex
// it will be interpolated in the fragment shader
vColor = color;
gl_Position = vec4( position, 0.0, 1.0);
}
// FRAGMENT
varying vec3 vColor; //our varying color
void main() {
// paint each pixel with the varying color
gl_FragColor = vec4( vColor, 1.);
}
// VERTEX
attribute vec2 position;
attribute vec3 color;
varying vec3 vColor;
// the third variable type: uniform is passed to both shaders
uniform float time;
void main() {
//use the time uniform to move the vertices around
vec2 pos = position + vec2( cos( time ), sin( time ) );
vColor = color;
gl_Position = vec4( pos, 0.0, 1.0);
}
// FRAGMENT
uniform float time;
varying vec3 vColor;
void main() {
//use the time uniform to change the opacity
gl_FragColor = vec4( vColor, abs( sin( time ) ) );
}