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!
Itâs not easy to find
See also the example.
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