Ejemplo n.º 1
0
  protected void endDrawIcons(DrawContext dc) {
    if (dc.isPickingMode()) this.pickSupport.endPicking(dc);

    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    if (dc.isPickingMode()) {
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, OGLUtil.DEFAULT_TEX_ENV_MODE);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_SRC0_RGB, OGLUtil.DEFAULT_SRC0_RGB);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_COMBINE_RGB, OGLUtil.DEFAULT_COMBINE_RGB);
    }

    gl.glBindTexture(GL.GL_TEXTURE_2D, 0);

    this.oglStackHandler.pop(gl);
  }
Ejemplo n.º 2
0
  protected void applyColor(DrawContext dc, java.awt.Color color, double opacity) {
    if (dc.isPickingMode()) return;

    double finalOpacity = opacity * (color.getAlpha() / 255.0);
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
    OGLUtil.applyColor(gl, color, finalOpacity, true);
  }
Ejemplo n.º 3
0
  protected void beginDrawIcons(DrawContext dc) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    this.oglStackHandler.clear();

    int attributeMask =
        GL2.GL_DEPTH_BUFFER_BIT // for depth test, depth mask and depth func
            | GL2.GL_TRANSFORM_BIT // for modelview and perspective
            | GL2.GL_VIEWPORT_BIT // for depth range
            | GL2.GL_CURRENT_BIT // for current color
            | GL2.GL_COLOR_BUFFER_BIT // for alpha test func and ref, and blend
            | GL2.GL_DEPTH_BUFFER_BIT // for depth func
            | GL2.GL_ENABLE_BIT; // for enable/disable changes
    this.oglStackHandler.pushAttrib(gl, attributeMask);

    // Apply the depth buffer but don't change it.
    if ((!dc.isDeepPickingEnabled())) gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthMask(false);

    // Suppress any fully transparent image pixels
    gl.glEnable(GL2.GL_ALPHA_TEST);
    gl.glAlphaFunc(GL2.GL_GREATER, 0.001f);

    // Load a parallel projection with dimensions (viewportWidth, viewportHeight)
    this.oglStackHandler.pushProjectionIdentity(gl);
    gl.glOrtho(
        0d, dc.getView().getViewport().width, 0d, dc.getView().getViewport().height, -1d, 1d);

    this.oglStackHandler.pushModelview(gl);
    this.oglStackHandler.pushTexture(gl);

    if (dc.isPickingMode()) {
      this.pickSupport.beginPicking(dc);

      // Set up to replace the non-transparent texture colors with the single pick color.
      gl.glEnable(GL.GL_TEXTURE_2D);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_COMBINE);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_SRC0_RGB, GL2.GL_PREVIOUS);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_COMBINE_RGB, GL2.GL_REPLACE);
    } else {
      gl.glEnable(GL.GL_TEXTURE_2D);
      gl.glEnable(GL.GL_BLEND);
      gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA);
    }
  }
Ejemplo n.º 4
0
  /**
   * Returns true if the IconRenderer should record feedback about how the specified WWIcon has been
   * processed.
   *
   * @param dc the current DrawContext.
   * @param icon the WWIcon to record feedback information for.
   * @return true to record feedback; false otherwise.
   */
  protected boolean isFeedbackEnabled(DrawContext dc, WWIcon icon) {
    if (dc.isPickingMode()) return false;

    Boolean b = (Boolean) icon.getValue(AVKey.FEEDBACK_ENABLED);
    return (b != null && b);
  }
Ejemplo n.º 5
0
  protected Vec4 drawIcon(DrawContext dc, OrderedIcon uIcon) {
    if (uIcon.point == null) {
      String msg = Logging.getMessage("nullValue.PointIsNull");
      Logging.logger().severe(msg);

      // Record feedback data for this WWIcon if feedback is enabled.
      if (uIcon.icon != null) this.recordFeedback(dc, uIcon.icon, null, null);

      return null;
    }

    WWIcon icon = uIcon.icon;
    if (dc.getView().getFrustumInModelCoordinates().getNear().distanceTo(uIcon.point) < 0) {
      // Record feedback data for this WWIcon if feedback is enabled.
      this.recordFeedback(dc, icon, uIcon.point, null);

      return null;
    }

    final Vec4 screenPoint = dc.getView().project(uIcon.point);
    if (screenPoint == null) {
      // Record feedback data for this WWIcon if feedback is enabled.
      this.recordFeedback(dc, icon, uIcon.point, null);

      return null;
    }

    double pedestalScale;
    double pedestalSpacing;
    if (this.pedestal != null) {
      pedestalScale = this.pedestal.getScale();
      pedestalSpacing = pedestal.getSpacingPixels();
    } else {
      pedestalScale = 0d;
      pedestalSpacing = 0d;
    }

    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    this.setDepthFunc(dc, uIcon, screenPoint);

    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    Dimension size = icon.getSize();
    double width = size != null ? size.getWidth() : icon.getImageTexture().getWidth(dc);
    double height = size != null ? size.getHeight() : icon.getImageTexture().getHeight(dc);
    gl.glTranslated(
        screenPoint.x - width / 2, screenPoint.y + (pedestalScale * height) + pedestalSpacing, 0d);

    if (icon.isHighlighted()) {
      double heightDelta = this.pedestal != null ? 0 : height / 2; // expand only above the pedestal
      gl.glTranslated(width / 2, heightDelta, 0);
      gl.glScaled(icon.getHighlightScale(), icon.getHighlightScale(), icon.getHighlightScale());
      gl.glTranslated(-width / 2, -heightDelta, 0);
    }

    Rectangle rect =
        new Rectangle(
            (int) (screenPoint.x - width / 2),
            (int) (screenPoint.y),
            (int) width,
            (int) (height + (pedestalScale * height) + pedestalSpacing));

    if (dc.isPickingMode()) {
      // If in picking mode and pick clipping is enabled, check to see if the icon is within the
      // pick volume.
      if (this.isPickFrustumClippingEnabled() && !dc.getPickFrustums().intersectsAny(rect)) {
        // Record feedback data for this WWIcon if feedback is enabled.
        this.recordFeedback(dc, icon, uIcon.point, rect);

        return screenPoint;
      } else {
        java.awt.Color color = dc.getUniquePickColor();
        int colorCode = color.getRGB();
        this.pickSupport.addPickableObject(colorCode, icon, uIcon.getPosition(), false);
        gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
      }
    }

    if (icon.getBackgroundTexture() != null)
      this.applyBackground(dc, icon, screenPoint, width, height, pedestalSpacing, pedestalScale);

    if (icon.getImageTexture().bind(dc)) {
      TextureCoords texCoords = icon.getImageTexture().getTexCoords();
      gl.glScaled(width, height, 1d);
      dc.drawUnitQuad(texCoords);
    }

    if (this.pedestal != null && this.pedestal.getImageTexture() != null) {
      gl.glLoadIdentity();
      gl.glTranslated(screenPoint.x - (pedestalScale * (width / 2)), screenPoint.y, 0d);
      gl.glScaled(width * pedestalScale, height * pedestalScale, 1d);

      if (this.pedestal.getImageTexture().bind(dc)) {
        TextureCoords texCoords = this.pedestal.getImageTexture().getTexCoords();
        dc.drawUnitQuad(texCoords);
      }
    }

    // Record feedback data for this WWIcon if feedback is enabled.
    this.recordFeedback(dc, icon, uIcon.point, rect);

    return screenPoint;
  }