Let's say we have a class called Render with a constructor that needs the window variable to create a canvas and the WebGL context:
class Render
{
constructor(WINDOW=window)
{
this.window = WINDOW
this.canvas = this.window.document.createElement("canvas")
this.gl = this.canvas.getContext("webgl2")
// after that there's some other code but has no relation with the above
}
}
when I make a 2D Context, everything works fine, but for WebGL, it returns null in the class.
I've tried:
- a parameter for WebGL and/or the canvas:
class Render
{
constructor(WINDOW=window,webgl,canvas)
}
- a method resetting the canvas, the 2D and WebGL context
- a function outside the class which creates a canvas
- porting my code to browser (same result)
These are the webPreferences I enabled:
nodeIntegration noteIntegrationInWorker enableRemoteModule webgl
Am I doing something wrong?
EDIT:
does webgl2 work on Chrome on the same machine?
Yes, going to https://get.webgl.org/ show me a rotating cube and "Your browser supports WebGL". At about:gpu in Chrome also shows that WebGL and WebGL2 are enabled.
does webgl1 work in Electron on the same machine?
Yes, I already tried that but same result.
open a window to about:gpu in Electron and see what it says
Interesting, it's says that webgl and webgl2 are disabled, even though in webPreferences webgl is set to true, but now there's something else i noticed:
When I start the app, it's says to the render property for webgl context null, right? BUT if I create a canvas in the console and get the Context, it returns the webgl/webgl2 context. Very weird
EDIT 2:
Um, I solved it? Looks like a canvas cannot have a 2D Context AND a Webgl context at the same time...