Skip to content
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

Added WebGL text error and textFont documentation update #7029

Conversation

RandomGamingDev
Copy link
Contributor

@RandomGamingDev RandomGamingDev commented May 9, 2024

Resolves #7028

Changes:

Replaced the previously vague error:

WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` for more details.

with

WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` (both of which have to be executed in preload() for WebGL mode when loading a new font) for more details.

and updated textFont()'s page to have a WEBGL example:

// 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.');
}

Screenshots of the change:

PR Checklist

@RandomGamingDev
Copy link
Contributor Author

RandomGamingDev commented May 10, 2024

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 createCanvas() statement which is how the font's actually getting loaded with no errors reporting what happened.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

textFont() doesn't work for WebGL outside of preload() for loading fonts unlike P2D which isn't specified
1 participant