-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebgl-context-v1.0.min.js
14 lines (14 loc) · 1.74 KB
/
webgl-context-v1.0.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var canvas,gl,width,height,RESOLUTION=0.5;function setup(){canvas=document.getElementsByTagName("canvas")[0];if(!canvas){console.error("ERROR: No canvas found.");return!1}
gl=canvas.getContext("webgl",{antialias:!1});if(!gl){console.warn("WARNING: falling back on experimental webgl.");gl=canvas.getContext("experimental-webgl",{antialias:!1})}
if(!gl){console.error("ERROR: WebGL not supported by browser.");return!1}
resize();clear();return!0}
function fontDefine(){let fontString="";for(let i=0;i<arguments.length;i++){let font=arguments[i].split(" ");for(let j=0;j<font.length;j++){fontString+=font[j];if(j!==font.length-1){fontString+="+"}}
if(i!==arguments.length-1){fontString+="|"}}
let fonts=document.getElementById("fonts");if(fonts){fonts.parentNode.removeChild(fonts)}else{let link=document.createElement("link");link.id="fonts";link.rel="stylesheet";link.type="text/css";link.href="https://fonts.googleapis.com/css?family="+fontString;document.getElementsByTagName("head")[0].appendChild(link)}
return!0}
function clear(buffer,color){if(!color){gl.clearColor(0.0,0.0,0.0,1.0)}else{if(color.length!==4){console.error("ERROR: Incorrect color specification at clear().");return!1}
gl.clearColor(color[0],color[1],color[2],color[3])}
if(!buffer){gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT)}else{if(buffer==="color"){gl.clear(gl.COLOR_BUFFER_BIT)}
if(buffer==="depth"){gl.clear(gl.DEPTH_BUFFER_BIT)}
if(buffer!=="color"||buffer!=="depth"){console.error("ERROR: Incorrect buffer specification at clear().");return!1}}
return!0};function resize(){canvas.width=window.innerWidth*RESOLUTION;canvas.height=window.innerHeight*RESOLUTION;width=window.innerWidth*RESOLUTION;height=window.innerHeight*RESOLUTION;gl.viewport(0,0,width,height)};setup();window.onresize=resize