2626import processing .core .PApplet ;
2727import processing .core .PConstants ;
2828import processing .core .PFont ;
29+ import processing .core .PGraphics ;
2930import processing .core .PImage ;
3031
3132import java .util .HashMap ;
@@ -50,8 +51,8 @@ class FontTexture implements PConstants {
5051 protected PGL pgl ;
5152 protected boolean is3D ;
5253
53- protected int maxTexWidth ;
54- protected int maxTexHeight ;
54+ protected int minSize ;
55+ protected int maxSize ;
5556 protected int offsetX ;
5657 protected int offsetY ;
5758 protected int lineHeight ;
@@ -62,12 +63,11 @@ class FontTexture implements PConstants {
6263 protected TextureInfo [] glyphTexinfos ;
6364 protected HashMap <PFont .Glyph , TextureInfo > texinfoMap ;
6465
65- public FontTexture (PGraphicsOpenGL pg , PFont font , int maxw , int maxh ,
66- boolean is3D ) {
66+ public FontTexture (PGraphicsOpenGL pg , PFont font , boolean is3D ) {
6767 pgl = PGraphicsOpenGL .pgl ;
6868 this .is3D = is3D ;
6969
70- initTexture (pg , font , maxw , maxh );
70+ initTexture (pg , font );
7171 }
7272
7373
@@ -84,13 +84,21 @@ protected void dispose() {
8484 }
8585
8686
87- protected void initTexture (PGraphicsOpenGL pg , PFont font , int w , int h ) {
88- maxTexWidth = w ;
89- maxTexHeight = h ;
90-
87+ protected void initTexture (PGraphicsOpenGL pg , PFont font ) {
9188 currentTex = -1 ;
9289 lastTex = -1 ;
9390
91+ int spow = PGL .nextPowerOfTwo (font .getSize ());
92+ minSize = PApplet .min (PGraphicsOpenGL .maxTextureSize ,
93+ PApplet .max (PGL .MIN_FONT_TEX_SIZE , spow ));
94+ maxSize = PApplet .min (PGraphicsOpenGL .maxTextureSize ,
95+ PApplet .max (PGL .MAX_FONT_TEX_SIZE , 2 * spow ));
96+
97+ if (maxSize < spow ) {
98+ PGraphics .showWarning ("The font size is too large to be properly " +
99+ "displayed with OpenGL" );
100+ }
101+
94102 addTexture (pg );
95103
96104 offsetX = 0 ;
@@ -107,15 +115,14 @@ public boolean addTexture(PGraphicsOpenGL pg) {
107115 int w , h ;
108116 boolean resize ;
109117
110- w = maxTexWidth ;
111- if (-1 < currentTex && textures [currentTex ].glHeight < maxTexHeight ) {
118+ w = maxSize ;
119+ if (-1 < currentTex && textures [currentTex ].glHeight < maxSize ) {
112120 // The height of the current texture is less than the maximum, this
113121 // means we can replace it with a larger texture.
114- h = PApplet .min (2 * textures [currentTex ].glHeight , maxTexHeight );
122+ h = PApplet .min (2 * textures [currentTex ].glHeight , maxSize );
115123 resize = true ;
116124 } else {
117- h = PApplet .min (PGraphicsOpenGL .maxTextureSize , PGL .MAX_FONT_TEX_SIZE / 2 ,
118- maxTexHeight / 4 );
125+ h = minSize ;
119126 resize = false ;
120127 }
121128
0 commit comments