// Might be reduced to !MSAA
 @Test
 public void testGL2OffScreenBitmapDblBufMSAA() throws InterruptedException {
   final GLCapabilities reqGLCaps = new GLCapabilities(GLProfile.getDefault());
   reqGLCaps.setOnscreen(false);
   reqGLCaps.setBitmap(true);
   reqGLCaps.setSampleBuffers(true);
   reqGLCaps.setNumSamples(4);
   doTest(reqGLCaps, new Gears(1));
 }
Exemple #2
0
 @Override
 protected GLJPanel createDrawable() {
   GLCapabilities caps = new GLCapabilities(null);
   caps.setSampleBuffers(true); // enable sample buffers for aliasing
   caps.setNumSamples(2);
   //
   GLJPanel panel = new GLJPanel(caps);
   panel.addGLEventListener(this);
   panel.addKeyListener(this);
   return panel;
 }
Exemple #3
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);
 }
  private void testMultiSampleAAImpl(
      final boolean useFBO, final boolean usePBuffer, final int reqSamples)
      throws InterruptedException {
    final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
    final GLProfile glp = GLProfile.getGL2ES2();
    final GLCapabilities caps = new GLCapabilities(glp);
    final GLCapabilitiesChooser chooser = new MultisampleChooser01();

    caps.setAlphaBits(1);
    caps.setFBO(useFBO);
    caps.setPBuffer(usePBuffer);

    if (reqSamples > 0) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(reqSamples);
    }

    final GLWindow window = GLWindow.create(caps);
    window.setCapabilitiesChooser(chooser);
    window.addGLEventListener(new MultisampleDemoES2(reqSamples > 0 ? true : false));
    window.addGLEventListener(
        new GLEventListener() {
          int displayCount = 0;

          public void init(final GLAutoDrawable drawable) {}

          public void dispose(final GLAutoDrawable drawable) {}

          public void display(final GLAutoDrawable drawable) {
            snapshot(displayCount++, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
          }

          public void reshape(
              final GLAutoDrawable drawable,
              final int x,
              final int y,
              final int width,
              final int height) {}
        });
    window.setSize(512, 512);
    window.setVisible(true);
    window.requestFocus();

    Thread.sleep(durationPerTest);

    window.destroy();
  }
Exemple #5
0
  public static void main(String[] args) {
    GLCapabilities caps = new GLCapabilities(null);
    caps.setSampleBuffers(true); // enable sample buffers for aliasing
    caps.setNumSamples(2);

    varray demo = new varray();

    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("varray");
    frame.setSize(512, 256);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.getContentPane().add(demo.drawable);
    frame.setVisible(true);
    demo.drawable.requestFocusInWindow();
  }
Exemple #6
0
  /** Run the game. */
  public void run() {
    GLProfile glProfile = GLProfile.getDefault();
    GLCapabilities glCapabilities = new GLCapabilities(glProfile);
    glCapabilities.setSampleBuffers(true);
    glCapabilities.setNumSamples(4);

    GLJPanel gamePanel = new GLJPanel(glCapabilities);
    JFrame gameFrame = new JFrame("3D Game");

    GameEngine gameEngine = new GameEngine(myTerrain, gamePanel);

    gameEngine.start();

    gameFrame.getContentPane().add(gamePanel, BorderLayout.CENTER);
    gameFrame.setSize(1024, 768);
    gameFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    gameFrame.setVisible(true);

    gamePanel.requestFocusInWindow();
  }
Exemple #7
0
  public static void main(String[] args) {
    GLProfile glp = GLProfile.getGL2ES2();
    GLCapabilities caps = new GLCapabilities(glp);
    caps.setAlphaBits(4);
    caps.setSampleBuffers(true);
    caps.setNumSamples(4);
    System.out.println("Requested: " + caps);

    final GLWindow window = GLWindow.create(caps);
    window.setPosition(10, 10);
    window.setSize(800, 400);
    window.setTitle("GPU UI Newt Demo 01");
    RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
    UIGLListener01 uiGLListener = new UIGLListener01(rs, DEBUG, TRACE);
    uiGLListener.attachInputListenerTo(window);
    window.addGLEventListener(uiGLListener);

    window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
    window.setVisible(true);

    final Animator animator = new Animator();
    animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
    animator.add(window);

    window.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_F4) {
              window.destroy();
            }
          }
        });
    window.addWindowListener(
        new WindowAdapter() {
          public void windowDestroyed(WindowEvent e) {
            animator.stop();
          }
        });

    animator.start();
  }
Exemple #8
0
  public static void main(String[] args) {

    final Configuration config = Configuration.loadFromFile();

    GLProfile glp = GLProfile.get(GLProfile.GL2);
    final GLCapabilities caps = new GLCapabilities(glp);
    caps.setStereo(config.graphics.useStereo);
    if (config.graphics.useFsaa) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(config.graphics.fsaaSamples);
    }

    final String[] arguments = args;

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            new Viewer(config, caps, arguments);
          }
        });
  }
  public void testImpl(
      final int sceneMSAASamples, final int graphMSAASamples, final int graphVBAASamples)
      throws InterruptedException {
    GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
    GLCapabilities caps = new GLCapabilities(glp);
    caps.setAlphaBits(4);
    if (0 < sceneMSAASamples) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(sceneMSAASamples);
    }
    System.err.println(
        "Requested: "
            + caps
            + ", graph[msaaSamples "
            + graphMSAASamples
            + ", vbaaSamples "
            + graphVBAASamples
            + "]");

    GLWindow window =
        createWindow(
            "text-gvbaa"
                + graphVBAASamples
                + "-gmsaa"
                + graphMSAASamples
                + "-smsaa"
                + sceneMSAASamples,
            caps,
            1024,
            640);
    window.display();
    System.err.println("Chosen: " + window.getChosenGLCapabilities());
    if (WaitStartEnd) {
      UITestCase.waitForKey("Start");
    }

    final RenderState rs = RenderState.createRenderState(SVertex.factory());
    final int renderModes, sampleCount;
    if (graphVBAASamples > 0) {
      renderModes = Region.VBAA_RENDERING_BIT;
      sampleCount = graphVBAASamples;
    } else if (graphMSAASamples > 0) {
      renderModes = Region.MSAA_RENDERING_BIT;
      sampleCount = graphMSAASamples;
    } else {
      renderModes = 0;
      sampleCount = 0;
    }
    final TextRendererGLEL textGLListener = new TextRendererGLEL(rs, renderModes, sampleCount);
    System.err.println(textGLListener.getFontInfo());

    window.addGLEventListener(textGLListener);

    Animator anim = new Animator();
    anim.add(window);
    anim.start();
    anim.setUpdateFPSFrames(60, null);
    sleep();
    window.invoke(
        true,
        new GLRunnable() {
          @Override
          public boolean run(GLAutoDrawable drawable) {
            try {
              textGLListener.printScreen(
                  renderModes,
                  drawable,
                  "./",
                  "TestTextRendererNEWT00-snap" + screenshot_num,
                  false);
              screenshot_num++;
            } catch (Exception e) {
              e.printStackTrace();
            }
            return true;
          }
        });
    anim.stop();
    if (WaitStartEnd) {
      UITestCase.waitForKey("Stop");
    }
    destroyWindow(window);
  }
  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();
  }
  /**
   * 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);
  }