コード例 #1
0
  /**
   * Implement stereo using the stereo-enabled graphics device. The mode has an effect only if the
   * display device implements stereo.
   *
   * @param dc the current draw context.
   */
  protected void doDrawToStereoDevice(DrawContext dc) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
    View dcView = dc.getView();

    // Draw the left eye
    if (this.isSwapEyes()) gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
    else gl.glDrawBuffer(GL2.GL_BACK_LEFT);

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    super.draw(dc);

    // Move the view to the right eye
    Angle viewHeading = dcView.getHeading();
    dcView.setHeading(dcView.getHeading().subtract(this.getFocusAngle()));
    dcView.apply(dc);

    // Draw the right eye
    try {
      if (this.isSwapEyes()) gl.glDrawBuffer(GL2.GL_BACK_LEFT);
      else gl.glDrawBuffer(GL2.GL_BACK_RIGHT);

      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      super.draw(dc);
    } finally {
      // Restore the original view heading
      dcView.setHeading(viewHeading);
      dcView.apply(dc);
    }
  }
コード例 #2
0
  /**
   * Implement stereo using the red-blue anaglyph technique.
   *
   * @param dc the current draw context.
   */
  protected void doDrawStereoRedBlue(DrawContext dc) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
    View dcView = dc.getView();

    // Draw the left eye
    if (this.isSwapEyes()) {
      if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
      gl.glColorMask(false, true, true, true); // right eye in green/blue
    } else {
      if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_LEFT);
      gl.glColorMask(true, false, false, true); // left eye in red only
    }

    if (this.isHardwareStereo()) gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    super.draw(dc);

    // Move the view to the right eye
    Angle viewHeading = dcView.getHeading();
    dcView.setHeading(dcView.getHeading().subtract(this.getFocusAngle()));
    dcView.apply(dc);

    // Draw the right eye frame green and blue only
    try {
      gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
      if (this.isSwapEyes()) {
        if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
        gl.glColorMask(true, false, false, true); // right eye in red only
      } else {
        if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_LEFT);
        gl.glColorMask(false, true, true, true); // right eye in green/blue
      }

      if (this.isHardwareStereo()) gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      super.draw(dc);
    } finally {
      // Restore the original view heading
      dcView.setHeading(viewHeading);
      dcView.apply(dc);
      gl.glColorMask(true, true, true, true);
    }
  }