javascript - Why is my webGL context returning as null, but also showing that it was retrieved? -


i'm starting on webgl , i'm little confused something. i'm getting context in try/catch , i'm showing try successful, however, i'm showing context null. can explain me why is? according tutorial, should seeing black box, i'm not.

html

<body>     <canvas id="webgl" width="500" height="500"></canvas> </body> 

js

window.addeventlistener("load", function(){     start();     var gl;//holds webgl context     function start(){         var canvas = document.getelementbyid("webgl");         gl = initwebgl(canvas);//initializes gl context         if(gl){             gl.clearcolor(0.0, 0.0, 0.0, 1.0);//sets clear color black             gl.enable(gl.depth_test);//enables depth testing             gl.depthfunc(gl.lequal);//near things obsure far things             gl.clear(gl.color_buffer_bit | gl.depth_buffer_bit);//clears color , depth buffer         }     }      function initwebgl(canvas){         gl = null;         try{             //tries grab standard context.  if fails, fallback experimental version             gl = canvas.getcontext("webgl") || canvas.getcontext("experimental-webgl");             console.log("got it");             console.log(gl);         }         catch(e){             //if there no gl context, give             if(!gl){                 gl = null;                 console.log("you suck");                 console.log(gl);             }         }         return gl;     } }) 

here's pen see what's happening.

your calling depthfunc when should call depthfunc


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -