computer-graphics-study/index.ts
2021-09-02 18:16:43 +09:00

25 lines
712 B
TypeScript

/// <reference path="node_modules/webgl-strict-types/index.d.ts" />
function main(){
const canvas = document.querySelector("canvas");
if(canvas === null){
console.error("couldn't find canvas");
return;
}
let gl = canvas.getContext("webgl2");
if(gl === null){
console.error("webgl2 is not supported!");
return;
}
const position = [
-0.5,-0.5,
0.0,0.5,
0.5,-0.5
];
let positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,positionBuffer);
const floatPosition = new Float32Array(position);
gl.bufferData(gl.ARRAY_BUFFER,floatPosition,gl.STATIC_DRAW);
gl.drawArrays(gl.TRIANGLES,0,3);
}
main();