1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
/**
* Copyright 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
package com.jogamp.opengl.test.junit.graph;
import java.io.IOException;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLCapabilitiesImmutable;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.math.geom.AABBox;
import jogamp.common.os.PlatformPropsImpl;
import org.junit.Assert;
import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jogamp.common.os.Platform;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.font.FontFactory;
import com.jogamp.graph.font.FontSet;
import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.test.junit.graph.demos.GPUTextRendererListenerBase01;
import com.jogamp.opengl.test.junit.util.UITestCase;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestTextRendererNEWT01 extends UITestCase {
static final boolean DEBUG = false;
static final boolean TRACE = false;
static long duration = 100; // ms
static int win_width = 1024;
static int win_height = 640;
static int atoi(final String a) {
try {
return Integer.parseInt(a);
} catch (final Exception ex) { throw new RuntimeException(ex); }
}
public static void main(final String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
i++;
duration = atoi(args[i]);
} else if(args[i].equals("-width")) {
i++;
win_width = atoi(args[i]);
} else if(args[i].equals("-height")) {
i++;
win_height = atoi(args[i]);
}
}
final String tstname = TestTextRendererNEWT01.class.getName();
org.junit.runner.JUnitCore.main(tstname);
}
static void sleep() {
try {
System.err.println("** new frame ** (sleep: "+duration+"ms)");
Thread.sleep(duration);
} catch (final InterruptedException ie) {}
}
static void destroyWindow(final GLWindow window) {
if(null!=window) {
window.destroy();
}
}
static GLWindow createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height) {
Assert.assertNotNull(caps);
final GLWindow window = GLWindow.create(caps);
window.setSize(width, height);
window.setPosition(10, 10);
window.setTitle(title);
Assert.assertNotNull(window);
window.setVisible(true);
return window;
}
@Test
public void testTextRendererR2T01() throws InterruptedException, GLException, IOException {
if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
// FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
System.err.println("disabled on non desktop (x86) arch for now ..");
return;
}
final GLProfile glp = GLProfile.getGL2ES2();
final GLCapabilities caps = new GLCapabilities(glp);
caps.setAlphaBits(4);
System.err.println("Requested: "+caps);
final GLWindow window = createWindow("text-vbaa1-msaa0", caps, win_width, win_height);
window.display();
System.err.println("Chosen: "+window.getChosenGLCapabilities());
final RenderState rs = RenderState.createRenderState(SVertex.factory());
final TextGLListener textGLListener = new TextGLListener(rs, Region.VBAA_RENDERING_BIT, 4 /* sampleCount */, DEBUG, TRACE);
textGLListener.attachInputListenerTo(window);
window.addGLEventListener(textGLListener);
textGLListener.setHeadBox(2, true);
window.display();
// final AABBox headbox = textGLListener.getHeadBox();
// GPUTextRendererListenerBase01.upsizeWindowSurface(window, false, (int)(headbox.getWidth()*1.5f), (int)(headbox.getHeight()*2f));
final Runnable action_per_font = new Runnable() {
@Override
public void run() {
textGLListener.setHeadBox(1, false);
textGLListener.setSampleCount(2);
window.display();
textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
sleep();
textGLListener.setHeadBox(2, false);
textGLListener.setSampleCount(2);
window.display();
textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
sleep();
textGLListener.setHeadBox(1, false);
textGLListener.setSampleCount(3);
window.display();
textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
sleep();
textGLListener.setHeadBox(2, false);
textGLListener.setSampleCount(3);
window.display();
textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
sleep();
textGLListener.setHeadBox(1, false);
textGLListener.setSampleCount(4);
window.display();
textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
sleep();
textGLListener.setHeadBox(2, false);
textGLListener.setSampleCount(4);
window.display();
textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
sleep();
} };
if(textGLListener.setFontSet(FontFactory.UBUNTU, FontSet.FAMILY_LIGHT, FontSet.STYLE_NONE)) {
action_per_font.run();
}
if(textGLListener.setFontSet(FontFactory.UBUNTU, FontSet.FAMILY_REGULAR, FontSet.STYLE_NONE)) {
action_per_font.run();
}
if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
action_per_font.run();
}
destroyWindow(window);
}
@Test
public void testTextRendererMSAA01() throws InterruptedException, GLException, IOException {
final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
final GLCapabilities caps = new GLCapabilities(glp);
caps.setAlphaBits(4);
caps.setSampleBuffers(true);
caps.setNumSamples(4);
System.err.println("Requested: "+caps);
final GLWindow window = createWindow("text-vbaa0-msaa1", caps, 1024, 640);
window.display();
System.err.println("Chosen: "+window.getChosenGLCapabilities());
final RenderState rs = RenderState.createRenderState(SVertex.factory());
final TextGLListener textGLListener = new TextGLListener(rs, 0, 0 /* sampleCount */, DEBUG, TRACE);
textGLListener.attachInputListenerTo(window);
window.addGLEventListener(textGLListener);
textGLListener.setHeadBox(2, true);
window.display();
final Runnable action_per_font = new Runnable() {
@Override
public void run() {
textGLListener.setHeadBox(1, false);
textGLListener.setSampleCount(0);
window.display();
textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
sleep();
textGLListener.setHeadBox(2, false);
textGLListener.setSampleCount(0);
window.display();
textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
sleep();
} };
if(textGLListener.setFontSet(FontFactory.UBUNTU, FontSet.FAMILY_LIGHT, FontSet.STYLE_NONE)) {
action_per_font.run();
}
if(textGLListener.setFontSet(FontFactory.UBUNTU, FontSet.FAMILY_REGULAR, FontSet.STYLE_NONE)) {
action_per_font.run();
}
if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
action_per_font.run();
}
destroyWindow(window);
}
private static class TextGLListener extends GPUTextRendererListenerBase01 {
public TextGLListener(final RenderState rs, final int type, final int sampleCount, final boolean debug, final boolean trace) {
super(rs, type, sampleCount, true, debug, trace);
}
@Override
public void attachInputListenerTo(final GLWindow window) {
super.attachInputListenerTo(window);
}
public void setSampleCount(final int sampleCount){
// setMatrix(xt, yt, zoom, angle, sampleCount);
setMatrix(0, 0, 0, 0f, sampleCount);
}
@Override
public void init(final GLAutoDrawable drawable) {
super.init(drawable);
final GL2ES2 gl = drawable.getGL().getGL2ES2();
gl.setSwapInterval(1);
gl.glEnable(GL.GL_DEPTH_TEST);
final RenderState rs = getRenderer().getRenderState();
rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
}
@Override
public void display(final GLAutoDrawable drawable) {
super.display(drawable);
}
}
}
|