hint(DISABLE_DEPTH_TEST) in P5

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!

1 Like

It’s not easy to find :slight_smile:


See also the example.

1 Like

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

3 Likes

I don’t want to pollute the GitHub issue with more examples :slight_smile:

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 :slight_smile:

3 Likes

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.

3 Likes

@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.

1 Like

Indeed undocumented variable drawingContext seems to always be a CanvasRenderingContext2D, regardless we choose WEBGL for createCanvas(). :open_mouth:

However, I’ve listed other undocumented variables as well. :stuck_out_tongue_winking_eye:

Among them, undocumented variable canvas: :smile_cat:
gl = canvas.getContext(WEBGL);

2 Likes
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);? :roll_eyes:

1 Like
    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. :thinking:

Clearly you’re using p5js’ so-called “instance mode”. :face_with_hand_over_mouth:

However, you’re not doing the same for the p5::canvas property! :astonished:

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: :nerd_face:

glCanvas = m4.canvas.getContext(WEBGL);

1 Like

This works like a charm mate, thank you