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.

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() {

	fill(255, 200, 30);
	rotateY(frameCount * 0.01);
	fill(30, 200, 255);
	rotateY(PI * 0.25);
function mousePressed() {
	if(b) {
	} else {
	b = !b;

Run it at https://editor.p5js.org/abe/sketches/rJm884hTQ


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

Here it is changed inside draw:

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


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(). :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);

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

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

This works like a charm mate, thank you