New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
textFont() doesn't work for WebGL outside of preload() for loading fonts unlike P2D which isn't specified #7028
Comments
This should be better clarified in the error message since using |
I think this error is misleading but for a different reason: it's allowed in |
Yeah, I didn't differentiate between loading an already loaded font and loading a new font so I changed the updated more specific error msg of the PR to be:
|
Is this true? I think |
That example is of |
I'm not sure I'm following the distinction between an already loaded font and a new font. I don't think we support string font names at all in WebGL, which is what the current error message is trying to say. If you set the font to a string font in preload, I don't think it will have direct behavior even though it doesn't give an error -- it just doesn't know yet that you're trying to create a WebGL sketch. |
Ah, I see. It looks like what's actually going on here is it's creating a WebGL canvas in the preload function before ignoring it and creating a P2D canvas automatically without a Example Code: // WEBGL Example
function preload() {
createCanvas(100, 100, WEBGL); // In WebGL textFont has to be executed in preload
textFont('Courier New');
}
function setup() {
background(200);
textSize(24);
text('hi', 35, 55);
describe('The text "hi" written in a black, monospace font on a gray background.');
} Sketch: https://editor.p5js.org/PotatoBoy/sketches/fSU62FlS3 |
Sorry about that, I didn't know that it would automatically create a P2D canvas alongside the WebGL canvas explicitly created and then use that instead if I tried to use |
Ah ok, yeah it's pretty confusing that that example still renders a canvas! Just the wrong one. Definitely open to suggestions on how to make that clearer (maybe catching instances of canvases created in preload, since I think the library assumes it will only be made in setup?) |
Yeah, adding a check for whether or not a canvas has been created in |
Most appropriate sub-area of p5.js?
p5.js version
1.9.3
Web browser and version
115.6.0esr
Operating system
Debian 12
Steps to reproduce this
Steps:
textFont
as requested by the error, but not in thepreload()
function:WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` for more details.
WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` for more details.
Snippet:
The text was updated successfully, but these errors were encountered: