Skip to content
This repository was archived by the owner on May 28, 2022. It is now read-only.

Commit 7a97cb3

Browse files
Bjorn SandvikBjorn Sandvik
Bjorn Sandvik
authored and
Bjorn Sandvik
committed
Added WebGL browser check
1 parent 89c0f9d commit 7a97cb3

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

index.html

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<style>
88
body { margin: 0; overflow: hidden; background-color: #000; }
99
.tm { position: absolute; top: 10px; right: 10px; }
10+
.webgl-error { font: 15px/30px monospace; text-align: center; color: #fff; margin: 50px; }
11+
.webgl-error a { color: #fff; }
1012
</style>
1113
</head>
1214
<body>
@@ -15,6 +17,7 @@
1517
<img src="http://earthatlas.info/img/thematicmapping.png">
1618
</a>
1719
<script src="js/three.min.js"></script>
20+
<script src="js/Detector.js"></script>
1821
<script src="js/TrackballControls.js"></script>
1922
<script src="js/earth.js"></script>
2023
</body>

js/Detector.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @author alteredq / http://alteredqualia.com/
3+
* @author mr.doob / http://mrdoob.com/
4+
*/
5+
6+
var Detector = {
7+
8+
canvas: !! window.CanvasRenderingContext2D,
9+
webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )(),
10+
workers: !! window.Worker,
11+
fileapi: window.File && window.FileReader && window.FileList && window.Blob,
12+
13+
getWebGLErrorMessage: function () {
14+
15+
var element = document.createElement( 'div' );
16+
element.className = 'webgl-error';
17+
18+
if ( !this.webgl ) {
19+
20+
element.innerHTML = window.WebGLRenderingContext ? [
21+
'Your graphics card does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>.<br />',
22+
'Find out how to get it <a href="http://get.webgl.org/">here</a>.'
23+
].join( '\n' ) : [
24+
'Your browser does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>.<br/>',
25+
'Find out how to get it <a href="http://get.webgl.org/">here</a>.'
26+
].join( '\n' );
27+
28+
}
29+
30+
return element;
31+
32+
},
33+
34+
addGetWebGLMessage: function (parent ) {
35+
36+
parent.appendChild( Detector.getWebGLErrorMessage() );
37+
38+
}
39+
40+
};

js/earth.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// Created by Bjorn Sandvik - thematicmapping.org
22
(function () {
33

4+
var webglEl = document.getElementById('webgl');
5+
6+
if (!Detector.webgl) {
7+
Detector.addGetWebGLMessage(webglEl);
8+
return;
9+
}
10+
411
var width = window.innerWidth,
512
height = window.innerHeight;
613

@@ -36,7 +43,7 @@
3643

3744
var controls = new THREE.TrackballControls(camera);
3845

39-
document.getElementById('webgl').appendChild(renderer.domElement);
46+
webglEl.appendChild(renderer.domElement);
4047

4148
render();
4249

0 commit comments

Comments
 (0)