Three.js Error creating WebGL context

5.6k views Asked by At

Friends, I need your help, the following code in three.js, all return null in this line:

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


function initGL() {

    try {

        var attributes = {
            alpha: _alpha,
            depth: _depth,
            stencil: _stencil,
            antialias: _antialias,
            premultipliedAlpha: _premultipliedAlpha,
            preserveDrawingBuffer: _preserveDrawingBuffer
        };

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

        if ( _gl === null ) {

            throw 'Error creating WebGL context.';

        }

    } catch ( error ) {

        console.error( error );

    }

    _glExtensionTextureFloat = _gl.getExtension( 'OES_texture_float' );

the attributes value:

enter image description here

this is canvas:

enter image description here

Thanks a lot!

~Rosone

1

There are 1 answers

1
Lindy On

I found the reason: It's because another context (canvas.getContext('2d') ) already occupied this same canvas.