0

I want to set context of canvas1 to canvas2.
I saw here - https://developers.whatwg.org/the-canvas-element.html#dom-canvas-setcontext
that setContext() is supported but I get an error of undefined function in chrome.

      var canvas1 = document.getElementById("myCanvas1");
      var canvas2 = document.getElementById("myCanvas2");
      ctx1 = canvas1.getContext("webgl");
      var gl = canvas2.setContext(ctx1);

why it happened? how can I set context of canvas from another canvas's context?

DASA
  • 11
  • 4

1 Answers1

1

Currently this feature is not supported by any browser.

The whatwg documentation is about standards, but not all the standards are currently supported by browsers. I recommend you to check caniuse and MDN to verify the actual support.

nicokant
  • 483
  • 4
  • 12
  • what's exactly your purpose? Do you want your `canvas2` to be an exact copy of `canvas1`? – nicokant May 25 '17 at 13:06
  • I want to create canvas 2 with the same context as canvas 1, but then each one of them will act standalone. Not mirror 1 in 2. – DASA May 25 '17 at 13:24
  • That's a contradiction, if they share the same context (same frame buffer, same render buffer) how could they act differently? I don't think that there is a workaround, what you want to do seems to be really tight coupled with the DOM implementation. – nicokant May 25 '17 at 13:41
  • I have a texture that belong to canvas1, when Im trying to render it from canvas2 I get an errro that "object not belong to this context". So Im trying to find a workaround - any idea? – DASA May 25 '17 at 13:47
  • 1
    This may be of help: https://stackoverflow.com/questions/9122361/is-it-possible-to-have-two-webgl-contexts-on-the-same-page – nicokant May 25 '17 at 13:52