Skip to content

Commit

Permalink
Start refactoring to work in WebGL mode too
Browse files Browse the repository at this point in the history
  • Loading branch information
davepagurek committed Dec 7, 2024
1 parent 584504d commit 876f900
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 163 deletions.
16 changes: 6 additions & 10 deletions preview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,21 @@
import p5 from '../src/app.js';

const sketch = function (p) {
let g, f;
let f;

p.setup = function () {
p.createCanvas(200, 200);
g = p.createGraphics(200, 200);
f = p.createGraphics(200, 200, p.WEBGL);
p.setup = async function () {
// TODO: make this work without a name
f = await p.loadFont('font/BricolageGrotesque-Variable.ttf', 'Bricolage')
p.createCanvas(200, 200, p.WEBGL);
};

p.draw = function () {
p.background(0, 50, 50);
p.circle(100, 100, 50);

p.fill('white');
p.textSize(30);
p.textFont(f)
p.text('hello', 10, 30);

// f.fill('red');
f.sphere();
p.image(f, 0, 0);
};
};

Expand Down
8 changes: 4 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ io(p5);
import math from './math';
math(p5);

// typography
import type from './type'
type(p5);

// utilities
import utilities from './utilities';
utilities(p5);
Expand All @@ -61,6 +57,10 @@ utilities(p5);
import webgl from './webgl';
webgl(p5);

// typography
import type from './type'
type(p5);

import './core/init';

export default p5;
2 changes: 1 addition & 1 deletion src/core/p5.Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ class Renderer {
* Helper function to check font type (system or otf)
*/
_isOpenType(f = this.states.textFont) {
return typeof f === 'object' && f.font && f.font.supported;
return typeof f === 'object' && f.data;
}

_updateTextMetrics() {
Expand Down
Loading

0 comments on commit 876f900

Please sign in to comment.