@Test
 public void test01_DefaultNorm()
     throws AWTException, InterruptedException, InvocationTargetException {
   final GLProfile glp;
   if (forceGL3) {
     glp = GLProfile.get(GLProfile.GL3);
   } else if (forceES3) {
     glp = GLProfile.get(GLProfile.GLES3);
   } else if (forceES2) {
     glp = GLProfile.get(GLProfile.GLES2);
   } else if (forceGLFFP) {
     glp = GLProfile.getMaxFixedFunc(true);
   } else {
     glp = GLProfile.getDefault();
   }
   final GLCapabilities caps = new GLCapabilities(glp);
   if (useMSAA) {
     caps.setNumSamples(msaaNumSamples);
     caps.setSampleBuffers(true);
   }
   if (shallUsePBuffer) {
     caps.setPBuffer(true);
   }
   if (shallUseBitmap) {
     caps.setBitmap(true);
   }
   runTestGL(caps);
 }
  public static void main(String[] args) {

    Display display = NewtFactory.createDisplay(null);
    Screen screen = NewtFactory.createScreen(display, 0);
    GLProfile glProfile = GLProfile.get(GLProfile.GL3);
    GLCapabilities glCapabilities = new GLCapabilities(glProfile);
    glWindow = GLWindow.create(screen, glCapabilities);

    glWindow.setSize(1024, 768);
    glWindow.setPosition(50, 50);
    glWindow.setUndecorated(false);
    glWindow.setAlwaysOnTop(false);
    glWindow.setFullscreen(false);
    glWindow.setPointerVisible(true);
    glWindow.confinePointer(false);
    glWindow.setTitle("Hello Triangle");

    glWindow.setVisible(true);

    HelloTriangle helloTriangle = new HelloTriangle();
    glWindow.addGLEventListener(helloTriangle);
    glWindow.addKeyListener(helloTriangle);

    animator = new Animator(glWindow);
    animator.start();
  }
Beispiel #3
0
  /** Default constructor for the window */
  public ExampleJOGL() {
    super("JOGL Example");

    // setup the JFrame
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create the size of the window
    Dimension size = new Dimension(800, 600);

    // setup OpenGL capabilities
    GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
    caps.setDoubleBuffered(true);
    caps.setHardwareAccelerated(true);

    // create a canvas to paint to
    this.canvas = new GLCanvas(caps);
    this.canvas.setPreferredSize(size);
    this.canvas.setMinimumSize(size);
    this.canvas.setMaximumSize(size);
    this.canvas.setIgnoreRepaint(true);
    this.canvas.addGLEventListener(this);

    // add the canvas to the JFrame
    this.add(this.canvas);

    // make the JFrame not resizable
    // (this way I dont have to worry about resize events)
    this.setResizable(false);

    // size everything
    this.pack();

    // setup the world
    this.initializeWorld();
  }
 static GLCapabilities getCaps(final String profile) {
   if (!GLProfile.isAvailable(profile)) {
     System.err.println("Profile " + profile + " n/a");
     return null;
   }
   return new GLCapabilities(GLProfile.get(profile));
 }
 @BeforeClass
 public static void initClass() {
   if (GLProfile.isAvailable(GLProfile.GL2ES2)) {
     glp = GLProfile.get(GLProfile.GL2ES2);
     Assert.assertNotNull(glp);
     caps = new GLCapabilities(glp);
     Assert.assertNotNull(caps);
     width = 256;
     height = 256;
   } else {
     setTestSupported(false);
   }
 }
Beispiel #6
0
Datei: Main.java Projekt: io7m/r2
  /**
   * Main program.
   *
   * @param args Command line arguments
   * @throws Exception On errors
   */
  public static void main(final String[] args) throws Exception {
    if (args.length != 3 && args.length != 4) {
      Main.LOG.info("usage: root file.vert [file.geom] file.frag");
      System.exit(1);
    }

    final File root = new File(args[0]);

    final R2ShaderPreprocessorType p = R2ShaderPreprocessor.newPreprocessor(root);

    List<String> vs = null;
    Optional<List<String>> gs = null;
    List<String> fs = null;

    try {
      if (args.length == 4) {
        vs = p.preprocessFile(args[1]);
        gs = Optional.of(p.preprocessFile(args[2]));
        fs = p.preprocessFile(args[3]);
      } else {
        vs = p.preprocessFile(args[1]);
        gs = Optional.empty();
        fs = p.preprocessFile(args[2]);
      }
    } catch (final Exception e) {
      Main.LOG.error("Preprocessing failure: ", e);
      System.exit(1);
    }

    final GLProfile pro = GLProfile.get(GLProfile.GL3);
    final GLCapabilities caps = new GLCapabilities(pro);
    final GLDrawableFactory f = GLDrawableFactory.getFactory(pro);
    final GLOffscreenAutoDrawable drawable =
        f.createOffscreenAutoDrawable(null, caps, null, 32, 32);
    drawable.display();
    final GLContext ctx = drawable.getContext();
    ctx.makeCurrent();

    try {
      final JCGLImplementationJOGLType i = JCGLImplementationJOGL.getInstance();
      final JCGLContextType jc = i.newContextFrom(ctx, "offscreen");
      final JCGLInterfaceGL33Type gi = jc.contextGetGL33();
      final R2ShaderCheckerType ch = R2ShaderChecker.newChecker(gi.getShaders());

      ch.check(vs, gs, fs);
    } finally {
      ctx.release();
      drawable.destroy();
    }
  }
  @Test
  public void test40_GL3() throws AWTException, InterruptedException, InvocationTargetException {
    if (manualTest) {
      return;
    }

    if (!GLProfile.isAvailable(GLProfile.GL3)) {
      System.err.println("GL3 n/a");
      return;
    }
    final GLProfile glp = GLProfile.get(GLProfile.GL3);
    final GLCapabilities caps = new GLCapabilities(glp);
    runTestGL(caps);
  }
 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 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);
 }
Beispiel #10
0
 public Triangle() {
   super(new GLCapabilities(GLProfile.get("GL3")));
   setSize(800, 800);
   addGLEventListener(this);
 }
  public void testImpl() throws InterruptedException {
    final JFrame frame = new JFrame(this.getSimpleTestName("."));

    //
    // GLDrawableFactory factory = GLDrawableFactory.getFactory(GLProfile.get(GLProfile.GL2));
    // GLContext sharedContext = factory.getOrCreateSharedContext(factory.getDefaultDevice());
    //
    final GLCapabilities glCapabilities = new GLCapabilities(GLProfile.get(GLProfile.GL2));
    glCapabilities.setSampleBuffers(true);
    glCapabilities.setNumSamples(4);

    final GearsES2 eventListener1 = new GearsES2(0);
    final GearsES2 eventListener2 = new GearsES2(1);

    final Component openGLComponent1;
    final Component openGLComponent2;
    final GLAutoDrawable openGLAutoDrawable1;
    final GLAutoDrawable openGLAutoDrawable2;

    final GLWindow glWindow1 = GLWindow.create(glCapabilities);
    final NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1);
    newtCanvasAWT1.setPreferredSize(new Dimension(640, 480));
    glWindow1.addGLEventListener(eventListener1);
    //
    final GLWindow glWindow2 = GLWindow.create(glCapabilities);
    final NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2);
    newtCanvasAWT2.setPreferredSize(new Dimension(640, 480));
    glWindow2.addGLEventListener(eventListener2);

    openGLComponent1 = newtCanvasAWT1;
    openGLComponent2 = newtCanvasAWT2;
    openGLAutoDrawable1 = glWindow1;
    openGLAutoDrawable2 = glWindow2;

    // group both OpenGL canvases / windows into a horizontal panel
    final JPanel openGLPanel = new JPanel();
    openGLPanel.setLayout(new BoxLayout(openGLPanel, BoxLayout.LINE_AXIS));
    openGLPanel.add(openGLComponent1);
    openGLPanel.add(Box.createHorizontalStrut(5));
    openGLPanel.add(openGLComponent2);

    final JPanel mainPanel = (JPanel) frame.getContentPane();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.LINE_AXIS));
    mainPanel.add(Box.createHorizontalGlue());
    mainPanel.add(openGLPanel);
    mainPanel.add(Box.createHorizontalGlue());

    final Animator animator = new Animator(Thread.currentThread().getThreadGroup());
    animator.setUpdateFPSFrames(1, null);
    animator.add(openGLAutoDrawable1);
    animator.add(openGLAutoDrawable2);

    // make the window visible using the EDT
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            frame.pack();
            frame.setVisible(true);
          }
        });

    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent1, true));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent2, true));

    animator.start();

    // sleep for test duration, then request the window to close, wait for the window to close,s and
    // stop the animation
    while (animator.isAnimating() && animator.getTotalFPSDuration() < durationPerTest) {
      Thread.sleep(100);
    }

    animator.stop();

    // ask the EDT to dispose of the frame;
    // if using newt, explicitly dispose of the canvases because otherwise it seems our destroy
    // methods are not called
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            newtCanvasAWT1.destroy(); // removeNotify does not destroy GLWindow
            newtCanvasAWT2.destroy(); // removeNotify does not destroy GLWindow
            frame.dispose();
          }
        });
    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, false));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent1, false));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent2, false));
  }
    @Override
    public SharedResourceRunner.Resource createSharedResource(
        final AbstractGraphicsDevice adevice) {
      final X11GraphicsDevice device =
          new X11GraphicsDevice(
              X11Util.openDisplay(adevice.getConnection()), adevice.getUnitID(), true /* owner */);
      GLContextImpl context = null;
      boolean contextIsCurrent = false;
      device.lock();
      try {
        final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen());

        GLXUtil.initGLXClientDataSingleton(device);
        final String glXServerVendorName =
            GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_VENDOR);
        final boolean glXServerMultisampleAvailable =
            GLXUtil.isMultisampleAvailable(
                GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_EXTENSIONS));

        final GLProfile glp = GLProfile.get(device, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false);
        if (null == glp) {
          throw new GLException("Couldn't get default GLProfile for device: " + device);
        }

        final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
        final GLDrawableImpl drawable =
            createOnscreenDrawableImpl(
                createDummySurfaceImpl(device, false, caps, caps, null, 64, 64));
        drawable.setRealized(true);
        final X11GLCapabilities chosenCaps = (X11GLCapabilities) drawable.getChosenGLCapabilities();
        final boolean glxForcedOneOne = !chosenCaps.hasFBConfig();
        final VersionNumber glXServerVersion;
        if (glxForcedOneOne) {
          glXServerVersion = versionOneOne;
        } else {
          glXServerVersion = GLXUtil.getGLXServerVersionNumber(device);
        }
        context = (GLContextImpl) drawable.createContext(null);
        if (null == context) {
          throw new GLException("Couldn't create shared context for drawable: " + drawable);
        }
        contextIsCurrent = GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent();

        final boolean allowsSurfacelessCtx;
        if (contextIsCurrent && context.getGLVersionNumber().compareTo(GLContext.Version3_0) >= 0) {
          allowsSurfacelessCtx = probeSurfacelessCtx(context, true /* restoreDrawable */);
        } else {
          setNoSurfacelessCtxQuirk(context);
          allowsSurfacelessCtx = false;
        }

        if (context.hasRendererQuirk(GLRendererQuirks.DontCloseX11Display)) {
          X11Util.markAllDisplaysUnclosable();
        }
        if (DEBUG_SHAREDCTX) {
          System.err.println("SharedDevice:  " + device);
          System.err.println("SharedScreen:  " + screen);
          System.err.println("SharedContext: " + context + ", madeCurrent " + contextIsCurrent);
          System.err.println("  allowsSurfacelessCtx " + allowsSurfacelessCtx);
          System.err.println("GLX Server Vendor:      " + glXServerVendorName);
          System.err.println(
              "GLX Server Version:     " + glXServerVersion + ", forced " + glxForcedOneOne);
          System.err.println("GLX Server Multisample: " + glXServerMultisampleAvailable);
          System.err.println("GLX Client Vendor:      " + GLXUtil.getClientVendorName());
          System.err.println("GLX Client Version:     " + GLXUtil.getClientVersionNumber());
          System.err.println("GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable());
        }
        return new SharedResource(
            device,
            screen,
            drawable,
            context,
            glXServerVersion,
            glXServerVendorName,
            glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable());
      } catch (final Throwable t) {
        throw new GLException(
            "X11GLXDrawableFactory - Could not initialize shared resources for " + adevice, t);
      } finally {
        if (contextIsCurrent) {
          context.release();
        }
        device.unlock();
      }
    }