question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebGL extract giving empty image

See original GitHub issue

I’m trying to use the WebGLExtract class to create screenshots, but am getting a black image instead (of the correct dimensions).

    var sourceCanvas = renderer.extract.canvas();
    var sourceContext = sourceCanvas.getContext('2d');
    var extractCanvas = document.createElement('canvas');
    var extractContext = extractCanvas.getContext('2d');
    var imageData = sourceContext.getImageData(x, y, width, height);

    extractCanvas.width = width;
    extractCanvas.height = height;
    extractContext.putImageData(imageData, 0, 0);
    return extractCanvas.toDataURL();

I’ve also tried just accessing sourceCanvas.toDataURL() directly, but with the same results. Any chance I’ve forgotten something obvious?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
ivanpopelyshevcommented, Mar 25, 2017

It can happen in some cases, but if you pass your stage there, and it gets imageData just after rendering it - I’m sure it’ll work.

renderer.extract.canvas(stage);

And if you are friday-night-drunk and forgot where is your stage

renderer.extract.canvas(renderer._lastObjectRendered);
1reaction
hackergrrlcommented, Apr 17, 2017

@ivanpopelyshev That did it! Thank you so much. ❤️ And thanks @englercj for poking me on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebGL extract giving empty image · Issue #3880 - GitHub
I'm trying to use the WebGLExtract class to create screenshots, but am getting a black image instead (of the correct dimensions). var ...
Read more >
HTML Save WebGL Canvas as Image - Stack Overflow
The reason the webgl canvas is blank has been answered at least 10 times here on stackoverflow. Saving canvas to image via canvas....
Read more >
CanvasRenderingContext2D.getImageData() - Web APIs | MDN
This example draws an image, and then uses getImageData() to grab a portion of the canvas. We use getImageData() to extract a slice...
Read more >
WebGL - Quick Guide - Tutorialspoint
To create an empty buffer object, WebGL provides a method called createBuffer(). This method returns a newly created buffer object, if the creation...
Read more >
Fabric.js filtering overview — Fabric.js Javascript Canvas Library
Webgl context is more complicated to handle than canvas2d context. To be filtered images needs to be put in a texture. Texture size...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found