Example #1
0
  WindowContext createWindow(final GLProfile glp, final boolean debugGL) {
    final GLCapabilities caps = new GLCapabilities(glp);
    //
    // Create native windowing resources .. X11/Win/OSX
    //
    final Display display = NewtFactory.createDisplay(null); // local display
    Assert.assertNotNull(display);

    final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
    Assert.assertNotNull(screen);

    final Window window = NewtFactory.createWindow(screen, caps);
    Assert.assertNotNull(window);
    window.setSize(128, 128);
    window.setVisible(true);

    final GLDrawableFactory factory = GLDrawableFactory.getFactory(glp);
    final GLDrawable drawable = factory.createGLDrawable(window);
    Assert.assertNotNull(drawable);

    drawable.setRealized(true);

    final GLContext context = drawable.createContext(null);
    Assert.assertNotNull(context);

    context.enableGLDebugMessage(debugGL);

    final int res = context.makeCurrent();
    Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW == res || GLContext.CONTEXT_CURRENT == res);

    return new WindowContext(window, context);
  }
Example #2
0
File: Main.java Project: 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();
    }
  }