28package com.jogamp.opengl.test.junit.graph;
31import java.io.IOException;
32import java.util.Locale;
34import com.jogamp.opengl.GL;
35import com.jogamp.opengl.GL2ES2;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLDrawable;
38import com.jogamp.opengl.GLException;
39import com.jogamp.opengl.GLProfile;
41import org.junit.Assert;
42import org.junit.BeforeClass;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
47import com.jogamp.common.util.IOUtil;
48import com.jogamp.graph.curve.Region;
49import com.jogamp.graph.curve.opengl.RenderState;
50import com.jogamp.graph.curve.opengl.RegionRenderer;
51import com.jogamp.graph.curve.opengl.TextRegionUtil;
52import com.jogamp.graph.font.Font;
53import com.jogamp.graph.font.FontFactory;
54import com.jogamp.graph.font.FontScale;
55import com.jogamp.graph.font.FontSet;
56import com.jogamp.math.geom.AABBox;
57import com.jogamp.math.util.PMVMatrix4f;
58import com.jogamp.opengl.test.junit.util.MiscUtils;
59import com.jogamp.opengl.test.junit.util.NEWTGLContext;
60import com.jogamp.opengl.test.junit.util.UITestCase;
61import com.jogamp.opengl.util.GLReadBufferUtil;
69@FixMethodOrder(MethodSorters.NAME_ASCENDING)
71 static final boolean DEBUG =
false;
72 static final boolean TRACE =
false;
73 static long duration = 100;
74 static boolean forceES2 =
false;
75 static boolean forceGL3 =
false;
76 static boolean mainRun =
false;
77 static boolean useMSAA =
true;
78 static int win_width = 1024;
79 static int win_height = 640;
82 static float fontSize = 24;
83 static String customStr =
null;
86 public static void setup() throws IOException {
92 static int atoi(
final String a) {
94 return Integer.parseInt(a);
95 }
catch (
final Exception ex) {
throw new RuntimeException(ex); }
98 public static void main(
final String args[])
throws IOException {
100 for(
int i=0; i<args.length; i++) {
101 if(args[i].equals(
"-time")) {
103 duration = atoi(args[i]);
104 }
else if(args[i].equals(
"-width")) {
106 win_width = atoi(args[i]);
107 }
else if(args[i].equals(
"-height")) {
109 win_height = atoi(args[i]);
110 }
else if(args[i].equals(
"-noMSAA")) {
112 }
else if(args[i].equals(
"-es2")) {
114 }
else if(args[i].equals(
"-gl3")) {
116 }
else if(args[i].equals(
"-font")) {
119 }
else if(args[i].equals(
"-fontSize")) {
122 }
else if(args[i].equals(
"-text")) {
128 org.junit.runner.JUnitCore.
main(tstname);
131 static void sleep() {
133 System.err.println(
"** new frame ** (sleep: "+duration+
"ms)");
134 Thread.sleep(duration);
135 }
catch (
final InterruptedException ie) {}
140 testTextRendererImpl(0, 0);
145 testTextRendererImpl(0, 4);
153 void testTextRendererImpl(
final int renderModes,
final int sampleCount)
throws InterruptedException,
GLException, IOException {
157 }
else if(forceES2) {
165 if( 0 < sampleCount && !Region.isVBAA(renderModes) ) {
169 System.err.println(
"Requested: "+caps);
170 System.err.println(
"Requested: "+Region.getRenderModeString(renderModes));
172 final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(caps, win_width, win_height,
true);
173 final GLDrawable drawable = winctx.context.getGLDrawable();
174 final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
176 Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
178 System.err.println(
"Chosen: "+winctx.window.getChosenCapabilities());
180 final RegionRenderer renderer = RegionRenderer.create(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
181 renderer.setHintBits(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
182 final TextRegionUtil textRenderUtil =
new TextRegionUtil(renderModes);
185 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
187 renderer.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
188 screenshot =
new GLReadBufferUtil(
false,
false);
191 gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
194 renderer.reshapeOrtho(drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0.1f, 1000.0f);
195 final int z0 = -1000;
197 final int[] sampleCountIO = { sampleCount };
199 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
200 if(
null == customStr ) {
202 final float[] pixelsPerMM = winctx.window.getPixelsPerMM(
new float[2]);
203 final float[] dpi = FontScale.ppmmToPPI(pixelsPerMM,
new float[2]);
204 final float mmSize = fontSize / pixelsPerMM[1];
206 String txt = String.format(
"Resolution dpiV %.2f, %.2f px/mm", dpi[1], pixelsPerMM[1]);
207 renderString(drawable, gl, renderer, textRenderUtil, txt, 0, 0, z0, sampleCountIO);
208 txt = String.format(
"Font %s, unitsPerEM %d, size %.2f px %2f mm", font.
getFullFamilyName(), unitsPerEM, fontSize, mmSize);
209 renderString(drawable, gl, renderer, textRenderUtil, txt, 0, -1, z0, sampleCountIO);
211 renderString(drawable, gl, renderer, textRenderUtil,
"012345678901234567890123456789", 0, -1, z0, sampleCountIO);
212 renderString(drawable, gl, renderer, textRenderUtil,
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, z0, sampleCountIO);
213 renderString(drawable, gl, renderer, textRenderUtil,
"Hello World", 0, -1, z0, sampleCountIO);
214 renderString(drawable, gl, renderer, textRenderUtil,
"4567890123456", 4, -1, z0,sampleCountIO);
215 renderString(drawable, gl, renderer, textRenderUtil,
"I like JogAmp", 4, -1, z0, sampleCountIO);
218 renderString(drawable, gl, renderer, textRenderUtil,
"GlueGen", c++, -1, z0, sampleCountIO);
219 renderString(drawable, gl, renderer, textRenderUtil,
"JOAL", c++, -1, z0, sampleCountIO);
220 renderString(drawable, gl, renderer, textRenderUtil,
"JOGL", c++, -1, z0, sampleCountIO);
221 renderString(drawable, gl, renderer, textRenderUtil,
"JOCL", c++, -1, z0, sampleCountIO);
223 renderString(drawable, gl, renderer, textRenderUtil, customStr, 0, 0, z0, sampleCountIO);
226 printScreen(renderModes, drawable, gl,
false, sampleCount);
227 drawable.swapBuffers();
232 screenshot.dispose(gl);
233 renderer.destroy(gl);
235 NEWTGLContext.destroyWindow(winctx);
238 private GLReadBufferUtil screenshot;
241 void renderString(
final GLDrawable drawable,
final GL2ES2 gl,
final RegionRenderer renderer,
final TextRegionUtil textRenderUtil,
final String text,
242 final int column,
int row,
final int z0,
final int[] sampleCount)
244 final int height = drawable.getSurfaceHeight();
253 dy -= fontSize * textBox.getHeight() * ( row + 1 );
255 final PMVMatrix4f pmv = renderer.getMatrix();
256 pmv.loadMvIdentity();
257 pmv.translateMv(dx, dy, z0);
258 pmv.scaleMv(fontSize, fontSize, 1.0f);
259 textRenderUtil.drawString3D(gl, renderer, font, text,
null);
264 private int screenshot_num = 0;
267 final String dir =
"./";
268 final String objName = getSimpleTestName(
".")+
"-snap"+screenshot_num;
271 final String bname = String.format((Locale)
null,
"%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
272 drawable.getChosenGLCapabilities().getNumSamples(),
273 fontSize, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, sampleCount);
274 final String filename = dir + bname +
".png";
275 if(screenshot.readPixels(gl,
false)) {
276 screenshot.write(
new File(filename));
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
static String getRenderModeString(final int renderModes)
Returns a unique technical description string for renderModes as follows:
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
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}.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
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.
static final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
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.
TestTextRendererNEWT01 Variant.
void test02TextRendererVBAA04()
void printScreen(final int renderModes, final GLDrawable drawable, final GL gl, final boolean exportAlpha, final int sampleCount)
void test01TextRendererMSAA04()
void test00TextRendererNONE00()
static void main(final String args[])
static float atof(final String str, final float def)
static final int FAMILY_LIGHT
Font family LIGHT, {@value}.
Font get(int family, int stylebits)
static final int STYLE_NONE
Zero style, {@value}.
int getUnitsPerEM()
Returns the font's units per EM from the 'head' table.
Interface wrapper for font implementation.
AABBox getMetricBounds(final CharSequence string)
Returns metric-bounds in font em-size.
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
int getGlyphID(final char codepoint)
Returns the Glyph ID mapped to given UTF16 (unicode) codepoint symbol.
float getAdvanceWidth(final int glyphID)
Returns advance-width of given glyphID in font em-size [0..1], sourced from hmtx table - same as Glyp...
An abstraction for an OpenGL rendering target.