JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTextRendererNEWT20.java
Go to the documentation of this file.
1/**
2 * Copyright 2011-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.File;
31import java.io.IOException;
32
33import com.jogamp.opengl.GL;
34import com.jogamp.opengl.GL2ES2;
35import com.jogamp.opengl.GLAutoDrawable;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLCapabilitiesImmutable;
38import com.jogamp.opengl.GLException;
39import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.JoglVersion;
41
42import jogamp.common.os.PlatformPropsImpl;
43
44import org.junit.Assert;
45import org.junit.BeforeClass;
46import org.junit.Test;
47import org.junit.FixMethodOrder;
48import org.junit.runners.MethodSorters;
49
50import com.jogamp.common.os.Platform;
51import com.jogamp.common.util.VersionUtil;
52import com.jogamp.graph.curve.Region;
53import com.jogamp.graph.font.Font;
54import com.jogamp.graph.font.FontFactory;
55import com.jogamp.newt.opengl.GLWindow;
56import com.jogamp.opengl.test.junit.util.UITestCase;
57import com.jogamp.opengl.util.caps.NonFSAAGLCapsChooser;
58
59
60/**
61 * TestTextRendererNEWT20 Variant
62 * - Using listener derived from fully features GPUTextRendererListenerBase01
63 * - Renders multiple demo text with multiple fonts
64 * - Used for validation against reference
65 */
66@FixMethodOrder(MethodSorters.NAME_ASCENDING)
67public class TestTextRendererNEWT20 extends UITestCase {
68 static final boolean DEBUG = false;
69 static final boolean TRACE = false;
70 static long duration = 100; // ms
71 static int win_width = 1024;
72 static int win_height = 640;
73 static int[] aaQualitySet = new int[] { 0, 1 };
74 static int[] sampleSet = new int[] { 4 };
75 static Font[] fontSet = new Font[] { };
76
77 @BeforeClass
78 public static void setup() {
79 if( fontSet.length == 0 ) {
80 try {
81 fontSet = FontSet01.getSet00();
82 } catch (final IOException e) {
83 e.printStackTrace();
84 }
85 }
86 }
87
88 static int atoi(final String a) {
89 try {
90 return Integer.parseInt(a);
91 } catch (final Exception ex) { throw new RuntimeException(ex); }
92 }
93
94 public static void main(final String args[]) throws IOException {
95 for(int i=0; i<args.length; i++) {
96 if(args[i].equals("-time")) {
97 i++;
98 duration = atoi(args[i]);
99 } else if(args[i].equals("-width")) {
100 i++;
101 win_width = atoi(args[i]);
102 } else if(args[i].equals("-height")) {
103 i++;
104 win_height = atoi(args[i]);
105 } else if(args[i].equals("-font")) {
106 i++;
107 fontSet = new Font[] { FontFactory.get(new File(args[i])) };
108 } else if(args[i].equals("-samples")) {
109 i++;
110 sampleSet = new int[] { atoi(args[i]) };
111 } else if(args[i].equals("-aaq")) {
112 i++;
113 aaQualitySet = new int[] { atoi(args[i]) };
114 }
115 }
116 final String tstname = TestTextRendererNEWT20.class.getName();
117 org.junit.runner.JUnitCore.main(tstname);
118 }
119
120 static void sleep() {
121 try {
122 System.err.println("** new frame ** (sleep: "+duration+"ms)");
123 Thread.sleep(duration);
124 } catch (final InterruptedException ie) {}
125 }
126
127 static void destroyWindow(final GLWindow window) {
128 if(null!=window) {
129 window.destroy();
130 }
131 }
132
133 static GLWindow createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height) {
134 Assert.assertNotNull(caps);
135
136 final GLWindow window = GLWindow.create(caps);
137 if( !caps.getSampleBuffers() ) {
138 // Make sure to not have FSAA if not requested
139 // TODO: Implement in default chooser?
140 window.setCapabilitiesChooser(new NonFSAAGLCapsChooser(true));
141 }
142 window.setSize(width, height);
143 window.setPosition(10, 10);
144 window.setTitle(title);
145 Assert.assertNotNull(window);
146 window.setVisible(true);
147
148 return window;
149 }
150
151 @Test
152 public void test00TextRendererVBAA01() throws InterruptedException, GLException, IOException {
153 if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
154 // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
155 System.err.println("disabled on non desktop (x86) arch for now ..");
156 return;
157 }
158 final GLProfile glp = GLProfile.getGL2ES2();
159
160 final GLCapabilities caps = new GLCapabilities(glp);
161 caps.setAlphaBits(4);
162 System.err.println("Requested: "+caps);
163
164 final GLWindow window = createWindow("TTRN20", caps, win_width, win_height);
165 window.display();
166 System.err.println(VersionUtil.getPlatformInfo());
167 // System.err.println(JoglVersion.getAllAvailableCapabilitiesInfo(window.getScreen().getDisplay().getGraphicsDevice(), null).toString());
168 System.err.println("Chosen: "+window.getChosenGLCapabilities());
169
170 final TextGLListener textGLListener = new TextGLListener(glp, Region.VBAA_RENDERING_BIT, Region.DEFAULT_AA_QUALITY, 4 /* sampleCount */, DEBUG, TRACE);
171 textGLListener.attachInputListenerTo(window);
172 window.addGLEventListener(textGLListener);
173 textGLListener.setHeadBox(2, true);
174 window.display();
175 // final AABBox headbox = textGLListener.getHeadBox();
176 // GPUTextRendererListenerBase01.upsizeWindowSurface(window, false, (int)(headbox.getWidth()*1.5f), (int)(headbox.getHeight()*2f));
177
178 final Runnable action_per_font = new Runnable() {
179 @Override
180 public void run() {
181 textGLListener.setHeadBox(1, false);
182 window.display();
183 textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
184 sleep();
185
186 textGLListener.setHeadBox(2, false);
187 window.display();
188 textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
189 sleep();
190 } };
191
192 for(final Font f : fontSet) {
193 if( textGLListener.setFont(f) ) {
194 for(final int aaQuality : aaQualitySet ) {
195 textGLListener.getRenderer().setAAQuality(aaQuality);
196 for(final int sampleCount : sampleSet ) {
197 textGLListener.getRenderer().setSampleCount(sampleCount);
198 action_per_font.run();
199 }
200 }
201 }
202 }
203 destroyWindow(window);
204 }
205
206 @Test
207 public void test10TextRendererMSAA01() throws InterruptedException, GLException, IOException {
208 if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
209 // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
210 System.err.println("disabled on non desktop (x86) arch for now ..");
211 return;
212 }
213 final GLProfile glp = GLProfile.getGL2ES2();
214
215 final GLCapabilities caps = new GLCapabilities(glp);
216 caps.setAlphaBits(4);
217 System.err.println("Requested: "+caps);
218
219 final GLWindow window = createWindow("TTRN20", caps, win_width, win_height);
220 window.display();
221 System.err.println("Chosen: "+window.getChosenGLCapabilities());
222
223 final TextGLListener textGLListener = new TextGLListener(glp, Region.MSAA_RENDERING_BIT, -1, 4 /* sampleCount */, DEBUG, TRACE);
224 textGLListener.attachInputListenerTo(window);
225 window.addGLEventListener(textGLListener);
226 textGLListener.setHeadBox(2, true);
227 window.display();
228 // final AABBox headbox = textGLListener.getHeadBox();
229 // GPUTextRendererListenerBase01.upsizeWindowSurface(window, false, (int)(headbox.getWidth()*1.5f), (int)(headbox.getHeight()*2f));
230
231 final Runnable action_per_font = new Runnable() {
232 @Override
233 public void run() {
234 textGLListener.setHeadBox(1, false);
235 window.display();
236 textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
237 sleep();
238
239 textGLListener.setHeadBox(2, false);
240 window.display();
241 textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
242 sleep();
243 } };
244
245 for(final Font f : fontSet) {
246 if( textGLListener.setFont(f) ) {
247 for(final int sampleCount : sampleSet ) {
248 textGLListener.getRenderer().setSampleCount(sampleCount);
249 action_per_font.run();
250 }
251 }
252 }
253 destroyWindow(window);
254 }
255
256 @Test
257 public void test20TextRendererFSAA01() throws InterruptedException, GLException, IOException {
259 final GLCapabilities caps = new GLCapabilities(glp);
260 caps.setAlphaBits(4);
261 caps.setSampleBuffers(true);
262 caps.setNumSamples(4);
263 System.err.println("Requested: "+caps);
264
265 final GLWindow window = createWindow("TTRN20", caps, win_width, win_height);
266 window.display();
267 System.err.println("Chosen: "+window.getChosenGLCapabilities());
268
269 final TextGLListener textGLListener = new TextGLListener(glp, Region.NORM_RENDERING_BIT, -1, 0 /* sampleCount */, DEBUG, TRACE);
270 textGLListener.attachInputListenerTo(window);
271 window.addGLEventListener(textGLListener);
272 textGLListener.setHeadBox(2, true);
273 window.display();
274
275 final Runnable action_per_font = new Runnable() {
276 @Override
277 public void run() {
278 textGLListener.setHeadBox(1, false);
279 window.display();
280 textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
281 sleep();
282
283 textGLListener.setHeadBox(2, false);
284 window.display();
285 textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
286 sleep();
287 } };
288
289 for(final Font f : fontSet) {
290 if( textGLListener.setFont(f) ) {
291 action_per_font.run();
292 }
293 }
294 destroyWindow(window);
295 }
296
297 @Test
298 public void test30TextRendererNoSampling() throws InterruptedException, GLException, IOException {
300 final GLCapabilities caps = new GLCapabilities(glp);
301 caps.setAlphaBits(4);
302 System.err.println("Requested: "+caps);
303
304 final GLWindow window = createWindow("TTRN20", caps, win_width, win_height);
305 window.display();
306 System.err.println("Chosen: "+window.getChosenGLCapabilities());
307
308 final TextGLListener textGLListener = new TextGLListener(glp, Region.NORM_RENDERING_BIT, -1, 0 /* sampleCount */, DEBUG, TRACE);
309 textGLListener.attachInputListenerTo(window);
310 window.addGLEventListener(textGLListener);
311 textGLListener.setHeadBox(2, true);
312 window.display();
313
314 final Runnable action_per_font = new Runnable() {
315 @Override
316 public void run() {
317 textGLListener.setHeadBox(1, false);
318 window.display();
319 textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
320 sleep();
321
322 textGLListener.setHeadBox(2, false);
323 window.display();
324 textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
325 sleep();
326 } };
327
328 for(final Font f : fontSet) {
329 if( textGLListener.setFont(f) ) {
330 action_per_font.run();
331 }
332 }
333 destroyWindow(window);
334 }
335
336 private static class TextGLListener extends GPUTextRendererListenerBase01 {
337 public TextGLListener(final GLProfile glp, final int type, final int aaQuality, final int sampleCount, final boolean debug, final boolean trace) {
338 super(glp, type, aaQuality, sampleCount, true, debug, trace);
339 }
340
341 @Override
342 public void attachInputListenerTo(final GLWindow window) {
343 super.attachInputListenerTo(window);
344 }
345
346 @Override
347 public void init(final GLAutoDrawable drawable) {
348 super.init(drawable);
349
350 final GL2ES2 gl = drawable.getGL().getGL2ES2();
351 gl.setSwapInterval(1);
353 System.err.println(JoglVersion.getGLInfo(gl, null, false /* withCapsAndExts */).toString());
354 MSAATool.dump(drawable);
355
356 getRenderer().setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
357 }
358
359 @Override
360 public void display(final GLAutoDrawable drawable) {
361 super.display(drawable);
362 }
363 }
364}
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
static final int MSAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:95
static final int DEFAULT_AA_QUALITY
Default pass2 AA-quality rendering {@value} for Graph Region AA render-modes: VBAA_RENDERING_BIT.
Definition: Region.java:168
static final int NORM_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:79
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:115
The optional property jogamp.graph.font.ctor allows user to specify the FontConstructor implementatio...
static final FontSet get(final int font)
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
Specifies a set of OpenGL capabilities.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static StringBuilder getGLInfo(final GL gl, final StringBuilder sb)
Interface wrapper for font implementation.
Definition: Font.java:60
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
void glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expr...
Definition: GL.java:43