I thought it would be a simple question to find the answer, but it turned out to be very elusive. Basically, I'm trying to use WebGL for hard work on some of the processing and image generation tasks, and I want it to work on screen. Ideally, I would like WebGL to display the scene in a framebuffer with which I can gl.readPixels(), or on the webgl canvas so that I can use it as a source for context.drawImage(). The fact is that I do not want to display the webgl canvas itself, I only want to copy parts of it to a visible canvas, for which I use the usual "2d" context. So far, I can't get it to work without the following initialization, which seems like an ugly handle to me:
glCanvas = document.createElement('canvas');
glCanvas.width = 256;
glCanvas.height = 256;
document.body.appendChild(glCanvas);
glCanvas.style.visibility = 'hidden';
I am currently creating a scene for a framebuffer created with: gl.createFramebuffer()using one call gl.drawArrays()and then using gl.readPixels()to get the result in ImageData. With glCanvas attached to the DOM, it works exactly as planned. But if I leave these last 2 lines of code above, where I attach glCanvas and hide it, I don’t get the image when I try to read the Pixels from the framebuffer that I displayed.
, glCanvas DOM, . , framebuffer . , WebGL , webgl-, DOM? ? !