28package com.jogamp.opengl.test.junit.graph;
31import java.io.IOException;
33import com.jogamp.opengl.FPSCounter;
34import com.jogamp.opengl.GL;
35import com.jogamp.opengl.GL2ES2;
36import com.jogamp.opengl.GLAnimatorControl;
37import com.jogamp.opengl.GLAutoDrawable;
38import com.jogamp.opengl.GLEventListener;
39import com.jogamp.opengl.GLException;
40import com.jogamp.opengl.GLPipelineFactory;
41import com.jogamp.opengl.GLRunnable;
43import com.jogamp.graph.curve.Region;
44import com.jogamp.graph.curve.opengl.GLRegion;
45import com.jogamp.graph.curve.opengl.RegionRenderer;
46import com.jogamp.graph.curve.opengl.RenderState;
47import com.jogamp.graph.font.FontScale;
48import com.jogamp.math.FloatUtil;
49import com.jogamp.math.Recti;
50import com.jogamp.math.Vec3f;
51import com.jogamp.math.geom.AABBox;
52import com.jogamp.math.util.PMVMatrix4f;
53import com.jogamp.newt.Window;
54import com.jogamp.newt.event.KeyEvent;
55import com.jogamp.newt.event.KeyListener;
56import com.jogamp.newt.opengl.GLWindow;
57import com.jogamp.opengl.util.GLReadBufferUtil;
71 private final int renderModes;
72 private final boolean debug;
73 private final boolean trace;
83 private final float[] position =
new float[] {0,0,0};
89 private float xTran = -10;
90 private float yTran = 10;
91 private float ang = 0f;
92 private float zTran = -70f;
94 protected volatile float weight = 1.0f;
95 boolean ignoreInput =
false;
98 this.renderer = renderer;
99 this.renderModes = renderModes;
115 public void setMatrix(
final float xtrans,
final float ytrans,
final float zTran,
final float angle) {
125 if( upObj instanceof
Window ) {
129 System.err.println(
"DPI "+sDPI[0]+
" x "+sDPI[1]+
", "+sPpMM[0]+
" x "+sPpMM[1]+
" pixel/mm");
132 System.err.println(
"HiDPI PixelScale: "+hasSurfacePixelScale1[0]+
"x"+hasSurfacePixelScale1[1]+
" (has)");
134 autoDrawable = drawable;
151 final float orthoX,
final float orthoY,
final float orthoDist,
152 final float[] winZ,
final Vec3f objPos) {
154 pmv.
mapWinToObj(orthoX, orthoY, winZ[0], view, objPos);
158 public void reshape(
final GLAutoDrawable drawable,
final int xstart,
final int ystart,
final int width,
final int height) {
162 System.err.printf(
"Reshape: zNear %f, zFar %f%n",
zNear,
zFar);
163 System.err.printf(
"Reshape: Frustum: %s%n", pmv.
getFrustum());
165 final float orthoDist = 1f;
168 final float[] winZ =
new float[1];
169 final Recti view =
new Recti(0, 0, width, height);
172 System.err.printf(
"Reshape: mapped.00: [%f, %f, %f], winZ %f -> [%s]%n", 0f, 0f, orthoDist, winZ[0], obj00Coord);
175 System.err.printf(
"Reshape: mapped.11: [%f, %f, %f], winZ %f -> [%s]%n", (
float)width, (
float)height, orthoDist, winZ[0], obj11Coord);
201 public void move(
final float x,
final float y){
216 System.err.println(
"Global Weight: "+
weight);
220 System.err.println(
"Matrix: " + xTran +
" / " + yTran +
" / "+zTran +
" @ "+ang);
225 if (
null == keyAction ) {
232 if (
null == keyAction ) {
239 final String sw = String.format(
"_q%01d_s%02d-%s-Z%04d-snap%02d-%03dx%03d",
241 screenshot_num++, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
242 final String filename = dir + tech + sw +
".png";
243 if(screenshot.
readPixels(drawable.getGL(),
false)) {
244 screenshot.
write(
new File(filename));
247 private int screenshot_num = 0;
254 printScreen(drawable, dir, tech, objName, exportAlpha);
257 }
catch (
final IOException e) {
299 System.err.println(
"Sample Count: " +
getRenderer().getSampleCount());
303 System.err.println(
"Sample Count: " +
getRenderer().getSampleCount());
318 if(
null != autoDrawable) {
322 final GL gl = drawable.
getGL();
326 case 0: i = -1;
break;
327 case -1: i = 1;
break;
328 case 1: i = 0;
break;
329 default: i = 1;
break;
340 System.err.println(
"Swap Interval: "+_i+
" -> "+i+
" -> "+gl.
getSwapInterval());
347 if(
null != autoDrawable) {
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
static boolean hasVariableWeight(final int renderModes)
Returns true if render mode capable of variable weights, i.e.
static String getRenderModeString(final int renderModes)
Returns a unique technical description string for renderModes as follows:
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
final void destroy(final GL2ES2 gl)
Delete and clear the associated OGL objects.
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...
final void init(final GL2ES2 gl)
Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext if no...
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).
The RenderState is owned by RegionRenderer.
static boolean isWeightValid(final float v)
Simple static font scale methods for unit conversions.
static float[] ppmmToPPI(final float[] ppmm)
Converts [1/mm] to [1/inch] in place.
Basic Float math utility functions.
static final float QUARTER_PI
The value PI/4, i.e.
static float adegToRad(final float arc_degree)
Converts arc-degree to radians.
Rectangle with x, y, width and height integer components.
3D Vector based upon three float components.
Axis Aligned Bounding Box.
final AABBox setSize(final float[] low, final float[] high)
Set size of the AABBox specifying the coordinates of the low and high.
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
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 boolean mapWinToObj(final float winx, final float winy, final float winz, final Recti viewport, final Vec3f objPos)
Map window coordinates to object coordinates.
static final short VK_RIGHT
Constant for the cursor- or numerical-pad right arrow key.
static final short VK_W
See VK_A.
static final short VK_2
See VK_0.
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.
static final short VK_DOWN
Constant for the cursor- or numerical pad down arrow key.
static final short VK_9
See VK_0.
static final short VK_0
VK_0 thru VK_9 are the same as UTF16/ASCII '0' thru '9' [0x30 - 0x39].
static final short VK_S
See VK_A.
static final short VK_Q
See VK_A.
static final short VK_V
See VK_A.
static final short VK_1
See VK_0.
final short getKeyCode()
Returns the virtual key code using a fixed mapping to the US keyboard layout.
static final short VK_7
See VK_0.
static final short VK_6
See VK_0.
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)
abstract boolean isGLDebugMessageEnabled()
abstract GL setGL(GL gl)
Sets the GL pipeline object for this GLContext.
final String getGLVersion()
Returns a valid OpenGL version string, ie
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 keyPressed(final KeyEvent arg0)
A key has been pressed, excluding auto-repeat modifier keys.
void keyReleased(final KeyEvent arg0)
A key has been released, excluding auto-repeat modifier keys.
GPURendererListenerBase01(final RegionRenderer renderer, final int renderModes, final boolean debug, final boolean trace)
void printScreenOnGLThread(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha)
final float getAngleRad()
void setMatrix(final float xtrans, final float ytrans, final float zTran, final float angle)
void editGlobalWeight(final float delta)
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
final AABBox nearPlane1Box
Describing the bounding box in model-coordinates of the near-plane parallel at distance one.
static void mapWin2ObjectCoords(final PMVMatrix4f pmv, final Recti view, final float zNear, final float zFar, final float orthoX, final float orthoY, final float orthoDist, final float[] winZ, final Vec3f objPos)
void rotate(final float delta)
final float[] getPosition()
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 init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha)
void setIgnoreInput(final boolean v)
void attachInputListenerTo(final GLWindow window)
Attach the input listener to the window.
void detachInputListenerFrom(final GLWindow window)
final float getAngleDeg()
void move(final float x, final float y)
final int getRenderModes()
final RegionRenderer getRenderer()
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.
float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
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 resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
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) ...
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...
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.
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.
int getSwapInterval()
Return the current swap interval.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...