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;
43import org.junit.FixMethodOrder;
44import org.junit.runners.MethodSorters;
46import com.jogamp.graph.curve.Region;
47import com.jogamp.graph.curve.opengl.RenderState;
48import com.jogamp.graph.curve.opengl.RegionRenderer;
49import com.jogamp.graph.curve.opengl.TextRegionUtil;
50import com.jogamp.graph.font.Font;
51import com.jogamp.math.geom.AABBox;
52import com.jogamp.math.util.PMVMatrix4f;
53import com.jogamp.opengl.test.junit.util.NEWTGLContext;
54import com.jogamp.opengl.test.junit.util.UITestCase;
55import com.jogamp.opengl.util.GLReadBufferUtil;
58@FixMethodOrder(MethodSorters.NAME_ASCENDING)
60 static long duration = 100;
61 static boolean forceES2 =
false;
62 static boolean forceGL3 =
false;
63 static boolean mainRun =
false;
64 static boolean useMSAA =
true;
65 static boolean onlyIssues =
false;
67 static final float fontSize = 24;
69 static int atoi(
final String a) {
71 return Integer.parseInt(a);
72 }
catch (
final Exception ex) {
throw new RuntimeException(ex); }
75 public static void main(
final String args[])
throws IOException {
77 for(
int i=0; i<args.length; i++) {
78 if(args[i].equals(
"-time")) {
80 duration = atoi(args[i]);
81 }
else if(args[i].equals(
"-noMSAA")) {
83 }
else if(args[i].equals(
"-es2")) {
85 }
else if(args[i].equals(
"-gl3")) {
90 org.junit.runner.JUnitCore.
main(tstname);
95 System.err.println(
"** new frame ** (sleep: "+duration+
"ms)");
96 Thread.sleep(duration);
97 }
catch (
final InterruptedException ie) {}
108 void testTextRendererImpl(
final Font[] fonts,
final int renderModes,
final int sampleCount,
final boolean onlyIssues)
throws InterruptedException,
GLException, IOException {
112 }
else if(forceES2) {
120 if( 0 < sampleCount && !Region.isVBAA(renderModes) ) {
125 System.err.println(
"Requested: "+caps);
126 System.err.println(
"Requested: "+Region.getRenderModeString(renderModes));
128 final int totalHeight = ( (int)fontSize + 1 ) * ( onlyIssues ? 3 : 6 ) * fonts.length;
129 final NEWTGLContext.WindowContext winctx =
130 NEWTGLContext.createWindow(caps, 800, totalHeight,
true);
131 final GLDrawable drawable = winctx.context.getGLDrawable();
132 final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
134 Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
136 System.err.println(
"Chosen: "+winctx.window.getChosenCapabilities());
138 final RegionRenderer renderer = RegionRenderer.create(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
139 renderer.setHintBits(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
140 final TextRegionUtil textRenderUtil =
new TextRegionUtil(renderModes);
143 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
145 renderer.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
146 screenshot =
new GLReadBufferUtil(
false,
false);
149 gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
152 renderer.reshapeOrtho(drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0.1f, 1000.0f);
154 final int[] sampleCountIO = { sampleCount };
156 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
157 for(
int i=0; i<fonts.length; i++) {
158 final Font font = fonts[i];
159 renderString(drawable, gl, renderer, font, textRenderUtil, font.getFullFamilyName()+
": "+issues, 0, 0==i?0:-1, -1000, sampleCountIO);
161 renderString(drawable, gl, renderer, font, textRenderUtil,
"012345678901234567890123456789", 0, -1, -1000, sampleCountIO);
162 renderString(drawable, gl, renderer, font, textRenderUtil,
"abcdefghijklmnopqrstuvwxyz", 0, -1, -1000, sampleCountIO);
163 renderString(drawable, gl, renderer, font, textRenderUtil,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, -1, -1000, sampleCountIO);
165 renderString(drawable, gl, renderer, font, textRenderUtil,
"", 0, -1, -1000, sampleCountIO);
166 renderString(drawable, gl, renderer, font, textRenderUtil,
"", 0, -1, -1000, sampleCountIO);
169 drawable.swapBuffers();
170 printScreen(renderModes, drawable, gl,
false, sampleCount);
175 screenshot.dispose(gl);
176 renderer.destroy(gl);
178 NEWTGLContext.destroyWindow(winctx);
181 private static final String issues =
"m M n u 8 g q Q";
182 private GLReadBufferUtil screenshot;
185 void renderString(
final GLDrawable drawable,
final GL2ES2 gl,
final RegionRenderer renderer,
final Font font,
final TextRegionUtil textRenderUtil,
final String text,
final int column,
int row,
final int z0,
final int[] sampleCount) {
186 final int height = drawable.getSurfaceHeight();
193 final AABBox textBox = font.getMetricBounds(text);
194 dx += fontSize * font.getAdvanceWidth( font.getGlyphID(
'X' ) ) * column;
195 dy -= fontSize * textBox.getHeight() * ( row + 1 );
197 final PMVMatrix4f pmv = renderer.getMatrix();
198 pmv.loadMvIdentity();
199 pmv.translateMv(dx, dy, z0);
201 final float sxy = fontSize / font.getMetrics().getUnitsPerEM();
202 pmv.scaleMv(sxy, sxy, 1.0f);
204 textRenderUtil.drawString3D(gl, renderer, font, text,
null);
209 private int screenshot_num = 0;
212 final String dir =
"./";
213 final String objName = getSimpleTestName(
".")+
"-snap"+screenshot_num;
216 final String bname = String.format((Locale)
null,
"%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
217 drawable.getChosenGLCapabilities().getNumSamples(),
219 final String filename = dir + bname +
".png";
220 if(screenshot.readPixels(gl,
false)) {
221 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.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
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.
void printScreen(final int renderModes, final GLDrawable drawable, final GL gl, final boolean exportAlpha, final int sampleCount)
static void main(final String args[])
Interface wrapper for font implementation.
An abstraction for an OpenGL rendering target.