@@ -59,7 +59,6 @@ class FontTexture implements PConstants {
59
59
protected int lineHeight ;
60
60
protected Texture [] textures = null ;
61
61
protected PImage [] images = null ;
62
- protected int currentTex ;
63
62
protected int lastTex ;
64
63
protected TextureInfo [] glyphTexinfos ;
65
64
protected HashMap <PFont .Glyph , TextureInfo > texinfoMap ;
@@ -86,7 +85,6 @@ protected void dispose() {
86
85
87
86
88
87
protected void initTexture (PGraphicsOpenGL pg , PFont font ) {
89
- currentTex = -1 ;
90
88
lastTex = -1 ;
91
89
92
90
int spow = PGL .nextPowerOfTwo (font .getSize ());
@@ -117,10 +115,10 @@ public boolean addTexture(PGraphicsOpenGL pg) {
117
115
boolean resize ;
118
116
119
117
w = maxSize ;
120
- if (-1 < currentTex && textures [currentTex ].glHeight < maxSize ) {
118
+ if (-1 < lastTex && textures [lastTex ].glHeight < maxSize ) {
121
119
// The height of the current texture is less than the maximum, this
122
120
// means we can replace it with a larger texture.
123
- h = PApplet .min (2 * textures [currentTex ].glHeight , maxSize );
121
+ h = PApplet .min (2 * textures [lastTex ].glHeight , maxSize );
124
122
resize = true ;
125
123
} else {
126
124
h = minSize ;
@@ -147,38 +145,37 @@ public boolean addTexture(PGraphicsOpenGL pg) {
147
145
textures [0 ] = tex ;
148
146
images = new PImage [1 ];
149
147
images [0 ] = pg .wrapTexture (tex );
150
- currentTex = 0 ;
148
+ lastTex = 0 ;
151
149
} else if (resize ) {
152
150
// Replacing old smaller texture with larger one.
153
151
// But first we must copy the contents of the older
154
152
// texture into the new one. Setting blend mode to
155
153
// REPLACE to preserve color of transparent pixels.
156
- Texture tex0 = textures [currentTex ];
154
+ Texture tex0 = textures [lastTex ];
157
155
158
156
tex .pg .pushStyle ();
159
157
tex .pg .blendMode (REPLACE );
160
158
tex .put (tex0 );
161
159
tex .pg .popStyle ();
162
160
163
- textures [currentTex ] = tex ;
161
+ textures [lastTex ] = tex ;
164
162
165
- pg .setCache (images [currentTex ], tex );
166
- images [currentTex ].width = tex .width ;
167
- images [currentTex ].height = tex .height ;
163
+ pg .setCache (images [lastTex ], tex );
164
+ images [lastTex ].width = tex .width ;
165
+ images [lastTex ].height = tex .height ;
168
166
} else {
169
167
// Adding new texture to the list.
170
- Texture [] tempTex = textures ;
171
- textures = new Texture [textures . length + 1 ];
172
- PApplet .arrayCopy (tempTex , textures , tempTex .length );
173
- textures [ tempTex . length ] = tex ;
174
- currentTex = textures . length - 1 ;
175
-
176
- PImage [] tempImg = images ;
177
- images = new PImage [ textures .length ] ;
178
- PApplet . arrayCopy ( tempImg , images , tempImg . length );
179
- images [ tempImg . length ] = pg . wrapTexture ( tex ) ;
168
+ lastTex = textures . length ;
169
+ Texture [] tempTex = new Texture [lastTex + 1 ];
170
+ PApplet .arrayCopy (textures , tempTex , textures .length );
171
+ tempTex [ lastTex ] = tex ;
172
+ textures = tempTex ;
173
+
174
+ PImage [] tempImg = new PImage [ textures . length ] ;
175
+ PApplet . arrayCopy ( images , tempImg , images .length ) ;
176
+ tempImg [ lastTex ] = pg . wrapTexture ( tex );
177
+ images = tempImg ;
180
178
}
181
- lastTex = currentTex ;
182
179
183
180
// Make sure that the current texture is bound.
184
181
tex .bind ();
@@ -188,7 +185,6 @@ public boolean addTexture(PGraphicsOpenGL pg) {
188
185
189
186
190
187
public void begin () {
191
- setTexture (0 );
192
188
}
193
189
194
190
@@ -199,23 +195,8 @@ public void end() {
199
195
}
200
196
201
197
202
- public void setTexture (int idx ) {
203
- if (0 <= idx && idx < textures .length ) {
204
- currentTex = idx ;
205
- }
206
- }
207
-
208
-
209
- public PImage getTexture (int idx ) {
210
- if (0 <= idx && idx < images .length ) {
211
- return images [idx ];
212
- }
213
- return null ;
214
- }
215
-
216
-
217
- public PImage getCurrentTexture () {
218
- return getTexture (currentTex );
198
+ public PImage getTexture (TextureInfo info ) {
199
+ return images [info .texIndex ];
219
200
}
220
201
221
202
@@ -232,7 +213,7 @@ public void updateGlyphsTexCoords() {
232
213
// loop over current glyphs.
233
214
for (int i = 0 ; i < glyphTexinfos .length ; i ++) {
234
215
TextureInfo tinfo = glyphTexinfos [i ];
235
- if (tinfo != null && tinfo .texIndex == currentTex ) {
216
+ if (tinfo != null && tinfo .texIndex == lastTex ) {
236
217
tinfo .updateUV ();
237
218
}
238
219
}
@@ -265,14 +246,19 @@ public boolean contextIsOutdated() {
265
246
if (outdated ) {
266
247
for (int i = 0 ; i < textures .length ; i ++) {
267
248
textures [i ].dispose ();
268
- // PGraphicsOpenGL.removeTextureObject(textures[i].glName,
269
- // textures[i].context);
270
- // textures[i].glName = 0;
271
249
}
272
250
}
273
251
return outdated ;
274
252
}
275
253
254
+ // public void draw() {
255
+ // Texture tex = textures[lastTex];
256
+ // pgl.drawTexture(tex.glTarget, tex.glName,
257
+ // tex.glWidth, tex.glHeight,
258
+ // 0, 0, tex.glWidth, tex.glHeight);
259
+ // }
260
+
261
+
276
262
// Adds this glyph to the opengl texture in PFont.
277
263
protected void addToTexture (PGraphicsOpenGL pg , int idx , PFont .Glyph glyph ) {
278
264
// We add one pixel to avoid issues when sampling the font texture at
@@ -316,16 +302,15 @@ protected void addToTexture(PGraphicsOpenGL pg, int idx, PFont.Glyph glyph) {
316
302
}
317
303
318
304
// Is there room for this glyph in the current line?
319
- if (offsetX + w > textures [currentTex ].glWidth ) {
305
+ if (offsetX + w > textures [lastTex ].glWidth ) {
320
306
// No room, go to the next line:
321
307
offsetX = 0 ;
322
308
offsetY += lineHeight ;
323
- lineHeight = 0 ;
324
309
}
325
310
lineHeight = Math .max (lineHeight , h );
326
311
327
312
boolean resized = false ;
328
- if (offsetY + lineHeight > textures [currentTex ].glHeight ) {
313
+ if (offsetY + lineHeight > textures [lastTex ].glHeight ) {
329
314
// We run out of space in the current texture, so we add a new texture:
330
315
resized = addTexture (pg );
331
316
if (resized ) {
@@ -341,8 +326,7 @@ protected void addToTexture(PGraphicsOpenGL pg, int idx, PFont.Glyph glyph) {
341
326
}
342
327
}
343
328
344
- TextureInfo tinfo = new TextureInfo (currentTex , offsetX , offsetY ,
345
- w , h , rgba );
329
+ TextureInfo tinfo = new TextureInfo (lastTex , offsetX , offsetY , w , h , rgba );
346
330
offsetX += w ;
347
331
348
332
if (idx == glyphTexinfos .length ) {
@@ -385,6 +369,7 @@ class TextureInfo {
385
369
void updateUV () {
386
370
width = textures [texIndex ].glWidth ;
387
371
height = textures [texIndex ].glHeight ;
372
+
388
373
u0 = (float )crop [0 ] / (float )width ;
389
374
u1 = u0 + (float )crop [2 ] / (float )width ;
390
375
v0 = (float )(crop [1 ] + crop [3 ]) / (float )height ;
0 commit comments