Gio,
I was looking at some web gl tutorials on line and wanted to have a go with them in wade.
However, I can't seem to get the webgl context ?
When I try:
console.log(wade.getLayerCanvas().getContext("2d"));
I get the 2d context,
but when I call
console.log(wade.getLayerCanvas().getContext("webgl"));
or
console.log(wade.getLayerCanvas().getContext("experimental-webgl"));
I get null ?
When I call wade.isWebGlSupported() it returns true and my browser seems to run the web gl examples from the tutorial page ok.
So, how do I get the webgl context ?
Or do I even need to get the context as there is another way to approach it in wade ?
Any help you can provide is appreciated.
cheers,
Shri
When I try this in an html page, everything works ok
----------------------------------------------------------------
<body onload="start()"> <canvas id="glcanvas" width="640" height="480"> Your browser doesn't appear to support the HTML5 <code><canvas></code> element. </canvas> <script> var gl; // A global variable for the WebGL context function start() { var canvas = document.getElementById("glcanvas"); gl = initWebGL(canvas); // Initialize the GL context // Only continue if WebGL is available and working if (gl) { console.log('have webgl context'); gl.clearColor(0.0, 0.0, 0.0, 1.0); // Set clear color to black, fully opaque gl.enable(gl.DEPTH_TEST); // Enable depth testing gl.depthFunc(gl.LEQUAL); // Near things obscure far things gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT); // Clear the color as well as the depth buffer. } }; // end start function initWebGL(canvas) { gl = null; try { // Try to grab the standard context. If it fails, fallback to experimental. gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); } catch(e) {} // If we don't have a GL context, give up now if (!gl) { alert("Unable to initialize WebGL. Your browser may not support it."); gl = null; } return gl; }; // end initWebGL </script></body>
When I try this in wade - I get gl is null, no gl context
this.init = function() { console.log('wade global init'); gl = self.initWebGL(wade.getLayerCanvas()); if (gl) { console.log('web gl supported - initializing'); gl.clearColor(0.0, 0.0, 0.0, 1.0); gl.enable(gl.DEPTH_TEST); gl.depthFunc(gl.LEQUAL); gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT); } else { console.log('gl is null, no gl context'); } }; // end init this.initWebGL = function(canvas) { console.log('in init web gl'); gl = null; if (wade.isWebGlSupported()) { console.log('in web gl supported'); var sp = new Sprite(0,wade.defaultLayer); gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); } else { console.log('web gl not supported'); } return gl; }; // end initWebGL