28package com.jogamp.opengl.demos.graph.ui;
31import java.io.IOException;
33import com.jogamp.common.util.InterruptSource;
34import com.jogamp.graph.curve.Region;
35import com.jogamp.graph.curve.opengl.RegionRenderer;
36import com.jogamp.graph.ui.Scene;
37import com.jogamp.graph.ui.Shape;
38import com.jogamp.graph.ui.shapes.Rectangle;
39import com.jogamp.math.FloatUtil;
40import com.jogamp.math.Vec3f;
41import com.jogamp.math.geom.Cube;
42import com.jogamp.math.geom.Frustum;
43import com.jogamp.math.geom.plane.AffineTransform;
44import com.jogamp.math.util.PMVMatrix4f;
45import com.jogamp.newt.Window;
46import com.jogamp.newt.event.KeyAdapter;
47import com.jogamp.newt.event.KeyEvent;
48import com.jogamp.newt.event.KeyListener;
49import com.jogamp.newt.event.MouseAdapter;
50import com.jogamp.newt.event.MouseEvent;
51import com.jogamp.newt.event.WindowAdapter;
52import com.jogamp.newt.event.WindowEvent;
53import com.jogamp.newt.opengl.GLWindow;
54import com.jogamp.opengl.GL;
55import com.jogamp.opengl.GL2ES2;
56import com.jogamp.opengl.GLAutoDrawable;
57import com.jogamp.opengl.GLCapabilities;
58import com.jogamp.opengl.GLEventListener;
59import com.jogamp.opengl.GLException;
60import com.jogamp.opengl.GLPipelineFactory;
61import com.jogamp.opengl.GLRunnable;
62import com.jogamp.opengl.demos.graph.MSAATool;
63import com.jogamp.opengl.demos.util.CommandlineOptions;
64import com.jogamp.opengl.util.Animator;
65import com.jogamp.opengl.util.GLReadBufferUtil;
83 static final boolean DEBUG =
false;
84 static final boolean TRACE =
false;
88 static final float szw = 1/3f * 0.8f;
89 static final float szh = szw * 1f/2f;
92 public static void main(
final String[] args)
throws IOException {
93 final int[] idx = { 0 };
94 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
95 if( options.
parse(args, idx) ) {
99 System.err.println(options);
101 System.out.println(
"Requested: " + reqCaps);
119 animator.
add(window);
123 public void keyPressed(
final KeyEvent arg0) {
125 final float less = 0.99f;
126 final float more = 1.01f;
127 final float x = clipRect.
getX();
128 final float y = clipRect.
getY();
129 final float z = clipRect.
getZ();
130 final float w = clipRect.
getWidth();
134 final float d = w*more - w;
135 clipRect.
move(-d, 0, 0);
137 final float d = w*more - w;
145 final float d = w*more - w;
146 clipRect.
move(d, 0, 0);
148 final float d = w - w*less;
156 final float d = h*more - h;
157 clipRect.
move(0, d, 0);
159 final float d = h - h*less;
167 final float d = h*more - h;
168 clipRect.
move(0, -d, 0);
170 final float d = h*more - h;
177 new InterruptSource.Thread( () -> { window.
destroy(); } ).start();
192 private final int renderModes;
194 private final boolean debug;
195 private final boolean trace;
199 private KeyAction keyAction;
203 private final float[] position =
new float[] {0,0,0};
205 private static final float xTran = 0f;
206 private static final float yTran = 0f;
207 private static final float zTran = -1/5f;
208 private static final float zNear = 0.1f;
209 private static final float zFar = 7000.0f;
211 boolean ignoreInput =
false;
217 this.renderModes = renderModes;
225 this.shape =
new Rectangle(renderModes, szw*0.9f, szh*0.9f, 0);
234 autoDrawable = drawable;
250 if( drawable instanceof
Window ) {
254 public void mouseWheelMoved(
final MouseEvent e) {
257 final float tmp = rot.x(); rot.
setX( rot.y() ); rot.
setY( tmp );
265 public void reshape(
final GLAutoDrawable drawable,
final int xstart,
final int ystart,
final int width,
final int height) {
276 if( drawable instanceof
Window ) {
277 ((
Window)drawable).setTitle(
UIShapeClippingDemo00.class.getSimpleName()+
": "+drawable.getSurfaceWidth()+
" x "+drawable.getSurfaceHeight());
289 renderer.
enable(gl,
true);
298 if(
null != shape && shape.
isVisible() ) {
301 shape.
draw(gl, renderer);
306 clipRect.
draw(gl, renderer);
310 renderer.
enable(gl,
false);
316 if(
null != shape ) {
320 if(
null != clipRect ) {
330 if (
null == keyAction ) {
337 if (
null == keyAction ) {
345 final String sw = String.format(
"-%03dx%03d-Z%04d-T%04d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (
int)Math.abs(zTran), 0, objName);
347 final String filename = dir + tech + sw +
".png";
348 if(screenshot.
readPixels(drawable.getGL(),
false)) {
349 screenshot.
write(
new File(filename));
353 int screenshot_num = 0;
370 if(
null != autoDrawable) {
376 printScreen(drawable,
"./",
"demo-"+type,
"snap"+screenshot_num,
false);
380 }
catch (
final IOException e) {
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.
final void enable(final GL2ES2 gl, final boolean enable)
Enabling or disabling the RenderState's current shader program.
final PMVMatrix4f getMatrix()
Borrow the current PMVMatrix4f.
final void setClipFrustum(final Frustum clipFrustum)
Set the optional clipping Frustum, which shall be pre-multiplied with the Mv-matrix or null to disabl...
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....
static final GLCallback defaultBlendEnable
Default GL#GL_BLEND enable GLCallback, turning-off depth writing via GL#glDepthMask(boolean) if Rende...
final void init(final GL2ES2 gl)
Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext if no...
static RegionRenderer create()
Create a hardware accelerated RegionRenderer including its RenderState composition.
final void reshapePerspective(final float angle_rad, final int width, final int height, final float near, final float far)
Perspective projection, method also calls reshapeNotify(int, int, int, int).
final void destroy(final GL2ES2 gl)
Deletes all ShaderPrograms and nullifies its references including RenderState#destroy(GL2ES2).
static final float DEFAULT_Z16_EPSILON
Default Z precision on 16-bit depth buffer using DEFAULT_SCENE_DIST z-position and DEFAULT_ZNEAR.
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
Shape setColor(final float r, final float g, final float b, final float a)
Set base color.
final Shape move(final float dtx, final float dty, final float dtz)
Move about scaled distance.
void draw(final GL2ES2 gl, final RegionRenderer renderer)
Renders the shape.
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
final boolean isVisible()
Returns true if this shape is set visible by the user, otherwise false.
final Quaternion getRotation()
Returns Quaternion for rotation.
final Shape setRotation(final Quaternion q)
Sets the rotation Quaternion.
final void destroy(final GL2ES2 gl, final RegionRenderer renderer)
Destroys all data.
final void applyMatToMv(final PMVMatrix4f pmv)
Applies the internal Matrix4f to the given modelview matrix, i.e.
A GraphUI rectangle GraphShape.
final float getLineWidth()
void setDimension(final float width, final float height, final float lineWidth)
void setPosition(final float minX, final float minY, final float zPos)
Basic Float math utility functions.
static final float QUARTER_PI
The value PI/4, i.e.
static final float PI
The value PI, i.e.
final Quaternion rotateByEuler(final Vec3f angradXYZ)
Rotates this quaternion from the given Euler rotation array angradXYZ in radians.
3D Vector based upon three float components.
Vec3f scale(final float s)
this = this * s, returns this.
Simple 8-point Vec3f cube compound having z-far <= z-near @endiliteral.
Frustum updateFrustumPlanes(final Frustum frustum)
Calculate the frustum planes using this Cube.
Cube transform(final Matrix4f mat)
Affine 3f-vector transformation of all 8-points with given matrix, Matrix4f#mulVec3f(Vec3f).
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
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 loadMvIdentity()
Load the modelview matrix with the values of the given Matrix4f.
final Matrix4f getMv()
Returns the modelview matrix (Mv).
final PMVMatrix4f popMv()
Pop the modelview matrix from its stack.
final PMVMatrix4f pushMv()
Push the modelview matrix to its stack, while preserving its values.
static final short VK_RIGHT
Constant for the cursor- or numerical-pad right arrow key.
static final short VK_F4
Constant for the F4 function key.
static final short VK_ESCAPE
Constant for the ESCAPE function key.
static final short VK_UP
Constant for the cursor- or numerical-pad up arrow key.
static final short VK_LEFT
Constant for the cursor- or numerical-pad left arrow key.
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
static final short VK_DOWN
Constant for the cursor- or numerical pad down arrow key.
static final short VK_S
See VK_A.
static final short VK_Q
See VK_A.
final short getKeyCode()
Returns the virtual key code using a fixed mapping to the US keyboard layout.
Pointer event of type PointerType.
final float[] getRotation()
Returns a 3-component float array filled with the values of the rotational axis in the following orde...
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void setTitle(final String title)
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final void removeKeyListener(final KeyListener l)
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
abstract GL setGL(GL gl)
Sets the GL pipeline object for this GLContext.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Factory for pipelining GL instances.
static final GL create(final String pipelineClazzBaseName, final Class<?> reqInterface, final GL downstream, final Object[] additionalArgs)
Creates a pipelined GL instance using the given downstream downstream and optional arguments addition...
void keyReleased(final KeyEvent arg0)
A key has been released, excluding auto-repeat modifier keys.
void keyPressed(final KeyEvent arg0)
A key has been pressed, excluding auto-repeat modifier keys.
Basic UIShape Clipping demo, using manual invocation via GLEventListener w/o a Scene.
final float[] getPosition()
final AffineTransform tempT1
final AffineTransform tempT2
static void main(final String[] args)
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 setIgnoreInput(final boolean v)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
UIShapeClippingDemo00(final int renderModes, final boolean debug, final boolean trace)
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void attachInputListenerTo(final GLWindow window)
Attach the input listener to the window.
final RegionRenderer getRegionRenderer()
void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha)
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void detachFrom(final GLWindow window)
GLCapabilities getGLCaps()
int graphAASamples
Sample count for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT or Region#MSAA_RENDERING_BIT...
int graphAAQuality
Pass2 AA-quality rendering for Graph Region AA render-modes: VBAA_RENDERING_BIT.
void parse(final String[] args)
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.
final synchronized boolean stop()
Stops this animator.
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
void write(final File dest)
Write the TextureData filled by readPixels(GLAutoDrawable, boolean) to file.
void dispose(final GL gl)
boolean readPixels(final GL gl, final boolean mustFlipVertically)
Read the drawable's pixels to TextureData and Texture, if requested at construction.
Specifying NEWT's Window functionality:
void addMouseListener(MouseListener l)
Appends the given MouseListener to the end of the list.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLEventListener removeGLEventListener(GLEventListener listener)
Removes the given listener from this drawable queue.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GLContext getContext()
Returns the GLContext associated which this GL object.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
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 glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expr...
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...