예제 #1
0
  /**
   * Init the rendering of this canvas. This function is called right before the first rendering
   * run. Its used to setup everything correctly.
   *
   * @param drawable the drawable object used to access the openGL functions
   */
  @Override
  public void init(final GLAutoDrawable drawable) {
    if (drawable.getContext() == null) {
      return;
    }
    displayOpenGLStatusInfo();
    // drawable.setGL(new DebugGL(drawable.getGL()));
    setupViewport(drawable);

    boolean releaseContext = false;
    if (GLContext.getCurrent() == null) {
      drawable.getContext().makeCurrent();
      releaseContext = true;
    }

    final GL gl = drawable.getGL();
    gl.glEnable(GL.GL_BLEND);
    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    // getContext().setSynchronized(true);
    gl.setSwapInterval(0); // disable vsync

    if (releaseContext) {
      drawable.getContext().release();
    }
  }
예제 #2
0
 public void init(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();
   System.err.println("INIT GL IS: " + gl.getClass().getName());
   gl.setSwapInterval(1);
   gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
 }
예제 #3
0
  @Override
  public void init(GLAutoDrawable drawable) {
    GL _gl = drawable.getGL();

    if (glDebug) {
      try {
        _gl =
            _gl.getContext()
                .setGL(GLPipelineFactory.create("javax.media.opengl.Debug", null, _gl, null));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (glTrace) {
      try {
        // Trace ..
        _gl =
            _gl.getContext()
                .setGL(
                    GLPipelineFactory.create(
                        "javax.media.opengl.Trace", null, _gl, new Object[] {System.err}));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (glSwapInterval >= 0) {
      _gl.setSwapInterval(glSwapInterval);
    }
  }
예제 #4
0
  /** OpenGL reshape function Perspective and view calls go here */
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    final GL gl = drawable.getGL();
    final GLU glu = new GLU();

    gl.setSwapInterval(1);

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45.0f, (double) width / (double) height, 0.1f, 1000.0f);

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
예제 #5
0
  private void initOpenGL() {
    pgl = (PGraphicsOpenGL) g;
    gl = pgl.gl;
    gl.setSwapInterval(1);

    gl.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
    gl.glClearDepth(1.0f); // Depth Buffer Setup
    gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing
    gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do
    gl.glHint(
        GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // Really Nice Perspective Calculations
    gl.glDisable(GL.GL_TEXTURE_2D);

    // Set up lighting
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightAmbient, 0);
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, lightDiffuse, 0);
    //      gl.glLightfv( GL.GL_LIGHT1, GL.GL_SPECULAR, lightSpecular, 0 );
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPosition, 0);
    gl.glEnable(GL.GL_LIGHTING);
    gl.glEnable(GL.GL_LIGHT1);
  }