# hint(DISABLE\_DEPTH\_TEST) in P5

**URL:** <https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595>\
**Category:** p5.js\
**Created:** [November 16, 2018, 11:28am UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595 "2018-11-16T11:28:20Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![FedFod](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fedfod/32/2312_2.png) [@FedFod](https://discourse.processing.org/u/FedFod)\
**Post date:** [November 16, 2018, 11:28am UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/1 "2018-11-16T11:28:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [November 16, 2018, 11:45am UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/2 "2018-11-16T11:45:25Z")

</div>

It’s not easy to find 🙂

> <https://github.com/processing/p5.js/issues/1507#issuecomment-401862739>

  
See also [the example](https://github.com/processing/p5.js/issues/1507#issuecomment-416626722).

---

<div class="post-metadata">

**Author:** ![FedFod](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fedfod/32/2312_2.png) [@FedFod](https://discourse.processing.org/u/FedFod)\
**Post date:** [November 16, 2018, 11:51am UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/3 "2018-11-16T11:51:30Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![FedFod](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fedfod/32/2312_2.png) [@FedFod](https://discourse.processing.org/u/FedFod)\
**Post date:** [November 16, 2018, 11:53am UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/4 "2018-11-16T11:53:05Z")

</div>

Just realised that it doesn’t work in run time, must be set in the setup() function apparently. Solved! Sorry for the fuss

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [November 16, 2018, 12:20pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/5 "2018-11-16T12:20:37Z")

</div>

> [@FedFod](#):
>
> Just realised that it doesn’t work in run time

For me it works (click to toggle):

```auto
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](https://editor.p5js.org/abe/sketches/rJm884hTQ)

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [November 16, 2018, 12:30pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/6 "2018-11-16T12:30:21Z")

</div>

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](https://editor.p5js.org/abe/sketches/HkT9P4367)

If you have an answer to the original GitHub question you could answer it there 🙂

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 16, 2018, 12:36pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/7 "2018-11-16T12:36:24Z")

</div>

> [@hamoid](#):
>
> `gl = document.getElementById('defaultCanvas0').getContext('webgl');`

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

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [November 16, 2018, 1:46pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/8 "2018-11-16T13:46:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 16, 2018, 2:05pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/9 "2018-11-16T14:05:11Z")

</div>

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);`

---

<div class="post-metadata">

**Author:** ![FedFod](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fedfod/32/2312_2.png) [@FedFod](https://discourse.processing.org/u/FedFod)\
**Post date:** [November 16, 2018, 2:55pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/10 "2018-11-16T14:55:03Z")

</div>

```auto
gl = canvas.getContext(WEBGL);

```

canvas returns undefined

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 16, 2018, 2:59pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/11 "2018-11-16T14:59:58Z")

</div>

R u sure you’re passing the constant WEBGL as the 3rd argument for **createCanvas()** before the statement `gl = canvas.getContext(WEBGL);`? 🙄

---

<div class="post-metadata">

**Author:** ![FedFod](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fedfod/32/2312_2.png) [@FedFod](https://discourse.processing.org/u/FedFod)\
**Post date:** [November 16, 2018, 3:01pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/12 "2018-11-16T15:01:12Z")

</div>

```auto
    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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 16, 2018, 3:27pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/13 "2018-11-16T15:27:01Z")

</div>

> [@FedFod](#):
>
> `canvas2 = mCreateCanvas(m4.windowWidth, m4.windowHeight, m4.WEBGL);`

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! 😲

> [@FedFod](#):
>
> `glCanvas = canvas.getContext(WEBGL);`

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);`

---

<div class="post-metadata">

**Author:** ![FedFod](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fedfod/32/2312_2.png) [@FedFod](https://discourse.processing.org/u/FedFod)\
**Post date:** [November 16, 2018, 3:30pm UTC](https://discourse.processing.org/t/hint-disable-depth-test-in-p5/5595/14 "2018-11-16T15:30:34Z")

</div>

This works like a charm mate, thank you
