diff --git a/core/src/processing/opengl/FontTexture.java b/core/src/processing/opengl/FontTexture.java index c14367e15..2a9fbadeb 100644 --- a/core/src/processing/opengl/FontTexture.java +++ b/core/src/processing/opengl/FontTexture.java @@ -26,6 +26,7 @@ package processing.opengl; import processing.core.PApplet; import processing.core.PConstants; import processing.core.PFont; +import processing.core.PGraphics; import processing.core.PImage; import java.util.HashMap; @@ -50,8 +51,8 @@ class FontTexture implements PConstants { protected PGL pgl; protected boolean is3D; - protected int maxTexWidth; - protected int maxTexHeight; + protected int minSize; + protected int maxSize; protected int offsetX; protected int offsetY; protected int lineHeight; @@ -62,12 +63,11 @@ class FontTexture implements PConstants { protected TextureInfo[] glyphTexinfos; protected HashMap texinfoMap; - public FontTexture(PGraphicsOpenGL pg, PFont font, int maxw, int maxh, - boolean is3D) { + public FontTexture(PGraphicsOpenGL pg, PFont font, boolean is3D) { pgl = PGraphicsOpenGL.pgl; this.is3D = is3D; - initTexture(pg, font, maxw, maxh); + initTexture(pg, font); } @@ -84,13 +84,21 @@ class FontTexture implements PConstants { } - protected void initTexture(PGraphicsOpenGL pg, PFont font, int w, int h) { - maxTexWidth = w; - maxTexHeight = h; - + protected void initTexture(PGraphicsOpenGL pg, PFont font) { currentTex = -1; lastTex = -1; + int spow = PGL.nextPowerOfTwo(font.getSize()); + minSize = PApplet.min(PGraphicsOpenGL.maxTextureSize, + PApplet.max(PGL.MIN_FONT_TEX_SIZE, spow)); + maxSize = PApplet.min(PGraphicsOpenGL.maxTextureSize, + PApplet.max(PGL.MAX_FONT_TEX_SIZE, 2 * spow)); + + if (maxSize < spow) { + PGraphics.showWarning("The font size is too large to be properly " + + "displayed with OpenGL"); + } + addTexture(pg); offsetX = 0; @@ -107,15 +115,14 @@ class FontTexture implements PConstants { int w, h; boolean resize; - w = maxTexWidth; - if (-1 < currentTex && textures[currentTex].glHeight < maxTexHeight) { + w = maxSize; + if (-1 < currentTex && textures[currentTex].glHeight < maxSize) { // The height of the current texture is less than the maximum, this // means we can replace it with a larger texture. - h = PApplet.min(2 * textures[currentTex].glHeight, maxTexHeight); + h = PApplet.min(2 * textures[currentTex].glHeight, maxSize); resize = true; } else { - h = PApplet.min(PGraphicsOpenGL.maxTextureSize, PGL.MAX_FONT_TEX_SIZE / 2, - maxTexHeight / 4); + h = minSize; resize = false; } diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 0c0d496f6..ba513c90b 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -127,7 +127,8 @@ public class PGL { */ protected static final int FLUSH_VERTEX_COUNT = MAX_VERTEX_INDEX1; - /** Maximum dimension of a texture used to hold font data. **/ + /** Minimum/maximum dimensions of a texture used to hold font data. **/ + protected static final int MIN_FONT_TEX_SIZE = 256; protected static final int MAX_FONT_TEX_SIZE = 1024; /** Minimum stroke weight needed to apply the full path stroking diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 509d5ff95..a8a2aa2dc 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -3278,12 +3278,10 @@ public class PGraphicsOpenGL extends PGraphics { textTex = pgPrimary.getFontTexture(textFont); if (textTex == null || textTex.contextIsOutdated()) { - textTex = new FontTexture(pgPrimary, textFont, - PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), - PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), is3D()); + textTex = new FontTexture(pgPrimary, textFont, is3D()); pgPrimary.setFontTexture(textFont, textTex); } - + textTex.begin(); // Saving style parameters modified by text rendering. diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java index 1792399d9..b3e4955c0 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java @@ -124,7 +124,8 @@ public class PGL extends processing.opengl.PGL { */ protected static final int FLUSH_VERTEX_COUNT = MAX_VERTEX_INDEX1; - /** Maximum dimension of a texture used to hold font data. **/ + /** Minimum/maximum dimensions of a texture used to hold font data. **/ + protected static final int MIN_FONT_TEX_SIZE = 256; protected static final int MAX_FONT_TEX_SIZE = 1024; /** Minimum stroke weight needed to apply the full path stroking