JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
GPUTextRendererListenerBase01.java
Go to the documentation of this file.
1/**
2 * Copyright 2010-2024 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.test.junit.graph;
29
30import java.io.IOException;
31
32import com.jogamp.opengl.GL;
33import com.jogamp.opengl.GL2ES2;
34import com.jogamp.opengl.GLAnimatorControl;
35import com.jogamp.opengl.GLAutoDrawable;
36import com.jogamp.opengl.GLException;
37import com.jogamp.opengl.GLProfile;
38import com.jogamp.common.util.InterruptSource;
39import com.jogamp.graph.curve.Region;
40import com.jogamp.graph.curve.opengl.GLRegion;
41import com.jogamp.graph.curve.opengl.RegionRenderer;
42import com.jogamp.graph.curve.opengl.RenderState;
43import com.jogamp.graph.curve.opengl.TextRegionUtil;
44import com.jogamp.graph.font.Font;
45import com.jogamp.graph.font.FontFactory;
46import com.jogamp.graph.font.FontScale;
47import com.jogamp.graph.font.FontSet;
48import com.jogamp.math.geom.AABBox;
49import com.jogamp.math.geom.plane.AffineTransform;
50import com.jogamp.math.util.PMVMatrix4f;
51import com.jogamp.newt.Window;
52import com.jogamp.newt.event.KeyEvent;
53import com.jogamp.newt.event.KeyListener;
54import com.jogamp.newt.opengl.GLWindow;
55
56/**
57 *
58 * GPURendererListenerBase01 Keys:
59 * - 1/2: zoom in/out
60 * - 6/7: 2nd pass texture size
61 * - 0/9: rotate
62 * - v: toggle v-sync
63 * - s: screenshot
64 *
65 * Additional Keys:
66 * - 3/4: font +/-
67 * - h: toogle draw 'font set'
68 * - f: toggle draw fps
69 * - space: toggle font (ubuntu/java)
70 * - i: live input text input (CR ends it, backspace supported)
71 */
74 private final GLRegion regionFPS, regionHead, regionBottom;
75 int fontSet = FontFactory.UBUNTU;
76 Font font;
77
78 int headType = 1;
79 boolean drawFPS = true;
80 final float fontSizeFName = 10f;
81 final float fontSizeFPS = 10f;
82 final int[] sampleCountFPS = new int[] { 8 };
83 float fontSizeHead = 12f;
84 float fontSizeCenter = 16f;
85 float dpiV = 96;
86 float ppmmV = 1;
87 final int fontSizeModulo = 100;
88 String fontName;
89 AABBox fontNameBox;
90 String headtext;
91 AABBox headbox;
92
93 protected final AffineTransform tempT1 = new AffineTransform();
94 protected final AffineTransform tempT2 = new AffineTransform();
95
96 static final String text2 = "The quick brown fox jumps over the lazy dog";
97 public static final String text_help =
98 "JOGL: Java™ Binding for OpenGL®, providing hardware-accelerated 3D graphics.\n\n"+
99 "JOGAMP graph demo using Resolution Independent NURBS\n"+
100 "JOGAMP JOGL - OpenGL ES2 profile\n"+
101 "Press 1/2 to zoom in/out the below text\n"+
102 "Press 3/4 to incr/decs font size (alt: head, w/o bottom)\n"+
103 "Press 6/7 to edit texture size if using VBAA\n"+
104 "Press 0/9 to rotate the below string\n"+
105 "Press s to screenshot\n"+
106 "Press v to toggle vsync\n"+
107 "Press i for live input text input (CR ends it, backspace supported)\n"+
108 "Press f to toggle fps. H for different text, space for font type\n";
109
110 public static final String textX1 =
111 "JOGL: Java™ Binding for OpenGL®, providing hardware-accelerated 3D graphics.\n\n"+
112 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+
113 "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+
114 "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+
115 "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est. \n"+
116 "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi. \n"+
117 "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper \n"+
118 "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem, \n" +
119 "-------Press H to change text---------";
120
121 public static final String textX2 =
122 "I “Ask Jeff” or ‘Ask Jeff’. Take the chef d’œuvre! Two of [of] (of) ‘of’ “of” of? of! of*.\n"+
123 "Les Woëvres, the Fôret de Wœvres, the Voire and Vauvise. Yves is in heaven; D’Amboise is in jail.\n"+
124 "Lyford’s in Texas & L’Anse-aux-Griffons in Québec; the Łyna in Poland. Yriarte, Yciar and Ysaÿe are at Yale.\n"+
125 "Kyoto and Ryotsu are both in Japan, Kwikpak on the Yukon delta, Kvæven in Norway, Kyulu in Kenya, not in Rwanda.…\n"+
126 "Von-Vincke-Straße in Münster, Vdovino in Russia, Ytterbium in the periodic table. Are Toussaint L’Ouverture, Wölfflin, Wolfe,\n"+
127 "Miłosz and Wū Wŭ all in the library? 1510–1620, 11:00 pm, and the 1980s are over. X\n"+
128 "-------Press H to change text---------";
129
130 public static final String textX20 =
131 "I “Ask Jeff” or ‘Ask Jeff’. Take the chef d’œuvre! Two of [of] (of) ‘of’ “of” of? of! of*.\n"+
132 "Two of [of] (of) ‘of’ “of” of? of! of*. Ydes, Yffignac and Ygrande are in France: so are Ypres,\n"+
133 "Les Woëvres, the Fôret de Wœvres, the Voire and Vauvise. Yves is in heaven; D’Amboise is in jail.\n"+
134 "Lyford’s in Texas & L’Anse-aux-Griffons in Québec; the Łyna in Poland. Yriarte, Yciar and Ysaÿe are at Yale.\n"+
135 "Kyoto and Ryotsu are both in Japan, Kwikpak on the Yukon delta, Kvæven in Norway, Kyulu in Kenya, not in Rwanda.…\n"+
136 "Walton’s in West Virginia, but «Wren» is in Oregon. Tlálpan is near Xochimilco in México.\n"+
137 "The Zygos & Xylophagou are in Cyprus, Zwettl in Austria, Fænø in Denmark, the Vøringsfossen and Værøy in Norway.\n"+
138 "Tchula is in Mississippi, the Tittabawassee in Michigan. Twodot is here in Montana, Ywamun in Burma.\n"+
139 "Yggdrasil and Ymir, Yngvi and Vóden, Vídrið and Skeggjöld and Týr are all in the Eddas.\n"+
140 "Tørberget and Våg, of course, are in Norway, Ktipas and Tmolos in Greece, but Vázquez is in Argentina, Vreden in Germany,\n"+
141 "Von-Vincke-Straße in Münster, Vdovino in Russia, Ytterbium in the periodic table. Are Toussaint L’Ouverture, Wölfflin, Wolfe,\n"+
142 "Miłosz and Wū Wŭ all in the library? 1510–1620, 11:00 pm, and the 1980s are over.\n"+
143 "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+
144 "-------Press H to change text---------";
145
146 static final String textXLast = "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
147
148 Window upstream_window = null;
149 StringBuilder userString = new StringBuilder(textX1);
150 boolean userInput = false;
151 public GPUTextRendererListenerBase01(final GLProfile glp, final int renderModes, final int aaQuality, final int sampleCount, final boolean blending, final boolean debug, final boolean trace) {
152 // NOTE_ALPHA_BLENDING: We use alpha-blending
154 renderModes, debug, trace);
156 this.textRegionUtil = new TextRegionUtil(renderModes);
157 this.regionFPS = GLRegion.create(glp, renderModes, null, 0, 0);
158 this.regionHead = GLRegion.create(glp, renderModes, null, 0, 0);
159 this.regionBottom = GLRegion.create(glp, renderModes, null, 0, 0);
161 setMatrix(0, 0, 0, 0f);
162 getRenderer().setAAQuality(aaQuality);
163 getRenderer().setSampleCount(sampleCount);
164 }
165
166 void switchHeadBox() {
167 setHeadBox( ( headType + 1 ) % 5, true );
168 }
169 public int getHeadBoxType() { return headType; }
170 public AABBox getHeadBox() { return headbox; }
171 public void setHeadBox(final int choice, final boolean resize) {
172 headType = choice % 5 ;
173 switch(headType) {
174 case 0:
175 headtext = null;
176 break;
177
178 case 1:
179 headtext= textX1;
180 break;
181 case 2:
182 headtext= textX2;
183 break;
184 case 3:
185 headtext= text_help;
186 break;
187
188 default:
189 headtext = textXLast;
190 }
191 if(resize && null != headtext) {
192 headbox = font.getMetricBounds(headtext);
193 if( headtext != text_help ) {
194 final float pxSz = FontScale.toPixels(fontSizeHead, dpiV);
195 upsizeWindowSurface(upstream_window, true, (int)(headbox.getWidth()*pxSz*1.1f), (int)(headbox.getHeight()*pxSz*2f));
196 }
197 }
198 }
199
200 public void setHeadBox(final String text, final boolean resize) {
201 headtext = text;
202 if(resize && null != headtext) {
203 headbox = font.getMetricBounds(headtext);
204 if( headtext != text_help ) {
205 final float pxSz = FontScale.toPixels(fontSizeHead, dpiV);
206 upsizeWindowSurface(upstream_window, true, (int)(headbox.getWidth()*pxSz*1.1f), (int)(headbox.getHeight()*pxSz*2f));
207 }
208 }
209 }
210
211 public static void upsizeWindowSurface(final Window window, final boolean off_thread, final int w, final int h) {
212 if( null == window ) {
213 return;
214 }
215 final int w2 = Math.max(window.getSurfaceWidth(), w);
216 final int h2 = Math.max(window.getSurfaceHeight(), h);
217 System.err.println("upsizeWindowSurface: "+window.getSurfaceWidth()+"x"+window.getSurfaceHeight()+" -> "+w+"x"+h+" -> "+w2+"x"+h2);
218 if( off_thread ) {
219 new InterruptSource.Thread() {
220 @Override
221 public void run() {
222 window.setSurfaceSize(w2, h2);
223 } }.start();
224 } else {
225 window.setSurfaceSize(w2, h2);
226 }
227 }
228
229 @Override
230 public void init(final GLAutoDrawable drawable) {
231 super.init(drawable);
232 final Object upObj = drawable.getUpstreamWidget();
233 if( upObj instanceof Window ) {
234 upstream_window = (Window) upObj;
235 final float[] sPpMM = upstream_window.getPixelsPerMM(new float[2]);
236 final float[] sDPI = FontScale.ppmmToPPI( new float[] { sPpMM[0], sPpMM[1] } );
237 dpiV = sDPI[1];
238 ppmmV = sPpMM[1];
239 System.err.println("Using vertical screen DPI of "+dpiV+", "+ppmmV+" pixel/mm");
240 } else {
241 System.err.println("Using vertical default DPI of "+dpiV+", "+ppmmV+" pixel/mm");
242 }
243 fontNameBox = font.getGlyphBounds(fontName, tempT1, tempT2);
244 setHeadBox(headType, true);
245 {
246 final float pixelSizeFName = FontScale.toPixels(fontSizeFName, dpiV);
247 System.err.println("XXX: fontName size "+fontSizeFName+"pt, dpiV "+dpiV+" -> "+pixelSizeFName+"px");
248 System.err.println("XXX: fontName boxM fu "+font.getMetricBoundsFU(fontName));
249 System.err.println("XXX: fontName boxG fu "+font.getGlyphBoundsFU(fontName, tempT1, tempT2));
250 System.err.println("XXX: fontName boxM em "+font.getMetricBounds(fontName));
251 System.err.println("XXX: fontName boxG em "+font.getGlyphBounds(fontName, tempT1, tempT2));
252 System.err.println("XXX: fontName box height px "+(fontNameBox.getHeight() * pixelSizeFName));
253 }
254 }
255
256 @Override
257 public void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height) {
258 super.reshape(drawable, xstart, ystart, width, height);
259 final Object upObj = drawable.getUpstreamWidget();
260 if( upObj instanceof Window ) {
261 upstream_window = (Window) upObj;
262 }
263 final float dist = 100f;
264 nearPlaneX0 = nearPlane1Box.getMinX() * dist;
265 nearPlaneY0 = nearPlane1Box.getMinY() * dist;
266 nearPlaneZ0 = nearPlane1Box.getMinZ() * dist;
267 final float xd = nearPlane1Box.getWidth() * dist;
268 final float yd = nearPlane1Box.getHeight() * dist;
269 nearPlaneSx = xd / width;
270 nearPlaneSy = yd / height;
271 nearPlaneS = nearPlaneSy;
272 System.err.printf("Scale: [%f x %f] / [%d x %d] = [%f, %f] -> %f%n", xd, yd, width, height, nearPlaneSx, nearPlaneSy, nearPlaneS);
273 }
274 float nearPlaneX0, nearPlaneY0, nearPlaneZ0, nearPlaneSx, nearPlaneSy, nearPlaneS;
275
276 @Override
277 public void dispose(final GLAutoDrawable drawable) {
278 upstream_window = null;
279 regionFPS.destroy(drawable.getGL().getGL2ES2());
280 regionHead.destroy(drawable.getGL().getGL2ES2());
281 regionBottom.destroy(drawable.getGL().getGL2ES2());
282 super.dispose(drawable);
283 }
284
285 @Override
286 public void display(final GLAutoDrawable drawable) {
287 final Object upObj = drawable.getUpstreamWidget();
288 if( upObj instanceof Window ) {
289 upstream_window = (Window) upObj;
290 }
291 final int width = drawable.getSurfaceWidth();
292 final int height = drawable.getSurfaceHeight();
293 final GL2ES2 gl = drawable.getGL().getGL2ES2();
294
295 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
297
298 // final float zDistance0 = 500f;
299 // final float zDistance1 = 400f;
300 // final float[] objPos = new float[3];
301 // final float[] winZ = new float[1];
302 // final int[] view = new int[] { 0, 0, drawable.getWidth(), drawable.getHeight() };
303
304 final RegionRenderer renderer = getRenderer();
305 final PMVMatrix4f pmv = renderer.getMatrix();
306 pmv.loadMvIdentity();
307 renderer.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
308 final float pixelSizeFName = FontScale.toPixels(fontSizeFName, dpiV);
309 final float pixelSizeHead = FontScale.toPixels(fontSizeHead, dpiV);
310 final float mmSizeHead = pixelSizeHead / ppmmV;
311 final float pixelSizeCenter = FontScale.toPixels(fontSizeCenter, dpiV);
312 final float mmSizeCenter = pixelSizeCenter / ppmmV;
313 final int pass2AAQual = getRenderer().getAAQuality();
314 final int pass2Samples = getRenderer().getSampleCount();
315
316 renderer.enable(gl, true);
317
318 if( drawFPS ) {
319 pmv.pushMv();
320 final float pixelSizeFPS = FontScale.toPixels(fontSizeFPS, dpiV);
321 final float lfps, tfps;
322 final GLAnimatorControl animator = drawable.getAnimator();
323 if( null != animator ) {
324 lfps = animator.getLastFPS();
325 tfps = animator.getTotalFPS();
326 } else {
327 lfps = 0f;
328 tfps = 0f;
329 }
330 final String modeS = Region.getRenderModeString(regionFPS.getRenderModes())+"-q"+pass2AAQual;
331 final String text = String.format("%03.1f/%03.1f fps, v-sync %d, dpiV %.2f %.2f px/mm, font[head %.1fpt %.2fpx %.2fmm, center %.1fpt %.2fpx %.2fmm], %s-samples[%d], blend %b, alpha %d",
332 lfps, tfps, gl.getSwapInterval(), dpiV, ppmmV,
333 fontSizeHead, pixelSizeHead, mmSizeHead,
334 fontSizeCenter, pixelSizeCenter, mmSizeCenter,
335 modeS, pass2Samples,
338
339 // bottom, half line up
340 pmv.translateMv(nearPlaneX0, nearPlaneY0+(nearPlaneS * pixelSizeFPS / 2f), nearPlaneZ0);
341 {
342 final float sxy = nearPlaneS * pixelSizeFPS;
343 pmv.scaleMv(sxy, sxy, 1.0f);
344 }
345 // No cache, keep region alive!
346 TextRegionUtil.drawString3D(gl, regionFPS.clear(gl), renderer, font, text, null, tempT1, tempT2);
347 pmv.popMv();
348 }
349
350 // float dx = width - ( fontNameBox.getWidth() + font.getAdvanceWidth( Glyph.ID_SPACE ) ) * pixelSizeFName;
351 float dx = width - ( fontNameBox.getWidth() + 2 * font.getAdvanceWidth( font.getGlyphID('X') ) ) * pixelSizeFName;
352 float dy = height - fontNameBox.getHeight() * pixelSizeFName;
353 {
354 pmv.pushMv();
355 pmv.translateMv(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
356 {
357 final float sxy = nearPlaneS * pixelSizeFName;
358 pmv.scaleMv(sxy, sxy, 1.0f);
359 }
360 // System.err.printf("FontN: [%f %f] -> [%f %f]%n", dx, dy, nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy));
361 textRegionUtil.drawString3D(gl, renderer, font, fontName, null);
362 pmv.popMv();
363 }
364
365 dx = 10f;
366 dy += -fontNameBox.getHeight() * pixelSizeFName - 10f;
367
368 if(null != headtext) {
369 pmv.pushMv();
370 // System.err.printf("Head: [%f %f] -> [%f %f]%n", dx, dy, nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy));
371 pmv.translateMv(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
372 {
373 final float sxy = nearPlaneS * pixelSizeHead;
374 pmv.scaleMv(sxy, sxy, 1.0f);
375 }
376 // pmv.glTranslatef(x0, y1, z0);
377 textRegionUtil.drawString3D(gl, renderer, font, headtext, null);
378 pmv.popMv();
379 }
380
381 dy += ( -headbox.getHeight() - font.getLineHeight() ) * pixelSizeCenter;
382
383 {
384 final String mg_s = font.getGlyph('M').toString()+"\n"+font.getGlyph('X').toString();
385 pmv.pushMv();
386 // System.err.printf("Head: [%f %f] -> [%f %f]%n", dx, dy, nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy));
387 pmv.translateMv(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
388 {
389 final float sxy = nearPlaneS * pixelSizeFName;
390 pmv.scaleMv(sxy, sxy, 1.0f);
391 }
392 // pmv.glTranslatef(x0, y1, z0);
393 final AABBox box = textRegionUtil.drawString3D(gl, renderer, font, mg_s, null);
394 pmv.popMv();
395
396 dy += ( -box.getHeight() - font.getLineHeight() ) * pixelSizeFName;
397 }
398
399 {
400 pmv.pushMv();
401 pmv.translateMv(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
402 // System.err.printf("Bottom: [%f %f] -> [%f %f]%n", dx, dy, nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy));
404 pmv.rotateMv(getAngleRad(), 0, 1, 0);
405 {
406 final float sxy = nearPlaneS * pixelSizeCenter;
407 pmv.scaleMv(sxy, sxy, 1.0f);
408 }
409 renderer.setColorStatic(0.9f, 0.0f, 0.0f, 1.0f);
410
411 if( bottomTextUseFrustum ) {
412 regionBottom.setFrustum(pmv.getFrustum());
413 }
414 if(!userInput) {
415 if( bottomTextUseFrustum ) {
416 TextRegionUtil.drawString3D(gl, regionBottom.clear(gl), renderer, font, text2, null, tempT1, tempT2);
417 } else {
418 textRegionUtil.drawString3D(gl, renderer, font, text2, null);
419 }
420 } else {
421 if( bottomTextUseFrustum ) {
422 TextRegionUtil.drawString3D(gl, regionBottom.clear(gl), renderer, font, userString.toString(), null, tempT1, tempT2);
423 } else {
424 textRegionUtil.drawString3D(gl, renderer, font, userString.toString(), null);
425 }
426 }
427 pmv.popMv();
428 }
429 renderer.enable(gl, false);
430 }
431 final boolean bottomTextUseFrustum = true;
432
433 public Font getFont() { return font; }
434 public float getFontSizeHead() { return fontSizeHead; }
435
436 public void fontBottomIncr(final int v) {
437 fontSizeCenter = Math.abs((fontSizeCenter + v) % fontSizeModulo) ;
438 dumpMatrix(true);
439 }
440
441 public void fontHeadIncr(final int v) {
442 fontSizeHead = Math.abs((fontSizeHead + v) % fontSizeModulo) ;
443 updateFontNameBox();
444 if(null != headtext) {
445 headbox = font.getMetricBounds(headtext);
446 }
447 }
448
449 public void setFontHeadSize(final int v) {
450 if( 0 < v ) {
451 fontSizeHead = v % fontSizeModulo;
452 updateFontNameBox();
453 if(null != headtext) {
454 headbox = font.getMetricBounds(headtext);
455 }
456 }
457 }
458
459 public boolean nextFontSet() {
460 try {
461 final int set = ( fontSet == FontFactory.UBUNTU ) ? FontFactory.UBUNTU : FontFactory.UBUNTU ;
462 final Font _font = FontFactory.get(set).getDefault();
463 if(null != _font) {
464 fontSet = set;
465 font = _font;
466 updateFontNameBox();
467 return true;
468 }
469 } catch (final IOException ex) {
470 System.err.println("Caught: "+ex.getMessage());
471 }
472 return false;
473 }
474
475 public boolean setFontSet(final int set, final int family, final int stylebits) {
476 try {
477 final Font _font = FontFactory.get(set).get(family, stylebits);
478 if(null != _font) {
479 fontSet = set;
480 font = _font;
481 updateFontNameBox();
482 return true;
483 }
484 } catch (final IOException ex) {
485 System.err.println("Caught: "+ex.getMessage());
486 }
487 return false;
488 }
489
490 public boolean setFont(final Font _font) {
491 if(null != _font) {
492 // fontSet = ???
493 font = _font;
494 updateFontNameBox();
495 return true;
496 }
497 return false;
498 }
499
500 private void updateFontNameBox() {
501 fontName = font.getFullFamilyName()+" (head "+fontSizeHead+"pt)";
502 fontNameBox = font.getMetricBounds(fontName);
503 }
504
505 public boolean isUserInputMode() { return userInput; }
506
507 void dumpMatrix(final boolean bbox) {
508 System.err.println("Matrix: " + getXTran() + "/" + getYTran() + " x"+getZTran() + " @"+getAngleDeg() +" fontSize "+fontSizeCenter);
509 if(bbox) {
510 System.err.println("bbox em: "+font.getMetricBounds(text2));
511 System.err.println("bbox px: "+font.getMetricBounds(text2).scale(nearPlaneS * FontScale.toPixels(fontSizeCenter, dpiV)));
512 }
513 }
514
515 KeyAction keyAction = null;
516
517 @Override
518 public void attachInputListenerTo(final GLWindow window) {
519 if ( null == keyAction ) {
520 keyAction = new KeyAction();
521 window.addKeyListener(keyAction);
522 super.attachInputListenerTo(window);
523 }
524 }
525
526 @Override
527 public void detachInputListenerFrom(final GLWindow window) {
528 super.detachInputListenerFrom(window);
529 if ( null == keyAction ) {
530 return;
531 }
532 window.removeKeyListener(keyAction);
533 }
534
535 @Override
536 public void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha) throws GLException, IOException {
537 // winTitle + <renderModes> + s<sampleCount> + "fsaa"+<CapsNumSamples> + <font> + <textType> + Z<zTran> + snap<Count> + <resolution>
538 //
539 // winTitle + s<sampleCount> + <objName> + Z<zTran> + snap<Count> + <resolution>
540 final String fn = font.getFullFamilyName().replace(' ', '_').replace('-', '_');
541 final String modes = Region.getRenderModeString(getRenderModes());
542 final String fsaa = "fsaa"+drawable.getChosenGLCapabilities().getNumSamples();
543 super.printScreen(drawable, dir, tech+"-"+modes, fsaa+"-"+fn+"-text"+getHeadBoxType()+"-"+objName, exportAlpha);
544 }
545
546 float fontHeadScale = 1f;
547
548 public class KeyAction implements KeyListener {
549 @Override
550 public void keyPressed(final KeyEvent e) {
551 if(userInput) {
552 return;
553 }
554 final short s = e.getKeySymbol();
555 if(s == KeyEvent.VK_3) {
556 if( e.isAltDown() ) {
557 fontHeadIncr(1);
558 } else {
560 }
561 }
562 else if(s == KeyEvent.VK_4) {
563 if( e.isAltDown() ) {
564 fontHeadIncr(-1);
565 } else {
566 fontBottomIncr(-1);
567 }
568 }
569 else if(s == KeyEvent.VK_H) {
570 switchHeadBox();
571 }
572 else if(s == KeyEvent.VK_F) {
573 drawFPS = !drawFPS;
574 }
575 else if(s == KeyEvent.VK_SPACE) {
576 nextFontSet();
577 }
578 else if(s == KeyEvent.VK_I) {
579 userInput = true;
580 setIgnoreInput(true);
581 }
582 }
583
584 @Override
585 public void keyReleased(final KeyEvent e) {
586 if( !e.isPrintableKey() || e.isAutoRepeat() ) {
587 return;
588 }
589 if(userInput) {
590 final short k = e.getKeySymbol();
591 if( KeyEvent.VK_ENTER == k ) {
592 userInput = false;
593 setIgnoreInput(false);
594 } else if( KeyEvent.VK_BACK_SPACE == k && userString.length()>0) {
595 userString.deleteCharAt(userString.length()-1);
596 } else {
597 final char c = e.getKeyChar();
598 if( font.isPrintableChar( c ) ) {
599 userString.append(c);
600 }
601 }
602 }
603 }
604 }
605}
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
static String getRenderModeString(final int renderModes)
Returns a unique technical description string for renderModes as follows:
Definition: Region.java:251
final void setFrustum(final Frustum frustum)
Set Frustum culling for addOutlineShape(OutlineShape, AffineTransform, float[]).
Definition: Region.java:407
final int getRenderModes()
Returns bit-field of render modes, see create(..).
Definition: Region.java:344
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
Definition: GLRegion.java:70
final GLRegion clear(final GL2ES2 gl)
Clears all buffers, i.e.
Definition: GLRegion.java:436
final void destroy(final GL2ES2 gl)
Delete and clear the associated OGL objects.
Definition: GLRegion.java:460
static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit, final int initialVerticesCount, final int initialIndicesCount)
Create a GLRegion using the passed render mode.
Definition: GLRegion.java:109
final void enable(final GL2ES2 gl, final boolean enable)
Enabling or disabling the RenderState's current shader program.
final int getAAQuality()
Returns pass2 AA-quality rendering value for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT.
final void setColorStatic(final Vec4f rgbaColor)
final PMVMatrix4f getMatrix()
Borrow the current PMVMatrix4f.
final int setSampleCount(final int v)
Sets pass2 AA sample count clipped to the range [Region#MIN_AA_SAMPLE_COUNT..Region#MAX_AA_SAMPLE_COU...
static final GLCallback defaultBlendDisable
Default GL#GL_BLEND disable GLCallback, simply turning-off the GL#GL_BLEND state and turning-on depth...
final int setAAQuality(final int v)
Sets pass2 AA-quality rendering value clipped to the range [Region#MIN_AA_QUALITY....
final boolean hintBitsSet(final int mask)
static final GLCallback defaultBlendEnable
Default GL#GL_BLEND enable GLCallback, turning-off depth writing via GL#glDepthMask(boolean) if Rende...
final int getSampleCount()
Returns pass2 AA sample count for Graph Region AA render-modes: VBAA_RENDERING_BIT or Region#MSAA_REN...
static RegionRenderer create()
Create a hardware accelerated RegionRenderer including its RenderState composition.
The RenderState is owned by RegionRenderer.
static final int BITHINT_BLENDING_ENABLED
Bitfield hint, if set stating enabled GL#GL_BLEND, otherwise disabled.
static final int BITHINT_GLOBAL_DEPTH_TEST_ENABLED
Bitfield hint, if set stating globally enabled GL#GL_DEPTH_TEST, otherwise disabled.
Text Type Rendering Utility Class adding the Font.Glyphs OutlineShape to a GLRegion.
AABBox drawString3D(final GL2ES2 gl, final RegionRenderer renderer, final Font font, final CharSequence str, final Vec4f rgbaColor)
Render the string in 3D space w.r.t.
The optional property jogamp.graph.font.ctor allows user to specify the FontConstructor implementatio...
static final FontSet get(final int font)
static final int UBUNTU
Ubuntu is the default font family, {@value}.
Simple static font scale methods for unit conversions.
Definition: FontScale.java:37
static float[] ppmmToPPI(final float[] ppmm)
Converts [1/mm] to [1/inch] in place.
Definition: FontScale.java:105
static float toPixels(final float points, final float res_dpi)
Converts typical font size in points and screen resolution in dpi (pixels-per-inch) to font size in p...
Definition: FontScale.java:76
Axis Aligned Bounding Box.
Definition: AABBox.java:54
final float getWidth()
Definition: AABBox.java:879
final float getHeight()
Definition: AABBox.java:883
final AABBox scale(final float s)
Scale this AABBox by a constant around fixed center.
Definition: AABBox.java:750
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
final PMVMatrix4f translateMv(final float x, final float y, final float z)
Translate the modelview matrix.
final PMVMatrix4f scaleMv(final float x, final float y, final float z)
Scale the modelview matrix.
final PMVMatrix4f rotateMv(final float ang_rad, final float x, final float y, final float z)
Rotate the modelview matrix by the given axis and angle in radians.
final PMVMatrix4f loadMvIdentity()
Load the modelview matrix with the values of the given Matrix4f.
final Frustum getFrustum()
Returns the frustum, derived from projection x modelview.
final PMVMatrix4f popMv()
Pop the modelview matrix from its stack.
final PMVMatrix4f pushMv()
Push the modelview matrix to its stack, while preserving its values.
final boolean isAutoRepeat()
getModifiers() contains AUTOREPEAT_MASK.
final boolean isAltDown()
getModifiers() contains ALT_MASK.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
Definition: KeyEvent.java:161
static final short VK_ENTER
Constant for the ENTER key, i.e.
Definition: KeyEvent.java:446
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
Definition: KeyEvent.java:176
static final short VK_4
See VK_0.
Definition: KeyEvent.java:561
static final short VK_SPACE
Constant for the SPACE function key.
Definition: KeyEvent.java:505
static final short VK_H
See VK_A.
Definition: KeyEvent.java:609
static final short VK_F
See VK_A.
Definition: KeyEvent.java:605
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
Definition: KeyEvent.java:316
static final short VK_I
See VK_A.
Definition: KeyEvent.java:611
static final short VK_3
See VK_0.
Definition: KeyEvent.java:559
static final short VK_BACK_SPACE
Constant for the BACK SPACE key "\b", matching ASCII.
Definition: KeyEvent.java:431
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final void removeKeyListener(final KeyListener l)
Definition: GLWindow.java:912
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
void setMatrix(final float xtrans, final float ytrans, final float zTran, final float angle)
final AABBox nearPlane1Box
Describing the bounding box in model-coordinates of the near-plane parallel at distance one.
void keyPressed(final KeyEvent e)
A key has been pressed, excluding auto-repeat modifier keys.
void keyReleased(final KeyEvent e)
A key has been released, excluding auto-repeat modifier keys.
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
GPUTextRendererListenerBase01(final GLProfile glp, final int renderModes, final int aaQuality, final int sampleCount, final boolean blending, final boolean debug, final boolean trace)
boolean setFontSet(final int set, final int family, final int stylebits)
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void attachInputListenerTo(final GLWindow window)
Attach the input listener to the window.
void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha)
static void upsizeWindowSurface(final Window window, final boolean off_thread, final int w, final int h)
void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
static final int FAMILY_LIGHT
Font family LIGHT, {@value}.
Definition: FontSet.java:39
Font getDefault()
Returns the family FAMILY_REGULAR with STYLE_NONE as retrieved with get(int, int).
Font get(int family, int stylebits)
static final int STYLE_NONE
Zero style, {@value}.
Definition: FontSet.java:51
Interface wrapper for font implementation.
Definition: Font.java:60
Glyph getGlyph(final String name)
Returns the Glyph mapped to given name.
AABBox getMetricBounds(final CharSequence string)
Returns metric-bounds in font em-size.
float getLineHeight()
Returns line height, baseline-to-baseline in em-size [0..1], composed from ‘hhea’ table entries.
AABBox getMetricBoundsFU(final CharSequence string)
Returns metric-bounds in font-units.
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
AABBox getGlyphBounds(final CharSequence string)
Try using getGlyphBounds(CharSequence, AffineTransform, AffineTransform) to reuse AffineTransform ins...
int getGlyphID(final char codepoint)
Returns the Glyph ID mapped to given UTF16 (unicode) codepoint symbol.
String toString()
Returns getFullFamilyName().
AABBox getGlyphBoundsFU(final CharSequence string)
Try using getGlyphBoundsFU(CharSequence, AffineTransform, AffineTransform) to reuse AffineTransform i...
boolean isPrintableChar(final char c)
float getAdvanceWidth(final int glyphID)
Returns advance-width of given glyphID in font em-size [0..1], sourced from hmtx table - same as Glyp...
int getAlphaBits()
Returns the number of bits for the color buffer's alpha component.
int getSurfaceWidth()
Returns the width of the client area excluding insets (window decorations) in pixel units.
int getSurfaceHeight()
Returns the height of the client area excluding insets (window decorations) in pixel units.
Specifying NEWT's Window functionality:
Definition: Window.java:115
float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter of this window's NativeSurface according to the main monitor's curr...
void setSurfaceSize(int pixelWidth, int pixelHeight)
Sets the size of the window's surface in pixel units which claims the window's client area excluding ...
Listener for KeyEvents.
An animator control interface, which implementation may drive a com.jogamp.opengl....
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GLAnimatorControl getAnimator()
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
Object getUpstreamWidget()
Method may return the upstream UI toolkit object holding this GLAutoDrawable instance,...
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
int getSwapInterval()
Return the current swap interval.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
Definition: GL.java:390
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...
Definition: GL.java:738