28package com.jogamp.opengl.test.junit.graph;
30import java.io.IOException;
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;
74 private final GLRegion regionFPS, regionHead, regionBottom;
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;
87 final int fontSizeModulo = 100;
96 static final String text2 =
"The quick brown fox jumps over the lazy dog";
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";
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---------";
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---------";
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---------";
146 static final String textXLast =
"abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
148 Window upstream_window =
null;
149 StringBuilder userString =
new StringBuilder(
textX1);
150 boolean userInput =
false;
154 renderModes, debug, trace);
159 this.regionBottom =
GLRegion.
create(glp, renderModes,
null, 0, 0);
166 void switchHeadBox() {
171 public void setHeadBox(
final int choice,
final boolean resize) {
172 headType = choice % 5 ;
189 headtext = textXLast;
191 if(resize &&
null != headtext) {
200 public void setHeadBox(
final String text,
final boolean resize) {
202 if(resize &&
null != headtext) {
212 if(
null == window ) {
219 new InterruptSource.Thread() {
231 super.init(drawable);
233 if( upObj instanceof
Window ) {
234 upstream_window = (
Window) upObj;
235 final float[] sPpMM = upstream_window.
getPixelsPerMM(
new float[2]);
239 System.err.println(
"Using vertical screen DPI of "+dpiV+
", "+ppmmV+
" pixel/mm");
241 System.err.println(
"Using vertical default DPI of "+dpiV+
", "+ppmmV+
" pixel/mm");
247 System.err.println(
"XXX: fontName size "+fontSizeFName+
"pt, dpiV "+dpiV+
" -> "+pixelSizeFName+
"px");
250 System.err.println(
"XXX: fontName boxM em "+font.
getMetricBounds(fontName));
252 System.err.println(
"XXX: fontName box height px "+(fontNameBox.
getHeight() * pixelSizeFName));
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);
260 if( upObj instanceof
Window ) {
261 upstream_window = (
Window) upObj;
263 final float dist = 100f;
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);
274 float nearPlaneX0, nearPlaneY0, nearPlaneZ0, nearPlaneSx, nearPlaneSy, nearPlaneS;
278 upstream_window =
null;
282 super.dispose(drawable);
288 if( upObj instanceof
Window ) {
289 upstream_window = (
Window) upObj;
310 final float mmSizeHead = pixelSizeHead / ppmmV;
312 final float mmSizeCenter = pixelSizeCenter / ppmmV;
316 renderer.
enable(gl,
true);
321 final float lfps, tfps;
323 if(
null != animator ) {
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",
333 fontSizeHead, pixelSizeHead, mmSizeHead,
334 fontSizeCenter, pixelSizeCenter, mmSizeCenter,
340 pmv.
translateMv(nearPlaneX0, nearPlaneY0+(nearPlaneS * pixelSizeFPS / 2f), nearPlaneZ0);
342 final float sxy = nearPlaneS * pixelSizeFPS;
352 float dy = height - fontNameBox.
getHeight() * pixelSizeFName;
355 pmv.
translateMv(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
357 final float sxy = nearPlaneS * pixelSizeFName;
366 dy += -fontNameBox.
getHeight() * pixelSizeFName - 10f;
368 if(
null != headtext) {
371 pmv.
translateMv(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
373 final float sxy = nearPlaneS * pixelSizeHead;
387 pmv.
translateMv(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
389 final float sxy = nearPlaneS * pixelSizeFName;
401 pmv.
translateMv(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
406 final float sxy = nearPlaneS * pixelSizeCenter;
411 if( bottomTextUseFrustum ) {
415 if( bottomTextUseFrustum ) {
421 if( bottomTextUseFrustum ) {
429 renderer.
enable(gl,
false);
431 final boolean bottomTextUseFrustum =
true;
437 fontSizeCenter = Math.abs((fontSizeCenter + v) % fontSizeModulo) ;
442 fontSizeHead = Math.abs((fontSizeHead + v) % fontSizeModulo) ;
444 if(
null != headtext) {
451 fontSizeHead = v % fontSizeModulo;
453 if(
null != headtext) {
469 }
catch (
final IOException ex) {
470 System.err.println(
"Caught: "+ex.getMessage());
475 public boolean setFontSet(
final int set,
final int family,
final int stylebits) {
484 }
catch (
final IOException ex) {
485 System.err.println(
"Caught: "+ex.getMessage());
500 private void updateFontNameBox() {
507 void dumpMatrix(
final boolean bbox) {
515 KeyAction keyAction =
null;
519 if (
null == keyAction ) {
522 super.attachInputListenerTo(window);
528 super.detachInputListenerFrom(window);
529 if (
null == keyAction ) {
542 final String fsaa =
"fsaa"+drawable.getChosenGLCapabilities().getNumSamples();
543 super.printScreen(drawable, dir, tech+
"-"+modes, fsaa+
"-"+fn+
"-text"+
getHeadBoxType()+
"-"+objName, exportAlpha);
546 float fontHeadScale = 1f;
595 userString.deleteCharAt(userString.length()-1);
599 userString.append(c);
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:
final void setFrustum(final Frustum frustum)
Set Frustum culling for addOutlineShape(OutlineShape, AffineTransform, float[]).
final int getRenderModes()
Returns bit-field of render modes, see create(..).
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
final GLRegion clear(final GL2ES2 gl)
Clears all buffers, i.e.
final void destroy(final GL2ES2 gl)
Delete and clear the associated OGL objects.
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.
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.
final void setHintBits(final int mask)
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.
static float[] ppmmToPPI(final float[] ppmm)
Converts [1/mm] to [1/inch] in place.
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...
Axis Aligned Bounding Box.
final AABBox scale(final float s)
Scale this AABBox by a constant around fixed center.
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 char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
static final short VK_ENTER
Constant for the ENTER key, i.e.
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
static final short VK_4
See VK_0.
static final short VK_SPACE
Constant for the SPACE function key.
static final short VK_H
See VK_A.
static final short VK_F
See VK_A.
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
static final short VK_I
See VK_A.
static final short VK_3
See VK_0.
static final short VK_BACK_SPACE
Constant for the BACK SPACE key "\b", matching ASCII.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final void removeKeyListener(final KeyListener l)
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
final float getAngleRad()
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 setIgnoreInput(final boolean v)
final float getAngleDeg()
final int getRenderModes()
final RegionRenderer getRenderer()
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.
GPURendererListenerBase01 Keys:
final TextRegionUtil textRegionUtil
void setHeadBox(final String text, final boolean resize)
final AffineTransform tempT1
void setFontHeadSize(final int v)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
final AffineTransform tempT2
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,...
static final String textX2
static final String textX1
static final String textX20
void fontHeadIncr(final int v)
void attachInputListenerTo(final GLWindow window)
Attach the input listener to the window.
static final String text_help
void setHeadBox(final int choice, final boolean resize)
void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha)
boolean setFont(final Font _font)
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.
void detachInputListenerFrom(final GLWindow window)
boolean isUserInputMode()
void fontBottomIncr(final int v)
static final int FAMILY_LIGHT
Font family LIGHT, {@value}.
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}.
Interface wrapper for font implementation.
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:
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 ...
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...
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...