protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationStatic(
      Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) {
    if (absScreen == null) {
      throw new IllegalArgumentException("AbstractGraphicsScreen is null");
    }
    if (!(absScreen instanceof X11GraphicsScreen)) {
      throw new IllegalArgumentException("Only X11GraphicsScreen are allowed here");
    }
    X11GraphicsScreen x11Screen = (X11GraphicsScreen) absScreen;

    if (capabilities != null && !(capabilities instanceof GLCapabilities)) {
      throw new IllegalArgumentException(
          "This NativeWindowFactory accepts only GLCapabilities objects");
    }

    if (chooser != null && !(chooser instanceof GLCapabilitiesChooser)) {
      throw new IllegalArgumentException(
          "This NativeWindowFactory accepts only GLCapabilitiesChooser objects");
    }

    if (capabilities == null) {
      capabilities = new GLCapabilities(null);
    }

    boolean onscreen = capabilities.isOnscreen();
    boolean usePBuffer = ((GLCapabilities) capabilities).isPBuffer();

    GLCapabilities caps2 = (GLCapabilities) capabilities.clone();
    if (!caps2.isOnscreen()) {
      // OFFSCREEN !DOUBLE_BUFFER // FIXME DBLBUFOFFSCRN
      caps2.setDoubleBuffered(false);
    }

    X11GLXGraphicsConfiguration res;
    res =
        chooseGraphicsConfigurationFBConfig(
            (GLCapabilities) caps2, (GLCapabilitiesChooser) chooser, x11Screen);
    if (null == res) {
      if (usePBuffer) {
        throw new GLException(
            "Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig");
      }
      res =
          chooseGraphicsConfigurationXVisual(
              (GLCapabilities) caps2, (GLCapabilitiesChooser) chooser, x11Screen);
    }
    if (null == res) {
      throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration");
    }
    if (DEBUG) {
      System.err.println(
          "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationStatic("
              + x11Screen
              + ","
              + caps2
              + "): "
              + res);
    }
    return res;
  }
예제 #2
0
  /** 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);
  }
예제 #3
0
 protected GLCapabilities createCapabilities() {
   GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
   caps.setStencilBits(1);
   caps.setDoubleBuffered(true);
   caps.setAlphaBits(8);
   return caps;
 }
예제 #4
0
 public static GLCapabilities fixCaps(
     GLCapabilities caps, boolean onscreen, boolean pbuffer, boolean undecorated) {
   GLCapabilities caps2 = (GLCapabilities) caps.clone();
   caps2.setOnscreen(onscreen);
   caps2.setPBuffer(!onscreen && pbuffer);
   caps2.setDoubleBuffered(!onscreen);
   return caps2;
 }
 static {
   caps = new GLCapabilities();
   caps.setDoubleBuffered(true);
   caps.setAlphaBits(8);
   caps.setRedBits(8);
   caps.setGreenBits(8);
   caps.setBlueBits(8);
 }
예제 #6
0
 private static GLCapabilities stdcaps() {
   GLProfile prof = GLProfile.getDefault();
   GLCapabilities cap = new GLCapabilities(prof);
   cap.setDoubleBuffered(true);
   cap.setAlphaBits(8);
   cap.setRedBits(8);
   cap.setGreenBits(8);
   cap.setBlueBits(8);
   cap.setSampleBuffers(true);
   cap.setNumSamples(4);
   return (cap);
 }
예제 #7
0
  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);
  }
예제 #8
0
  void doTest(
      final boolean onscreen, final GLEventListener demo, final GLProfile glp, final int msaaCount)
      throws IOException {
    final GLCapabilities caps = new GLCapabilities(glp);
    caps.setDoubleBuffered(onscreen);
    if (msaaCount > 0) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(msaaCount);
    }

    final int maxTileSize = 256;
    final GLAutoDrawable glad;
    if (onscreen) {
      final GLWindow glWin = GLWindow.create(caps);
      glWin.setSize(maxTileSize, maxTileSize);
      glWin.setVisible(true);
      glad = glWin;
    } else {
      final GLDrawableFactory factory = GLDrawableFactory.getFactory(glp);
      glad = factory.createOffscreenAutoDrawable(null, caps, null, maxTileSize, maxTileSize);
    }

    glad.addGLEventListener(demo);

    // Fix the image size for now
    final int imageWidth = glad.getSurfaceWidth() * 6;
    final int imageHeight = glad.getSurfaceHeight() * 4;

    final String filename =
        this.getSnapshotFilename(
            0,
            "-tile",
            glad.getChosenGLCapabilities(),
            imageWidth,
            imageHeight,
            false,
            TextureIO.PNG,
            null);
    final File file = new File(filename);

    // Initialize the tile rendering library
    final TileRenderer renderer = new TileRenderer();
    renderer.setImageSize(imageWidth, imageHeight);
    renderer.setTileSize(glad.getSurfaceWidth(), glad.getSurfaceHeight(), 0);
    renderer.attachAutoDrawable(glad);

    final GLPixelBuffer.GLPixelBufferProvider pixelBufferProvider =
        GLPixelBuffer.defaultProviderWithRowStride;
    final boolean[] flipVertically = {false};

    final GLEventListener preTileGLEL =
        new GLEventListener() {
          @Override
          public void init(final GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
            final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3);
            final GLPixelBuffer pixelBuffer =
                pixelBufferProvider.allocate(gl, pixelAttribs, imageWidth, imageHeight, 1, true, 0);
            renderer.setImageBuffer(pixelBuffer);
            if (drawable.isGLOriented()) {
              flipVertically[0] = false;
            } else {
              flipVertically[0] = true;
            }
          }

          @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) {}
        };
    renderer.setGLEventListener(preTileGLEL, null);

    while (!renderer.eot()) {
      renderer.display();
    }

    renderer.detachAutoDrawable();

    // Restore viewport and Gear's PMV matrix
    // .. even though we close the demo, this is for documentation!
    glad.invoke(
        true,
        new GLRunnable() {
          @Override
          public boolean run(final GLAutoDrawable drawable) {
            drawable
                .getGL()
                .glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
            demo.reshape(drawable, 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
            return false;
          }
        });

    final GLPixelBuffer imageBuffer = renderer.getImageBuffer();
    final TextureData textureData =
        new TextureData(
            caps.getGLProfile(),
            0 /* internalFormat */,
            imageWidth,
            imageHeight,
            0,
            imageBuffer.pixelAttributes,
            false,
            false,
            flipVertically[0],
            imageBuffer.buffer,
            null /* Flusher */);

    TextureIO.write(textureData, file);

    glad.destroy();
  }
예제 #9
0
  private boolean mapAvailableEGLESConfig(
      AbstractGraphicsDevice adevice,
      int esProfile,
      boolean[] hasPBuffer,
      GLRendererQuirks[] rendererQuirks,
      int[] ctp) {
    final String profileString;
    switch (esProfile) {
      case 3:
        profileString = GLProfile.GLES3;
        break;
      case 2:
        profileString = GLProfile.GLES2;
        break;
      case 1:
        profileString = GLProfile.GLES1;
        break;
      default:
        throw new GLException("Invalid ES profile number " + esProfile);
    }
    if (!GLProfile.isAvailable(adevice, profileString)) {
      if (DEBUG) {
        System.err.println(
            "EGLDrawableFactory.mapAvailableEGLESConfig: " + profileString + " n/a on " + adevice);
      }
      return false;
    }
    final GLProfile glp = GLProfile.get(adevice, profileString);
    final GLDrawableFactoryImpl desktopFactory =
        (GLDrawableFactoryImpl) GLDrawableFactory.getDesktopFactory();
    final boolean mapsADeviceToDefaultDevice =
        !QUERY_EGL_ES_NATIVE_TK || null == desktopFactory || adevice instanceof EGLGraphicsDevice;
    if (DEBUG) {
      System.err.println(
          "EGLDrawableFactory.mapAvailableEGLESConfig: "
              + profileString
              + " ( "
              + esProfile
              + " ), "
              + "defaultSharedResourceSet "
              + (null != defaultSharedResource)
              + ", mapsADeviceToDefaultDevice "
              + mapsADeviceToDefaultDevice
              + " (QUERY_EGL_ES_NATIVE_TK "
              + QUERY_EGL_ES_NATIVE_TK
              + ", hasDesktopFactory "
              + (null != desktopFactory)
              + ", isEGLGraphicsDevice "
              + (adevice instanceof EGLGraphicsDevice)
              + ")");
    }

    EGLGraphicsDevice eglDevice = null;
    NativeSurface surface = null;
    ProxySurface upstreamSurface = null; // X11, GLX, ..
    boolean success = false;
    boolean deviceFromUpstreamSurface = false;
    try {
      final GLCapabilities reqCapsAny = new GLCapabilities(glp);
      reqCapsAny.setRedBits(5);
      reqCapsAny.setGreenBits(5);
      reqCapsAny.setBlueBits(5);
      reqCapsAny.setAlphaBits(0);
      reqCapsAny.setDoubleBuffered(false);

      if (mapsADeviceToDefaultDevice) {
        // In this branch, any non EGL device is mapped to EGL default shared resources (default
        // behavior).
        // Only one default shared resource instance is ever be created.
        final GLCapabilitiesImmutable reqCapsPBuffer =
            GLGraphicsConfigurationUtil.fixGLPBufferGLCapabilities(reqCapsAny);
        final List<GLCapabilitiesImmutable> availablePBufferCapsL =
            getAvailableEGLConfigs(defaultDevice, reqCapsPBuffer);
        hasPBuffer[0] = availablePBufferCapsL.size() > 0;

        // 1st case: adevice is not the EGL default device, map default shared resources
        if (adevice != defaultDevice) {
          if (null == defaultSharedResource) {
            return false;
          }
          switch (esProfile) {
            case 3:
              if (!defaultSharedResource.wasES3ContextCreated) {
                return false;
              }
              rendererQuirks[0] = defaultSharedResource.rendererQuirksES3ES2;
              ctp[0] = defaultSharedResource.ctpES3ES2;
              break;
            case 2:
              if (!defaultSharedResource.wasES2ContextCreated) {
                return false;
              }
              rendererQuirks[0] = defaultSharedResource.rendererQuirksES3ES2;
              ctp[0] = defaultSharedResource.ctpES3ES2;
              break;
            case 1:
              if (!defaultSharedResource.wasES1ContextCreated) {
                return false;
              }
              rendererQuirks[0] = defaultSharedResource.rendererQuirksES1;
              ctp[0] = defaultSharedResource.ctpES1;
              break;
          }
          EGLContext.mapStaticGLVersion(adevice, esProfile, 0, ctp[0]);
          return true;
        }

        // attempt to created the default shared resources ..

        eglDevice = defaultDevice; // reuse

        if (hasPBuffer[0]) {
          // 2nd case create defaultDevice shared resource using pbuffer surface
          surface =
              createDummySurfaceImpl(
                  eglDevice,
                  false,
                  reqCapsPBuffer,
                  reqCapsPBuffer,
                  null,
                  64,
                  64); // egl pbuffer offscreen
          upstreamSurface = (ProxySurface) surface;
          upstreamSurface.createNotify();
          deviceFromUpstreamSurface = false;
        } else {
          // 3rd case fake creation of defaultDevice shared resource, no pbuffer available
          final List<GLCapabilitiesImmutable> capsAnyL =
              getAvailableEGLConfigs(eglDevice, reqCapsAny);
          if (capsAnyL.size() > 0) {
            final GLCapabilitiesImmutable chosenCaps = capsAnyL.get(0);
            EGLContext.mapStaticGLESVersion(eglDevice, chosenCaps);
            success = true;
          }
          if (DEBUG) {
            System.err.println(
                "EGLDrawableFactory.mapAvailableEGLESConfig() no pbuffer config available, detected !pbuffer config: "
                    + success);
            EGLGraphicsConfigurationFactory.printCaps("!PBufferCaps", capsAnyL, System.err);
          }
        }
      } else {
        // 4th case always creates a true mapping of given device to EGL
        surface =
            desktopFactory.createDummySurface(
                adevice, reqCapsAny, null, 64, 64); // X11, WGL, .. dummy window
        upstreamSurface = (surface instanceof ProxySurface) ? (ProxySurface) surface : null;
        if (null != upstreamSurface) {
          upstreamSurface.createNotify();
        }
        eglDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(surface);
        deviceFromUpstreamSurface = true;
        hasPBuffer[0] = true;
      }

      if (null != surface) {
        final EGLDrawable drawable =
            (EGLDrawable)
                createOnscreenDrawableImpl(
                    surface); // works w/ implicit pbuffer surface via proxy-hook
        drawable.setRealized(true);
        final EGLContext context = (EGLContext) drawable.createContext(null);
        if (null != context) {
          try {
            context.makeCurrent(); // could cause exception
            if (context.isCurrent()) {
              final String glVersion = context.getGL().glGetString(GL.GL_VERSION);
              if (null != glVersion) {
                context.mapCurrentAvailableGLVersion(eglDevice);
                if (eglDevice != adevice) {
                  context.mapCurrentAvailableGLVersion(adevice);
                }
                rendererQuirks[0] = context.getRendererQuirks();
                ctp[0] = context.getContextOptions();
                success = true;
              } else {
                // Oops .. something is wrong
                if (DEBUG) {
                  System.err.println(
                      "EGLDrawableFactory.mapAvailableEGLESConfig: "
                          + eglDevice
                          + ", "
                          + context.getGLVersion()
                          + " - VERSION is null, dropping availability!");
                }
              }
            }
          } catch (GLException gle) {
            if (DEBUG) {
              System.err.println(
                  "EGLDrawableFactory.mapAvailableEGLESConfig: INFO: context create/makeCurrent failed");
              gle.printStackTrace();
            }
          } finally {
            context.destroy();
          }
        }
        drawable.setRealized(false);
      }
    } catch (Throwable t) {
      if (DEBUG) {
        System.err.println("Catched Exception on thread " + getThreadName());
        t.printStackTrace();
      }
      success = false;
    } finally {
      if (eglDevice == defaultDevice) {
        if (null != upstreamSurface) {
          upstreamSurface.destroyNotify();
        }
      } else if (deviceFromUpstreamSurface) {
        if (null != eglDevice) {
          eglDevice.close();
        }
        if (null != upstreamSurface) {
          upstreamSurface.destroyNotify();
        }
      } else {
        if (null != upstreamSurface) {
          upstreamSurface.destroyNotify();
        }
        if (null != eglDevice) {
          eglDevice.close();
        }
      }
    }
    return success;
  }
예제 #10
0
파일: Local.java 프로젝트: Vineg/aparapi
  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>&micro;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();
  }
예제 #11
0
  /**
   * 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);
  }