Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error when using WebGLRenderer() with jsdom

I'm trying to render a cube on server side, and was able to do so using the CanvasRenderer, but i want to be able to render it with WebGLRenderer, which should produce better results. i've narrowed it down to this code snippet:

var jsdom = require('jsdom')
, document = jsdom.jsdom('<!doctype html><html><head></head><body></body></html>')
, window = document.createWindow()
, THREE = require('three');

document.onload = docOnLoad();

function docOnLoad()
{
    console.log("docOnLoad called.");
    global.document = document;
    global.window = window;
    //renderer = new THREE.CanvasRenderer(); //works
    renderer = new THREE.WebGLRenderer();
    renderer.setSize(400, 400);
    document.body.appendChild(renderer.domElement);     
}

When using the WebGLRenderer, i got:

_glExtensionTextureFloat = _gl.getExtension( 'OES_texture_float');
                               ^
TypeError: Cannot call method 'getExtension' of undefined
    at initGL (C:\programming\nodejs\node_modules\three\three.js:25870:34)

when trying to debug three.js code, console.log(_gl) indeed shows that _gl is undefined, and the source of it is line #25856, where:

_gl = _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );

now, console.log() of _canvas shows: [Canvas 0x0]

Has anyone encountered something similar?

like image 247
bks Avatar asked Feb 20 '26 12:02

bks


1 Answers

Usually happens when you already obtained a 2D context from _canvas. Both 2D context and gl cannot be obtained from the same canvas. If this is not the case, can you confirm if you are able to successfully run any other WebGL example independently (from node.js) ?

like image 111
Prabindh Avatar answered Feb 22 '26 02:02

Prabindh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!