10
09/2014
webgl threejs
babylonjs 和 threejs 都是 webgl 框架
3D cube
<script src="/labs/three.min.js"></script> <!--初始化 three--> <script src="/labs/threejs-detector.js"></script> <!--检测是否支持 webgl--> <div id="earth" style="height:300px;"></div> <!--容器--> <script src="/labs/three-cube.js"></script> <!--代码-->
webgl 环境检测
canvas: !! window.CanvasRenderingContext2D, webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )(), workers: !! window.Worker, fileapi: window.File && window.FileReader && window.FileList && window.Blob,
- canvas 检查 window.CanvasRenderingContext2D
- webgl 检查 window.WebGLRenderingContext 以及 canvas.getContext( ‘webgl’ ) 或者 canvas.getContext( ‘experimental-webgl’ )
- workers 检查 window.Worker
- fileapi 检查 window.File 以及 window.FileReader 以及 window.FileList 以及 window.Blob