var canvas = <HTMLCanvasElement>document.getElementById('canvas1');
var gl = canvas.getContext('webgl');
canvas.width = 400;
canvas.height = 400;
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
“HTMLCanvasElement”似乎只提供了2d画布方法。它不会让我编译gl.viewport()等。如何添加对WebGL的支持?
答案 0 :(得分:12)
您需要在使用WebGL方法之前定义它们。您可以找到一些社区编写的WebGL输入here。将WebGL.d.ts添加到项目中并将其命名为:
///<reference path="WebGL.d.ts" />
var canvas = <any>document.getElementById('canvas1');
var gl = <WebGLRenderingContext> canvas.getContext('webgl');
canvas.width = 400;
canvas.height = 400;
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);