Exemple #1
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();
  }
Exemple #2
0
 /** Returns the default, desired OpenGL capabilities needed for this component. */
 public static GLCapabilities getDefaultCapabalities() {
   GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES1());
   caps.setRedBits(8);
   caps.setGreenBits(8);
   caps.setBlueBits(8);
   caps.setAlphaBits(8);
   caps.setDoubleBuffered(true);
   caps.setHardwareAccelerated(true);
   caps.setNumSamples(4);
   caps.setBackgroundOpaque(false);
   caps.setSampleBuffers(true);
   return caps;
 }
  protected void initGLCanvas() {
    loadNatives();

    device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

    // FIXME use the settings to know whether to use the max programmable profile
    // then call GLProfile.getMaxProgrammable(true);
    GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc(true));
    caps.setHardwareAccelerated(true);
    caps.setDoubleBuffered(true);
    caps.setStencilBits(settings.getStencilBits());
    caps.setDepthBits(settings.getDepthBits());

    if (settings.getSamples() > 1) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(settings.getSamples());
    }

    canvas =
        new GLCanvas(caps) {
          @Override
          public void addNotify() {
            super.addNotify();
            onCanvasAdded();
          }

          @Override
          public void removeNotify() {
            onCanvasRemoved();
            super.removeNotify();
          }
        };
    canvas.invoke(
        false,
        new GLRunnable() {
          public boolean run(GLAutoDrawable glad) {
            canvas.getGL().setSwapInterval(settings.isVSync() ? 1 : 0);
            return true;
          }
        });
    canvas.setFocusable(true);
    canvas.requestFocus();
    canvas.setSize(settings.getWidth(), settings.getHeight());
    canvas.setIgnoreRepaint(true);
    canvas.addGLEventListener(this);

    // FIXME not sure it is the best place to do that
    renderable.set(true);

    // TODO remove this block once for all when the unified renderer is stable
    /*if (settings.getBoolean("GraphicsDebug")) {
        canvas.invoke(false, new GLRunnable() {
            public boolean run(GLAutoDrawable glad) {
                GL gl = glad.getGL();
                if (gl.isGLES()) {
                    if (gl.isGLES1()) {
                        glad.setGL(new DebugGLES1(gl.getGLES1()));
                    } else {
                        if (gl.isGLES2()) {
                            glad.setGL(new DebugGLES2(gl.getGLES2()));
                        } else {
                            if (gl.isGLES3()) {
                            	glad.setGL(new DebugGLES3(gl.getGLES3()));
                            }
                        }
                    }
                } else {
                    if (gl.isGL4bc()) {
                        glad.setGL(new DebugGL4bc(gl.getGL4bc()));
                    } else {
                        if (gl.isGL4()) {
                            glad.setGL(new DebugGL4(gl.getGL4()));
                        } else {
                            if (gl.isGL3bc()) {
                                glad.setGL(new DebugGL3bc(gl.getGL3bc()));
                            } else {
                                if (gl.isGL3()) {
                                    glad.setGL(new DebugGL3(gl.getGL3()));
                                } else {
                                    if (gl.isGL2()) {
                                        glad.setGL(new DebugGL2(gl.getGL2()));
                                    }
                                }
                            }
                        }
                    }
                }
                return true;
            }
        });
    }

    renderer = new JoglRenderer();

    canvas.invoke(false, new GLRunnable() {
        public boolean run(GLAutoDrawable glad) {
            renderer.setMainFrameBufferSrgb(settings.getGammaCorrection());
            return true;
        }
    });*/
  }