var vshader_src =
'attribute vec4 a_Position;\n\
void main() {\n\
gl_Position = a_Position ;\n\
gl_PointSize = 10.0;\n\
}';
var fshader_src =
'precision mediump float;\n\
uniform vec4 u_FragColor;\n\
void main() {\n\
gl_FragColor = u_FragColor;\n\
}';
function main() {
var canvas = document.getElementById("webgl");
var gl = getWebGLContext(canvas, true);
if (!gl) {
alert("Failed at getWebGLContext");
return;
}
if (!initShaders(gl, vshader_src, fshader_src)) {
alert("Failed at initShaders");
return;
}
var n = initVertexBuffers(gl);
gl.clearColor(0, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.POINTS, 0, n);
}
function initVertexBuffers(gl){
var vertices = new Float32Array([0.0,0.5,-0.5,-0.5,0.5,-0.5]);
var n = 3;
var vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER,vertices,gl.STATIC_DRAW);
var a_Position = gl.getAttribLocation(gl.program,'a_Position');
gl.vertexAttribPointer(a_Position,2,gl.FLOAT,false,0,0);
gl.enableVertexAttribArray(a_Position);
return n;
}
04-12