Hey everybody, do you know how to get the same functionality of the hint function in P5? Cannot seem to find it anywhere. Thank you!
Thank you hamoid! I just replied you there. It seems not to have any effect on my sketch.
I’m declaring my canvas like this:
canvas2 = mCreateCanvas(m4.windowWidth, m4.windowHeight, m4.WEBGL);
m4.setAttributes('antialias', true);
glCanvas = document.getElementById('defaultCanvas0').getContext('webgl');
I’ve checked the id, and it is ‘defaultCanvas0’ so everything should be okay. Working on instance mode with multiple setches
Just realised that it doesn’t work in run time, must be set in the setup() function apparently. Solved! Sorry for the fuss
For me it works (click to toggle):
var gl;
var b = true;
function setup() {
createCanvas(400, 400, WEBGL);
gl = document.getElementById('defaultCanvas0').getContext('webgl');
}
function draw() {
background(0);
noStroke();
fill(255, 200, 30);
rotateY(frameCount * 0.01);
box(200);
fill(30, 200, 255);
rotateY(PI * 0.25);
box(200);
}
function mousePressed() {
if(b) {
gl.disable(gl.DEPTH_TEST);
} else {
gl.enable(gl.DEPTH_TEST);
}
b = !b;
}
Run it at p5.js Web Editor
I don’t want to pollute the GitHub issue with more examples
Here it is changed inside draw:
https://editor.p5js.org/abe/sketches/HkT9P4367
If you have an answer to the original GitHub question you could answer it there
Shortest way to reach the sketch’s canvas rendering context is via undocumented variable drawingContext:
gl = drawingContext;
The canvas itself is under undocumented variable canvas.
And its wrapper is under both undocumented variables _renderer & _curElement.
@GoToLoop did you try that?
Because drawingContext != document.getElementById('defaultCanvas0').getContext('webgl');
The first one is a CanvasRenderingContext2D
and the second one a WebGLRenderingContext
, so gl = drawingContext;
does not work here.
Indeed undocumented variable drawingContext seems to always be a CanvasRenderingContext2D, regardless we choose WEBGL for createCanvas().
However, I’ve listed other undocumented variables as well.
Among them, undocumented variable canvas:
gl = canvas.getContext(WEBGL);
gl = canvas.getContext(WEBGL);
canvas returns undefined
R u sure you’re passing the constant WEBGL as the 3rd argument for createCanvas() before the statement gl = canvas.getContext(WEBGL);
?
canvas2 = mCreateCanvas(m4.windowWidth, m4.windowHeight, m4.WEBGL);
m4.setAttributes('antialias', true);
// m4.print(canvas2)
// glCanvas = document.getElementById('defaultCanvas0').getContext('webgl');
glCanvas = canvas.getContext(WEBGL);
that’s what I’m doing. Working with 2 contexts in instance mode
You’re accessing p5 property members via a variable named m4.
Clearly you’re using p5js’ so-called “instance mode”.
However, you’re not doing the same for the p5::canvas property!
Given p5::canvas isn’t in the global window either, you’re gonna need that m4 variable of datatype p5 in order to reach the undocumented property p5::canvas as well:
glCanvas = m4.canvas.getContext(WEBGL);
This works like a charm mate, thank you