28package com.jogamp.opengl.demos.graph.ui;
30import java.io.IOException;
32import com.jogamp.common.util.InterruptSource;
33import com.jogamp.graph.curve.Region;
34import com.jogamp.graph.curve.opengl.RegionRenderer;
35import com.jogamp.graph.ui.GraphShape;
36import com.jogamp.graph.ui.Group;
37import com.jogamp.graph.ui.Scene;
38import com.jogamp.graph.ui.Shape;
39import com.jogamp.graph.ui.shapes.Rectangle;
40import com.jogamp.math.FloatUtil;
41import com.jogamp.math.Vec2f;
42import com.jogamp.math.Vec3f;
43import com.jogamp.math.geom.AABBox;
44import com.jogamp.math.geom.Cube;
45import com.jogamp.math.geom.Frustum;
46import com.jogamp.math.util.PMVMatrix4f;
47import com.jogamp.newt.event.KeyAdapter;
48import com.jogamp.newt.event.KeyEvent;
49import com.jogamp.newt.event.MouseEvent;
50import com.jogamp.newt.event.WindowAdapter;
51import com.jogamp.newt.event.WindowEvent;
52import com.jogamp.newt.opengl.GLWindow;
53import com.jogamp.opengl.GL;
54import com.jogamp.opengl.GLAutoDrawable;
55import com.jogamp.opengl.GLCapabilities;
56import com.jogamp.opengl.GLEventListener;
57import com.jogamp.opengl.GLProfile;
58import com.jogamp.opengl.demos.util.CommandlineOptions;
59import com.jogamp.opengl.util.Animator;
67 public static void main(
final String[] args)
throws IOException {
68 boolean _useFixedSize =
true;
69 if( 0 != args.length ) {
70 final int[] idx = { 0 };
71 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
72 if( options.
parse(args, idx) ) {
74 }
else if(args[idx[0]].equals(
"-NoFixedSize")) {
75 _useFixedSize =
false;
79 final boolean useFixedSize = _useFixedSize;
80 System.err.println(options);
81 System.err.println(
"useFixedSize "+useFixedSize);
83 System.err.println(
"GLProfile: "+reqGLP);
94 System.out.println(
"Requested: " + reqCaps);
104 Group contentBox =
null;
109 System.err.println(
"Init Scene "+sbox);
113 contentBox =
new Group();
119 final float w = sbox.
getWidth()*0.6f;
124 contentBox.
move(-w/2f, -h/2f, 0);
126 System.err.println(
"XXX shape "+shape.
getBounds());
131 public void mouseWheelMoved(final MouseEvent e) {
132 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
133 final Vec3f rot = new Vec3f(e.getRotation()).scale( FloatUtil.PI / 180.0f );
135 final float tmp = rot.x(); rot.setX( rot.y() ); rot.setY( tmp );
136 shapeEvent.shape.setRotation( shapeEvent.shape.getRotation().rotateByEuler( rot.scale( 2f ) ) );
150 contentBox.applyMatToMv(pmv);
152 final AABBox box = contentBox.getBounds();
153 final Cube cube = tempC00.
set(box);
157 shape.applyMatToMv(pmv);
159 final AABBox shapeBox = shape.getBounds();
162 final boolean isOutMv = frustumCbMv.
isOutside( shapedMv );
165 final boolean isOutPMv = frustumPMv.
isOutside( shapeBox );
167 System.err.println(
"ClipBox "+box);
168 System.err.println(
"ShapeBox "+shapeBox);
169 System.err.println(
"FrusPMv "+isOutPMv+
", "+frustumPMv);
170 System.err.println(
"FsCbMv 1 "+isOutMv+
", "+frustumCbMv);
177 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) { }
178 private final Cube tempC00 =
new Cube();
179 private final Cube tempC01 =
new Cube();
180 private final Cube tempC10 =
new Cube();
186 window.setTitle(
UIShapeClippingDemo01.class.getSimpleName()+
": "+window.getSurfaceWidth()+
" x "+window.getSurfaceHeight());
189 public void windowDestroyNotify(
final WindowEvent e) {
194 scene.attachInputListenerTo(window);
195 window.addKeyListener(
new KeyAdapter() {
197 public void keyPressed(
final KeyEvent arg0) {
198 final short keySym = arg0.getKeySymbol();
199 if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) {
200 new InterruptSource.Thread( () -> { window.destroy(); } ).start();
204 window.addWindowListener(
new WindowAdapter() {
206 public void windowDestroyed(
final WindowEvent e) {
211 animator.add(window);
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
final PMVMatrix4f getMatrix()
Borrow the current PMVMatrix4f.
Graph based GLRegion Shape.
Group of Shapes, optionally utilizing a Group.Layout.
void addShape(final Shape s)
Adds a Shape.
Group setClipOnBounds(final boolean v)
Enable Modelview (Mv) Frustum clipping on getBounds() for this group and its shapes as follows.
AABBox getBounds(final PMVMatrix4f pmv, final Shape shape)
Returns AABBox dimension of given Shape from this container's perspective, i.e.
Group setFixedSize(final Vec3f v)
Enforce size of this group for all given 3 dimensions getBounds() without adjusting 3D z-axis like se...
Default implementation of Scene.PMVMatrixSetup, implementing Scene.PMVMatrixSetup#set(PMVMatrix4f,...
void addShape(final Shape s)
Adds a Shape.
final void setClearParams(final float[] clearColor, final int clearMask)
Sets the clear parameter for glClearColor(..) and glClear(..) to be issued at display(GLAutoDrawable)...
RegionRenderer getRenderer()
Returns the associated RegionRenderer.
int setAAQuality(final int v)
Sets RegionRenderer#setAAQuality(int).
final void setPMVMatrixSetup(final PMVMatrixSetup setup)
Set a custom PMVMatrixSetup.
AABBox getBounds(final PMVMatrix4f pmv, final Shape shape)
Returns AABBox dimension of given Shape from this container's perspective, i.e.
Convenient adapter combining dummy implementation for MouseListener and GestureListener.
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
final Shape move(final float dtx, final float dty, final float dtz)
Move about scaled distance.
final Shape setInteractive(final boolean v)
Set whether this shape is interactive in general, i.e.
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
final Shape addMouseListener(final MouseGestureListener l)
final Shape setBorder(final float thickness)
Sets the thickness of the border, which is included in getBounds() and is outside of getPadding().
A GraphUI rectangle GraphShape.
2D Vector based upon two float components.
Axis Aligned Bounding Box.
Simple 8-point Vec3f cube compound having z-far <= z-near @endiliteral.
Cube transform(final Matrix4f mat)
Affine 3f-vector transformation of all 8-points with given matrix, Matrix4f#mulVec3f(Vec3f).
Cube set(final AABBox box)
Setting this cube to given AABBox minimum and maximum.
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
Frustum set(final Frustum o)
Frustum setFromMat(final Matrix4f pmv)
Calculate the frustum planes in world coordinates using the passed column major order matrix,...
Frustum updateFrustumPlanes(final Cube c)
Calculate the frustum planes using the given Cube.
final boolean isOutside(final AABBox box)
Returns whether the given AABBox is completely outside of this frustum.
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
final Matrix4f getMv()
Returns the modelview matrix (Mv).
final Matrix4f getPMv()
Returns the pre-multiplied projection x modelview, P x 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.
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 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.
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.
Specifies the the OpenGL profile.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
Basic UIShape Clipping demo using a Scene and Shape within a clipping Group.
static void main(final String[] args)
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)
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
GLProfile getGLProfile()
Fetches the GLProfile for this drawable.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
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...