Jak mogę dodać wsparcie dla przeglądarki, takich jak WebGL na maszynie?

głosy
6
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);

W „HTMLCanvasElement” wydaje się tylko do zaoferowania 2d metod płótnie. To nie pozwoli mi skompilować gl.viewport () itd. W jaki sposób mogę dodać wsparcie dla WebGL?

Utwórz 08/10/2012 o 06:14
źródło użytkownik
W innych językach...                            


1 odpowiedzi

głosy
10

Trzeba zdefiniować metody WebGL przed ich użyciem. Można znaleźć społeczności napisany WebGL pisać tutaj . Dodać WebGL.d.ts do projektu i nazywają to tak:

///<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);
Odpowiedział 08/10/2012 o 06:38
źródło użytkownik

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more