JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
GPUTextNewtDemo.java
Go to the documentation of this file.
1/**
2 * Copyright 2010-2023 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.demos.graph;
29
30import com.jogamp.opengl.GLCapabilities;
31import com.jogamp.opengl.GLProfile;
32import com.jogamp.opengl.demos.util.MiscUtils;
33
34import java.io.File;
35import java.io.IOException;
36
37import com.jogamp.common.util.InterruptSource;
38import com.jogamp.graph.curve.Region;
39import com.jogamp.graph.font.Font;
40import com.jogamp.graph.font.FontFactory;
41import com.jogamp.graph.font.FontScale;
42import com.jogamp.math.geom.AABBox;
43import com.jogamp.newt.MonitorDevice;
44import com.jogamp.newt.event.KeyAdapter;
45import com.jogamp.newt.event.KeyEvent;
46import com.jogamp.newt.event.WindowAdapter;
47import com.jogamp.newt.event.WindowEvent;
48import com.jogamp.newt.opengl.GLWindow;
49import com.jogamp.opengl.util.Animator;
50
51public class GPUTextNewtDemo {
52 /**
53 * FIXME:
54 *
55 * If DEBUG is enabled:
56 *
57 * Caused by: com.jogamp.opengl.GLException: Thread[main-Display-X11_:0.0-1-EDT-1,5,main] glGetError() returned the following error codes after a call to glFramebufferRenderbuffer(<int> 0x8D40, <int> 0x1902, <int> 0x8D41, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500),
58 * at com.jogamp.opengl.DebugGL4bc.checkGLGetError(DebugGL4bc.java:33961)
59 * at com.jogamp.opengl.DebugGL4bc.glFramebufferRenderbuffer(DebugGL4bc.java:33077)
60 * at jogamp.graph.curve.opengl.VBORegion2PGL3.initFBOTexture(VBORegion2PGL3.java:295)
61 */
62 static final boolean DEBUG = false;
63 static final boolean TRACE = false;
64
65 static int SceneMSAASamples = 0;
66 static int GraphVBAASamples = 4;
67 static int GraphMSAASamples = 0;
68
69 public static void main(final String[] args) throws IOException {
70 Font opt_font = null;
71 int opt_fontSizeHead = -1;
72 int width = 800, height = 400;
73 int x = 10, y = 10;
74 if( 0 != args.length ) {
75 for(int i=0; i<args.length; i++) {
76 if(args[i].equals("-smsaa")) {
77 i++;
78 SceneMSAASamples = MiscUtils.atoi(args[i], SceneMSAASamples);
79 GraphMSAASamples = 0;
80 GraphVBAASamples = 0;
81 } else if(args[i].equals("-gmsaa")) {
82 i++;
83 SceneMSAASamples = 0;
84 GraphMSAASamples = MiscUtils.atoi(args[i], GraphMSAASamples);
85 GraphVBAASamples = 0;
86 } else if(args[i].equals("-gvbaa")) {
87 i++;
88 SceneMSAASamples = 0;
89 GraphMSAASamples = 0;
90 GraphVBAASamples = MiscUtils.atoi(args[i], GraphVBAASamples);
91 } else if(args[i].equals("-width")) {
92 i++;
93 width = MiscUtils.atoi(args[i], width);
94 } else if(args[i].equals("-height")) {
95 i++;
96 height = MiscUtils.atoi(args[i], height);
97 } else if(args[i].equals("-x")) {
98 i++;
99 x = MiscUtils.atoi(args[i], x);
100 } else if(args[i].equals("-y")) {
101 i++;
102 y = MiscUtils.atoi(args[i], y);
103 } else if(args[i].equals("-font")) {
104 i++;
105 opt_font = FontFactory.get(new File(args[i]));
106 } else if(args[i].equals("-fontSize")) {
107 i++;
108 opt_fontSizeHead = MiscUtils.atoi(args[i], opt_fontSizeHead);
109 }
110 }
111 }
112 System.err.println("Desired win size "+width+"x"+height);
113 System.err.println("Desired win pos "+x+"/"+y);
114 System.err.println("Scene MSAA Samples "+SceneMSAASamples);
115 System.err.println("Graph MSAA Samples "+GraphMSAASamples);
116 System.err.println("Graph VBAA Samples "+GraphVBAASamples);
117
118 final GLProfile glp = GLProfile.getGL2ES2();
119
120 final GLCapabilities caps = new GLCapabilities(glp);
121 caps.setAlphaBits(4);
122 if( SceneMSAASamples > 0 ) {
123 caps.setSampleBuffers(true);
124 caps.setNumSamples(SceneMSAASamples);
125 }
126 System.out.println("Requested: " + caps);
127
128 int rmode = 0; // Region.VARIABLE_CURVE_WEIGHT_BIT;
129 int sampleCount = 0;
130 if( GraphVBAASamples > 0 ) {
131 rmode |= Region.VBAA_RENDERING_BIT;
132 sampleCount += GraphVBAASamples;
133 } else if( GraphMSAASamples > 0 ) {
134 rmode |= Region.MSAA_RENDERING_BIT;
135 sampleCount += GraphMSAASamples;
136 }
137
138 final GLWindow window = GLWindow.create(caps);
139 window.setPosition(x, y);
140 window.setSize(width, height);
141 window.setTitle("GPU Text Newt Demo - graph[vbaa"+GraphVBAASamples+" msaa"+GraphMSAASamples+"], msaa "+SceneMSAASamples);
142
143 final GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(glp, rmode, Region.DEFAULT_AA_QUALITY, sampleCount, true, DEBUG, TRACE);
144 textGLListener.setFont(opt_font);
145 textGLListener.setFontHeadSize(opt_fontSizeHead);
146 // ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32);
147 window.addGLEventListener(textGLListener);
148 window.setVisible(true);
149
150 {
151 final Font font2 = textGLListener.getFont();
152 final float[] sDPI = FontScale.ppmmToPPI( window.getPixelsPerMM(new float[2]) );
153 final float font_ptpi = 12f;
154 final float font_ppi = FontScale.toPixels(font_ptpi, sDPI[1]);
156 System.err.println("GPU Text Newt Demo: "+font2.fullString());
157 System.err.println("GPU Text Newt Demo: screen-dpi: "+sDPI[0]+"x"+sDPI[1]+", font "+font_ptpi+" pt, "+font_ppi+" pixel");
158 System.err.println("GPU Text Newt Demo: textX2: "+fontNameBox+" em, "+fontNameBox.scale(font_ppi)+" px");
159 final MonitorDevice monitor = window.getMainMonitor();
160 System.err.println("GPU Text Newt Demo: "+monitor);
161 // window.setSurfaceSize((int)(fontNameBox.getWidth()*1.1f), (int)(fontNameBox.getHeight()*2f));
162 }
163
164 // FPSAnimator animator = new FPSAnimator(60);
165 final Animator animator = new Animator(0 /* w/o AWT */);
166 animator.setUpdateFPSFrames(60, null);
167 animator.add(window);
168
169 window.addKeyListener(new KeyAdapter() {
170 @Override
171 public void keyPressed(final KeyEvent arg0) {
172 final short keySym = arg0.getKeySymbol();
173 if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) {
174 new InterruptSource.Thread( () -> { window.destroy(); } ).start();
175 }
176 }
177 });
178 window.addWindowListener(new WindowAdapter() {
179 @Override
180 public void windowDestroyed(final WindowEvent e) {
181 animator.stop();
182 }
183 });
184
185 animator.start();
186 }
187}
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 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)
Simple static font scale methods for unit conversions.
Definition: FontScale.java:37
static float[] ppmmToPPI(final float[] ppmm)
Converts [1/mm] to [1/inch] in place.
Definition: FontScale.java:105
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...
Definition: FontScale.java:76
Axis Aligned Bounding Box.
Definition: AABBox.java:54
final AABBox scale(final float s)
Scale this AABBox by a constant around fixed center.
Definition: AABBox.java:750
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
Visual output device, i.e.
static final short VK_F4
Constant for the F4 function key.
Definition: KeyEvent.java:686
static final short VK_ESCAPE
Constant for the ESCAPE function key.
Definition: KeyEvent.java:485
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
Definition: KeyEvent.java:176
static final short VK_Q
See VK_A.
Definition: KeyEvent.java:627
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
Definition: GLWindow.java:525
final void setTitle(final String title)
Definition: GLWindow.java:297
final float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter of this window's NativeSurface according to the main monitor's curr...
Definition: GLWindow.java:520
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final MonitorDevice getMainMonitor()
Returns the MonitorDevice with the highest viewport coverage of this window.
Definition: GLWindow.java:292
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
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.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static void main(final String[] args)
static int atoi(final String str, final int def)
Definition: MiscUtils.java:60
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
Interface wrapper for font implementation.
Definition: Font.java:60
AABBox getMetricBounds(final CharSequence string)
Returns metric-bounds in font em-size.
String fullString()
Returns all font details as string.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.