/** Setup the avaiatrix pipeline here */ private void setupAviatrix() { // Assemble a simple single-threaded pipeline. GLCapabilities caps = new GLCapabilities(); caps.setDoubleBuffered(true); caps.setHardwareAccelerated(true); GraphicsCullStage culler = new NullCullStage(); culler.setOffscreenCheckEnabled(false); GraphicsSortStage sorter = new SimpleTransparencySortStage(); surface = new DebugAWTSurface(caps); DefaultGraphicsPipeline pipeline = new DefaultGraphicsPipeline(); pipeline.setCuller(culler); pipeline.setSorter(sorter); pipeline.setGraphicsOutputDevice(surface); displayManager = new SingleDisplayCollection(); displayManager.addPipeline(pipeline); // Render manager sceneManager = new SingleThreadRenderManager(); sceneManager.addDisplay(displayManager); sceneManager.setMinimumFrameInterval(100); // Before putting the pipeline into run mode, put the canvas on // screen first. Component comp = (Component) surface.getSurfaceObject(); add(comp, BorderLayout.CENTER); }
public DrawByLevelFractal() { baseDir = "CS371/assignments/assignment02/ifs/"; ifsFiles = new ArrayList<String>(); ifsFiles.add("carpet.ifs"); ifsFiles.add("chaos.ifs"); ifsFiles.add("coral.ifs"); ifsFiles.add("curl.ifs"); ifsFiles.add("four.ifs"); ifsFiles.add("galaxy.ifs"); ifsFiles.add("dragon.ifs"); ifsFiles.add("leady.ifs"); ifsFiles.add("koch.ifs"); ifsFiles.add("mouse.ifs"); ifsFiles.add("leaf.ifs"); ifsFiles.add("seven.ifs"); ifsFiles.add("three.ifs"); ifsFiles.add("tri.ifs"); pointsToDraw = 80000; left = -7; right = 7; bottom = -7; top = 11; xOrigin = 0; yOrigin = 0; rotate_scale_xx = new double[maximumTransitions]; rotate_scale_xy = new double[maximumTransitions]; rotate_scale_yx = new double[maximumTransitions]; rotate_scale_yy = new double[maximumTransitions]; trans_x = new double[maximumTransitions]; trans_y = new double[maximumTransitions]; prob = new double[maximumTransitions]; caps = new GLCapabilities(GLProfile.getGL2GL3()); caps.setDoubleBuffered(true); // request double buffer display mode caps.setHardwareAccelerated(true); canvas = new GLJPanel(); // canvas.setOpaque(true); canvas.addGLEventListener(this); canvas.addKeyListener(this); animator = new FPSAnimator(canvas, 60); getContentPane().add(canvas); }
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(); }
/** * Constructor for this class. Sets up the window and enables common features like anti-aliasing * and hardware acceleration. * * @param forceGL2ES2 Force GL2ES2 support (default on), currently Unused * @param inputHandler A predefined InputHandler that is added as event handler for input events. * @param glEventListener A predefined GLEventListener that is added as event handler for openGL * events. * @param width The initial window width. * @param height The initial window height. * @param windowTitle The window title. */ public ESightNewtWindow( boolean forceGL2ES2, InputHandler inputHandler, final GLEventListener glEventListener, int width, int height, String windowTitle) { final GLProfile glp; // if (forceGL2ES2) { // glp = GLProfile.get(GLProfile.GL2ES2); // } else { glp = GLProfile.get(GLProfile.GL3); // } // Set up the GL context final GLCapabilities caps = new GLCapabilities(glp); caps.setBackgroundOpaque(true); caps.setHardwareAccelerated(true); caps.setDoubleBuffered(true); // Add Anti-Aliasing caps.setSampleBuffers(true); caps.setAlphaBits(4); caps.setNumSamples(4); // Create the Newt Window Display dpy = NewtFactory.createDisplay(null); Screen screen = NewtFactory.createScreen(dpy, screenIdx); final GLWindow glWindow = GLWindow.create(screen, caps); glWindow.setTitle(windowTitle); // Add listeners glWindow.addMouseListener(inputHandler); glWindow.addKeyListener(inputHandler); // glWindow.setFullscreen(true); WindowListener[] listeners = glWindow.getWindowListeners(); final WindowListener original = listeners[0]; glWindow.addWindowListener( 0, new WindowAdapter() { @Override public void windowDestroyNotify(WindowEvent arg0) { glWindow.getAnimator().stop(); System.exit(0); } @Override public void windowDestroyed(WindowEvent arg0) { glWindow.getAnimator().stop(); System.exit(0); } @Override public void windowGainedFocus(WindowEvent arg0) { original.windowGainedFocus(arg0); } @Override public void windowLostFocus(WindowEvent arg0) { original.windowLostFocus(arg0); } @Override public void windowMoved(WindowEvent arg0) { original.windowMoved(arg0); } @Override public void windowRepaint(WindowUpdateEvent arg0) { original.windowRepaint(arg0); } @Override public void windowResized(WindowEvent arg0) { original.windowResized(arg0); } }); glWindow.addGLEventListener(glEventListener); // Create the Animator final Animator animator = new Animator(); animator.add(glWindow); animator.start(); glWindow.setSize(width, height); glWindow.setVisible(true); }