private void initPanels(GLCapabilities caps) { // create panels to draw on myPanels = new GLJPanel[3]; myPanels[0] = new GLJPanel(caps); myPanels[1] = new GLJPanel(caps); myPanels[2] = new GLJPanel(caps); setLayout(new GridLayout(1, 3)); add(myPanels[0]); add(myPanels[1]); add(myPanels[2]); // The cross section view CrossSectionView view0 = new CrossSectionView(this); myPanels[0].addGLEventListener(view0); // the spine view SpineView view1 = new SpineView(this); myPanels[1].addGLEventListener(view1); myPanels[1].addMouseMotionListener(view1); // the extrusion view ExtrusionView view2 = new ExtrusionView(this); myPanels[2].addGLEventListener(view2); myPanels[2].addMouseMotionListener(view2); FPSAnimator animator = new FPSAnimator(60); animator.add(myPanels[0]); animator.add(myPanels[1]); animator.add(myPanels[2]); animator.start(); }
/** The entry main() method */ public static void main(String[] args) { // Create the OpenGL rendering canvas GLCanvas canvas = new GLCanvas(); // heavy-weight GLCanvas canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT)); canvas.addGLEventListener(new JOGL2Nehe11Flag()); // Create a animator that drives canvas' display() at the specified FPS. final FPSAnimator animator = new FPSAnimator(canvas, FPS, true); // Create the top-level container frame final JFrame frame = new JFrame(); // Swing's JFrame or AWT's Frame frame.getContentPane().add(canvas); frame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // Use a dedicate thread to run the stop() to ensure that the // animator stops before program exits. new Thread() { @Override public void run() { animator.stop(); // stop the animator loop System.exit(0); } }.start(); } }); frame.setTitle(TITLE); frame.pack(); frame.setVisible(true); animator.start(); // start the animation loop }
public void setFrameRate(float fps) { if (animator != null) { animator.stop(); animator.setFPS((int) fps); pgl.setFps(fps); animator.start(); } }
public static FPSAnimator startFpsAnimator(int fps, GlimpseCanvas... canvases) { FPSAnimator animator = new FPSAnimator(fps); for (GlimpseCanvas canvas : canvases) { animator.add(canvas.getGLDrawable()); } animator.start(); return animator; }
public boolean isStopped() { if (animator != null) { return !animator.isAnimating(); } else { return true; } }
private void initUI() { setTitle("pfps"); setSize(800, 600); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); glcanvas_ = new GLCanvas(glcap_); glcanvas_.addGLEventListener(this); this.getContentPane().add(glcanvas_, BorderLayout.CENTER); animator_ = new FPSAnimator(glcanvas_, 60); animator_.start(); glcanvas_.addKeyListener(input_); glcanvas_.addMouseMotionListener(input_); moveTimer_ = new Timer( MOVE_TIMER_FREQ, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onMoveTimer(); } }); moveTimer_.start(); this.addWindowListener( new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { MyFrame.this.windowOpened(e); } }); }
public Janela(int width, int height, GLCanvas canvas) throws IOException { animator = new FPSAnimator(canvas, 240); setSize(new Dimension(width, height)); setLocationRelativeTo(null); setMinimumSize(getSize()); setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(canvas, BorderLayout.CENTER); getContentPane().add(panel); canvas.addGLEventListener(new GLWindow(panel, canvas)); addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { super.windowClosing( e); // To change body of generated methods, choose Tools | Templates. animator.stop(); System.out.println("Animação parou!"); } }); setExtendedState(JFrame.MAXIMIZED_BOTH); setVisible(true); JDInfo info = new JDInfo(this, true); info.setVisible(true); animator.start(); clip = Applet.newAudioClip(new File("./resources/Cabin.wav").toURL()); clip.loop(); }
/** KeyListener method. */ @Override public void keyPressed(KeyEvent ke) { animator.start(); int DELTA_SIZE = 1; switch (ke.getKeyCode()) { case KeyEvent.VK_UP: gcodeRenderer.pan(0, DELTA_SIZE); // this.eye.y+=DELTA_SIZE; break; case KeyEvent.VK_DOWN: gcodeRenderer.pan(0, -DELTA_SIZE); break; case KeyEvent.VK_LEFT: gcodeRenderer.pan(-DELTA_SIZE, 0); break; case KeyEvent.VK_RIGHT: gcodeRenderer.pan(DELTA_SIZE, 0); break; case KeyEvent.VK_MINUS: if (ke.isControlDown()) gcodeRenderer.zoom(-1); break; case KeyEvent.VK_0: case KeyEvent.VK_ESCAPE: gcodeRenderer.resetView(); break; } switch (ke.getKeyChar()) { case '+': if (ke.isControlDown()) gcodeRenderer.zoom(1); break; } }
private void run() { setSize(800, 800); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); animator.start(); }
public boolean stopThread() { if (animator != null) { return animator.stop(); } else { return false; } }
/** UGS Event Listener */ @Override public void UGSEvent(UGSEvent cse) { if (cse.isFileChangeEvent()) { animator.pause(); switch (cse.getFileState()) { case FILE_LOADING: setGcodeFile(cse.getFile()); break; case FILE_LOADED: setProcessedGcodeFile(cse.getFile()); break; } animator.resume(); } }
@Override public void mousePressed(MouseEvent e) { switch (e.getButton()) { case MouseEvent.BUTTON1: animator.resume(); System.out.println("button 1, left click"); break; case MouseEvent.BUTTON2: System.out.println("button 2"); break; case MouseEvent.BUTTON3: System.out.println("button 3, right click"); willAnimatorPause = true; animator.resume(); break; } }
@Override public void init(GLAutoDrawable drawable) { super.init(drawable); GL3 gl = drawable.getGL().getGL3(); gl.glClearColor(1, 1, 1, 1); // Hintergrundfarbe (RGBA) fpsAnimator = new FPSAnimator(drawable, 60, true); fpsAnimator.start(); }
public FirstStepNewtLast() { GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2)); GLWindow glWindow = GLWindow.create(caps); glWindow.setTitle("First demo (Newt)"); glWindow.setSize(300, 300); glWindow.addWindowListener( new WindowAdapter() { @Override public void windowDestroyed(WindowEvent arg0) { System.exit(0); } }); glWindow.addGLEventListener(this); FPSAnimator animator = new FPSAnimator(10); // (2) animator.add(glWindow); animator.start(); glWindow.setVisible(true); }
public static void main(String[] args) { GLProfile glp = GLProfile.getDefault(); GLCapabilities caps = new GLCapabilities(glp); GLCanvas canvas = new GLCanvas(caps); cube unCube = new cube(); canvas.addGLEventListener(unCube); Frame frame = new Frame("AWT Window Test"); FPSAnimator anim = new FPSAnimator(canvas, 60); anim.start(); frame.setSize(400, 400); frame.add(canvas); frame.setVisible(true); frame.addKeyListener( new KeyListener() { @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub int keyCode = e.getKeyCode(); unCube.handleKeyPress(keyCode); // Here is the handleKeyPress function's call frame.add(canvas); } @Override public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } }); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // GL_DEPTH_BUFFER_BITを追加 gl.glLoadIdentity(); // 視点位置と視線方向 glu.gluLookAt(3.0f, 4.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); // 光源の位置設定 // gl.glLightfv(GL_LIGHT0, GL_POSITION, light0pos, 0); // gl.glLightfv(GL_LIGHT1, GL_POSITION, light1pos, 0); // 図形の回転 gl.glTranslatef(0.5f, 0.5f, 0.5f); gl.glRotatef(r, 0.0f, 1.0f, 0.0f); gl.glTranslatef(-0.5f, -0.5f, -0.5f); // 図形の色 (赤) // gl.glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red, 0);//追加 // gl.glColor3f(0.0f, 0.0f, 0.0f); // 図形の描画 gl.glBegin(GL_QUADS); for (int j = 0; j < 6; ++j) { // gl.glColor3fv(color[j], 0); //追加 // gl.glNormal3fv(normal[j], 0); for (int i = 0; i < 4; ++i) { gl.glNormal3fv(vertex[face[j][i]], 0); gl.glVertex3fv(vertex[face[j][i]], 0); } } gl.glEnd(); // 一周回ったら回転角を 0 に戻す if (r++ >= 360.0f) r = 0; System.out.println("anim:" + animator.isAnimating() + ", r:" + r); if (willAnimatorPause) { animator.pause(); System.out.println("animoator paused:"); willAnimatorPause = false; } }
/** * Mouse pressed is called on mouse-down. Mouse released and mouse clicked are called on mouse-up. */ @Override public void mousePressed(MouseEvent e) { // Zoom if (e.getButton() == MouseEvent.BUTTON1 && e.isMetaDown()) { selecting = true; selectionStart = gcodeRenderer.getMouseWorldLocation(); selection.setStart(selectionStart); } else { animator.start(); } }
@Override public void mouseReleased(MouseEvent e) { // Finish selecting. if (selecting) { selecting = false; selectionEnd = gcodeRenderer.getMouseWorldLocation(); gcodeRenderer.zoomToRegion(selectionStart, selectionEnd, 1.0); selection.clear(); gcodeRenderer.forceRedraw(); } animator.stop(); }
public CubeSample6InvalidNormal() { GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2)); glu = new GLU(); GLWindow glWindow = GLWindow.create(caps); glWindow.setTitle("Cube demo (Newt)"); glWindow.setSize(300, 300); glWindow.addWindowListener( new WindowAdapter() { @Override public void windowDestroyed(WindowEvent arg0) { System.exit(0); } }); glWindow.addGLEventListener(this); glWindow.addMouseListener(this); animator = new FPSAnimator(30); animator.add(glWindow); animator.start(); animator.pause(); glWindow.setVisible(true); }
private void initPanels(GLCapabilities caps) { // create a panel to draw on myPanels = new GLJPanel[1]; myPanels[0] = new GLJPanel(caps); // create a panel of sliders JPanel panel = initSliders(); setLayout(new GridLayout(1, 2)); add(myPanels[0]); add(panel); TextureView view1 = new TextureView(this); myPanels[0].addGLEventListener(view1); myPanels[0].addMouseMotionListener(view1); myPanels[0].addKeyListener(this); myPanels[0].setFocusable(true); FPSAnimator animator = new FPSAnimator(60); animator.add(myPanels[0]); animator.start(); }
public Engine(GLCanvas canvas) { frame = new Frame("TRIPPIN' BALLS"); frame.add(canvas); frame.setSize(600, 600); if (fullscreen) frame.setUndecorated(true); frame.setVisible(true); if (fullscreen) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.getDefaultScreenDevice().setFullScreenWindow(frame); } input = new Input(); frame.addWindowListener(input); canvas.addKeyListener(input); canvas.addMouseListener(input); canvas.addMouseWheelListener(input); canvas.addFocusListener(input); animator = new FPSAnimator(canvas, 60); animator.add(canvas); animator.start(); animator.getTotalFrames(); }
public void run() { // Create a animator that drives canvas' display() at the specified FPS. final FPSAnimator animator = new FPSAnimator(canvas, fPS, true); // Create the top-level container frame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // Use a dedicate thread to run the stop() to ensure that the // animator stops before program exits. new Thread() { @Override public void run() { if (animator.isStarted()) animator.stop(); System.exit(0); } }.start(); } }); frame.setVisible(true); animator.start(); }
protected void initAnimator() { // System.err.println("1. create animator"); animator = new FPSAnimator(window, 60); drawException = null; animator.setUncaughtExceptionHandler( new GLAnimatorControl.UncaughtExceptionHandler() { @Override public void uncaughtException( final GLAnimatorControl animator, final GLAutoDrawable drawable, final Throwable cause) { synchronized (waitObject) { // System.err.println("Caught exception: " + cause.getMessage()); drawException = cause; waitObject.notify(); } } }); new Thread( new Runnable() { public void run() { synchronized (waitObject) { try { if (drawException == null) waitObject.wait(); } catch (InterruptedException e) { e.printStackTrace(); } // System.err.println("Caught exception: " + drawException.getMessage()); if (drawException != null) { Throwable cause = drawException.getCause(); if (cause instanceof ThreadDeath) { // System.out.println("caught ThreadDeath"); // throw (ThreadDeath)cause; } else if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else { throw new RuntimeException(cause); } } } } }) .start(); }
public void startThread() { if (animator != null) { if (placedWindow) { window.setVisible(true); animator.start(); requestedStart = false; } else { // The GL window is not visible until it has been placed, so we cannot // start the animator because it requires the window to be visible. requestedStart = true; // Need this assignment to bypass the while loop in runSketch, otherwise // the programs hangs waiting for defaultSize to be false, but it never // happens because the animation thread is not yet running to avoid showing // the window in the wrong place: // https://github.com/processing/processing/issues/3308 // sketch.defaultSize = false; } } }
/** KeyListener method. */ @Override public void keyReleased(KeyEvent ke) { animator.stop(); }
public static void main(String _args[]) { final NBodyKernel kernel = new NBodyKernel(Range.create(Integer.getInteger("bodies", 8192), 256)); final JFrame frame = new JFrame("NBody"); final JPanel panel = new JPanel(new BorderLayout()); final JPanel controlPanel = new JPanel(new FlowLayout()); panel.add(controlPanel, BorderLayout.SOUTH); final JButton startButton = new JButton("Start"); startButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { running = true; startButton.setEnabled(false); } }); controlPanel.add(startButton); controlPanel.add(new JLabel(kernel.getExecutionMode().toString())); controlPanel.add(new JLabel(" Particles")); controlPanel.add(new JTextField("" + kernel.range.getGlobalSize(0), 5)); controlPanel.add(new JLabel("FPS")); final JTextField framesPerSecondTextField = new JTextField("0", 5); controlPanel.add(framesPerSecondTextField); controlPanel.add(new JLabel("Score(")); final JLabel miniLabel = new JLabel("<html><small>calcs</small><hr/><small>µsec</small></html>"); controlPanel.add(miniLabel); controlPanel.add(new JLabel(")")); final JTextField positionUpdatesPerMicroSecondTextField = new JTextField("0", 5); controlPanel.add(positionUpdatesPerMicroSecondTextField); final GLCapabilities caps = new GLCapabilities(null); caps.setDoubleBuffered(true); caps.setHardwareAccelerated(true); final GLCanvas canvas = new GLCanvas(caps); final Dimension dimension = new Dimension(Integer.getInteger("width", 742), Integer.getInteger("height", 742)); canvas.setPreferredSize(dimension); canvas.addGLEventListener( new GLEventListener() { private double ratio; private final float xeye = 0f; private final float yeye = 0f; private final float zeye = 100f; private final float xat = 0f; private final float yat = 0f; private final float zat = 0f; public final float zoomFactor = 1.0f; private int frames; private long last = System.currentTimeMillis(); @Override public void dispose(GLAutoDrawable drawable) {} @Override public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glLoadIdentity(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glColor3f(1f, 1f, 1f); final GLU glu = new GLU(); glu.gluPerspective(45f, ratio, 0f, 1000f); glu.gluLookAt(xeye, yeye, zeye * zoomFactor, xat, yat, zat, 0f, 1f, 0f); if (running) { kernel.execute(kernel.range); if (kernel.isExplicit()) { kernel.get(kernel.xyz); } final List<ProfileInfo> profileInfo = kernel.getProfileInfo(); if ((profileInfo != null) && (profileInfo.size() > 0)) { for (final ProfileInfo p : profileInfo) { System.out.print( " " + p.getType() + " " + p.getLabel() + ((p.getEnd() - p.getStart()) / 1000) + "us"); } System.out.println(); } } kernel.render(gl); final long now = System.currentTimeMillis(); final long time = now - last; frames++; if (time > 1000) { // We update the frames/sec every second if (running) { final float framesPerSecond = (frames * 1000.0f) / time; final int updatesPerMicroSecond = (int) ((framesPerSecond * kernel.range.getGlobalSize(0) * kernel.range.getGlobalSize(0)) / 1000000); framesPerSecondTextField.setText(String.format("%5.2f", framesPerSecond)); positionUpdatesPerMicroSecondTextField.setText( String.format("%4d", updatesPerMicroSecond)); } frames = 0; last = now; } gl.glFlush(); } @Override public void init(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glShadeModel(GLLightingFunc.GL_SMOOTH); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); try { final InputStream textureStream = Local.class.getResourceAsStream("particle.jpg"); final Texture texture = TextureIO.newTexture(textureStream, false, null); texture.enable(gl); } catch (final IOException e) { e.printStackTrace(); } catch (final GLException e) { e.printStackTrace(); } } @Override public void reshape(GLAutoDrawable drawable, int x, int y, int _width, int _height) { width = _width; height = _height; final GL2 gl = drawable.getGL().getGL2(); gl.glViewport(0, 0, width, height); ratio = (double) width / (double) height; } }); panel.add(canvas, BorderLayout.CENTER); frame.getContentPane().add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); final FPSAnimator animator = new FPSAnimator(canvas, 100); animator.start(); }
public void resumeThread() { if (animator != null) { animator.resume(); } }
protected void runTestGL(final GLCapabilities caps) throws AWTException, InterruptedException, InvocationTargetException { final JFrame frame = new JFrame("Swing GLJPanel"); frame.setLocation(xpos, ypos); Assert.assertNotNull(frame); final FPSAnimator animator = useAnimator ? new FPSAnimator(60) : null; final SnapshotGLEventListener snap = new SnapshotGLEventListener(); final GLJPanel glJPanel = newGLJPanel(frame, caps, animator, snap); if (null != animator) { animator.start(); Assert.assertEquals(true, animator.isAnimating()); } final Screen screen = NewtFactoryAWT.createScreen(glJPanel, true); screen.addReference(); // initial native creation - keep alive! System.err.println("GetPixelScale: AWT -> Screen: " + screen); final QuitAdapter quitAdapter = new QuitAdapter(); new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glJPanel).addTo(glJPanel); new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glJPanel).addTo(frame); final JFrame[] frame2 = {null}; final GLJPanel[] glJPanel2 = {null}; final com.jogamp.newt.event.KeyListener kl = new com.jogamp.newt.event.KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { if (e.isAutoRepeat()) { return; } if (e.getKeySymbol() == KeyEvent.VK_P) { System.err.println(); { // Just for manual validation! final java.awt.Point los = glJPanel.getLocationOnScreen(); final RectangleImmutable r = new Rectangle(los.x, los.y, glJPanel.getWidth(), glJPanel.getHeight()); System.err.printf("GetPixelScale: Panel Bounds: %s window-units%n", r.toString()); System.err.printf( "GetPixelScale: Panel Resolution: %d x %d pixel-units%n", glJPanel.getSurfaceWidth(), glJPanel.getSurfaceHeight()); } final MonitorDevice monitor = NewtFactoryAWT.getMonitorDevice(screen, glJPanel); System.err.printf("GetPixelScale: %s%n", monitor.toString()); final float[] pixelPerMM; final boolean cached; if (e.isShiftDown()) { // SHIFT: query current mode! pixelPerMM = monitor.getPixelsPerMM(monitor.queryCurrentMode(), new float[2]); cached = false; } else { // Default: Use cached mode! pixelPerMM = monitor.getPixelsPerMM(new float[2]); cached = true; } System.err.println( " pixel/mm [" + pixelPerMM[0] + ", " + pixelPerMM[1] + "], cached-mode " + cached); System.err.println( " pixel/in [" + pixelPerMM[0] * 25.4f + ", " + pixelPerMM[1] * 25.4f + "], cached-mode " + cached); System.err.println(); } else if (e.getKeyChar() == 'x') { final float[] hadSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new float[2]); final float[] reqSurfacePixelScale; if (hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE) { reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; } else { reqSurfacePixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; } System.err.println( "[set PixelScale pre]: had " + hadSurfacePixelScale[0] + "x" + hadSurfacePixelScale[1] + " -> req " + reqSurfacePixelScale[0] + "x" + reqSurfacePixelScale[1]); glJPanel.setSurfaceScale(reqSurfacePixelScale); final float[] valReqSurfacePixelScale = glJPanel.getRequestedSurfaceScale(new float[2]); final float[] hasSurfacePixelScale1 = glJPanel.getCurrentSurfaceScale(new float[2]); System.err.println( "[set PixelScale post]: " + hadSurfacePixelScale[0] + "x" + hadSurfacePixelScale[1] + " (had) -> " + reqSurfacePixelScale[0] + "x" + reqSurfacePixelScale[1] + " (req) -> " + valReqSurfacePixelScale[0] + "x" + valReqSurfacePixelScale[1] + " (val) -> " + hasSurfacePixelScale1[0] + "x" + hasSurfacePixelScale1[1] + " (has)"); setTitle(frame, glJPanel, caps); } else if (e.getKeyChar() == 'm') { final GLCapabilitiesImmutable capsPre = glJPanel.getChosenGLCapabilities(); final GLCapabilities capsNew = new GLCapabilities(capsPre.getGLProfile()); capsNew.copyFrom(capsPre); final boolean msaa; if (capsPre.getSampleBuffers()) { capsNew.setSampleBuffers(false); msaa = false; } else { capsNew.setSampleBuffers(true); capsNew.setNumSamples(4); msaa = true; } System.err.println("[set MSAA " + msaa + " Caps had]: " + capsPre); System.err.println("[set MSAA " + msaa + " Caps new]: " + capsNew); System.err.println("XXX-A1: " + animator.toString()); glJPanel.setRequestedGLCapabilities(capsNew); System.err.println("XXX-A2: " + animator.toString()); System.err.println("XXX: " + glJPanel.toString()); } else if (e.getKeyChar() == 'n') { System.err.println("XXX: frame2: " + frame2[0]); if (null != frame2[0]) { System.err.println("XXX: frame2.isShowing: " + frame2[0].isShowing()); } System.err.println("XXX: glJPanel2: " + glJPanel2[0]); if (null != frame2[0] && frame2[0].isShowing()) { destroy(frame2[0], glJPanel2[0]); frame2[0] = null; glJPanel2[0] = null; } else { frame2[0] = new JFrame("GLJPanel2"); frame2[0].setLocation(frame.getX() + frame.getWidth() + 64, frame.getY()); final FPSAnimator animator2 = useAnimator ? new FPSAnimator(60) : null; if (null != animator2) { animator2.start(); } final SnapshotGLEventListener snap2 = new SnapshotGLEventListener(); try { glJPanel2[0] = newGLJPanel(frame2[0], caps, animator2, snap2); } catch (final Exception e2) { e2.printStackTrace(); destroy(frame2[0], glJPanel2[0]); frame2[0] = null; glJPanel2[0] = null; } } } } }; new AWTKeyAdapter(kl, glJPanel).addTo(glJPanel); snap.setMakeSnapshot(); if (null != rwsize) { Thread.sleep(500); // 500ms delay setFrameSize(frame, true, rwsize); System.err.println( "window resize pos/siz: " + glJPanel.getX() + "/" + glJPanel.getY() + " " + glJPanel.getSurfaceWidth() + "x" + glJPanel.getSurfaceHeight()); } snap.setMakeSnapshot(); final long t0 = System.currentTimeMillis(); long t1 = t0; boolean triggerSnap = false; while (!quitAdapter.shouldQuit() && t1 - t0 < duration) { Thread.sleep(100); t1 = System.currentTimeMillis(); snap.getDisplayCount(); if (!triggerSnap && snap.getDisplayCount() > 1) { // Snapshot only after one frame has been rendered to suite FBO MSAA! snap.setMakeSnapshot(); triggerSnap = true; } } Assert.assertNotNull(frame); Assert.assertNotNull(glJPanel); if (useAnimator) { Assert.assertNotNull(animator); animator.stop(); Assert.assertEquals(false, animator.isAnimating()); } else { Assert.assertNull(animator); } screen.removeReference(); // final native destroy destroy(frame, glJPanel); if (null != frame2[0]) { destroy(frame2[0], glJPanel2[0]); } }
protected GLJPanel newGLJPanel( final JFrame frame, final GLCapabilities caps, final FPSAnimator animator, final SnapshotGLEventListener snap) throws AWTException, InterruptedException, InvocationTargetException { final GLJPanel glJPanel = new GLJPanel(caps); Assert.assertNotNull(glJPanel); glJPanel.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip); glJPanel.setMinimumSize(wsize); glJPanel.setPreferredSize(wsize); glJPanel.setSize(wsize); glJPanel.setSurfaceScale(reqSurfacePixelScale); { final GLEventListener demo = createDemo(caps); if (null != demo) { glJPanel.addGLEventListener(demo); } } if (null != snap) { glJPanel.addGLEventListener(snap); } glJPanel.addGLEventListener( new GLEventListener() { @Override public void init(final GLAutoDrawable drawable) {} @Override public void dispose(final GLAutoDrawable drawable) {} @Override public void display(final GLAutoDrawable drawable) {} @Override public void reshape( final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { setTitle(frame, glJPanel, caps); } }); setTitle(frame, glJPanel, caps); frame.addComponentListener( new ComponentListener() { @Override public void componentResized(final ComponentEvent e) { setTitle(frame, glJPanel, caps); } @Override public void componentMoved(final ComponentEvent e) { setTitle(frame, glJPanel, caps); } @Override public void componentShown(final ComponentEvent e) {} @Override public void componentHidden(final ComponentEvent e) {} }); if (SwingUtilities.isEventDispatchThread()) { frame.getContentPane().add(glJPanel, BorderLayout.CENTER); frame.getContentPane().validate(); frame.pack(); frame.setVisible(true); } else { SwingUtilities.invokeAndWait( new Runnable() { public void run() { frame.getContentPane().add(glJPanel, BorderLayout.CENTER); frame.getContentPane().validate(); frame.pack(); frame.setVisible(true); } }); Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel, true)); final float[] minSurfacePixelScale = glJPanel.getMinimumSurfaceScale(new float[2]); final float[] maxSurfacePixelScale = glJPanel.getMaximumSurfaceScale(new float[2]); final float[] valReqSurfacePixelScale = glJPanel.getRequestedSurfaceScale(new float[2]); final float[] hasSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new float[2]); System.err.println( "HiDPI PixelScale: min " + minSurfacePixelScale[0] + "x" + minSurfacePixelScale[1] + ", max " + maxSurfacePixelScale[0] + "x" + maxSurfacePixelScale[1] + ", req " + reqSurfacePixelScale[0] + "x" + reqSurfacePixelScale[1] + " -> val " + valReqSurfacePixelScale[0] + "x" + valReqSurfacePixelScale[1] + " -> has " + hasSurfacePixelScale[0] + "x" + hasSurfacePixelScale[1]); setTitle(frame, glJPanel, caps); } if (null != animator) { animator.add(glJPanel); animator.setUpdateFPSFrames(60, System.err); } return glJPanel; }
public void pauseThread() { if (animator != null) { animator.pause(); } }