private void draw(DrawContext dc) {
    this.referencePoint = this.computeReferencePoint(dc);

    this.assembleTiles(dc); // Determine the tiles to draw.

    if (this.currentTiles.size() >= 1) {
      MercatorTextureTile[] sortedTiles = new MercatorTextureTile[this.currentTiles.size()];
      sortedTiles = this.currentTiles.toArray(sortedTiles);
      Arrays.sort(sortedTiles, levelComparer);

      GL gl = dc.getGL();

      if (this.isUseTransparentTextures() || this.getOpacity() < 1) {
        gl.glPushAttrib(GL.GL_COLOR_BUFFER_BIT | GL.GL_POLYGON_BIT | GL.GL_CURRENT_BIT);
        gl.glColor4d(1d, 1d, 1d, this.getOpacity());
        gl.glEnable(GL.GL_BLEND);
        gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
      } else {
        gl.glPushAttrib(GL.GL_COLOR_BUFFER_BIT | GL.GL_POLYGON_BIT);
      }

      gl.glPolygonMode(GL.GL_FRONT, GL.GL_FILL);
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);

      dc.setPerFrameStatistic(
          PerformanceStatistic.IMAGE_TILE_COUNT, this.tileCountName, this.currentTiles.size());
      dc.getGeographicSurfaceTileRenderer().renderTiles(dc, this.currentTiles);

      gl.glPopAttrib();

      if (this.drawTileIDs) this.drawTileIDs(dc, this.currentTiles);

      if (this.drawBoundingVolumes) this.drawBoundingVolumes(dc, this.currentTiles);

      this.currentTiles.clear();
    }

    this.sendRequests();
    this.requestQ.clear();
  }
  public void render(GLOContext ctx) {
    GUIContext guictx = (GUIContext) ctx;
    GL gl = ctx.getGL();

    ModelRenderer mrend =
        guictx.rendcache.getModelRenderer(xpointermodel, ModelRenderer.NO_NORMALS);

    gl.glPushMatrix(); // #1
    gl.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_POLYGON_BIT);
    gl.glEnable(GL.GL_CULL_FACE);

    setShader("xpointer");
    Point org = origin;
    float w2 = getWidth() * 0.5f;
    float h2 = getHeight() * 0.5f;
    float cenx = org.x + w2;
    float ceny = org.y + h2;

    gl.glTranslatef(cenx, ceny, 0);
    gl.glScalef(w2, h2, 1); // must convert right-hand to left-hand coords

    // draw the x value
    gl.glPushMatrix();
    float xval = getXValue();
    xval = Math.max(-maxrot, Math.min(maxrot, xval * maxrot));
    gl.glRotatef(90, 0, 0, 1);
    gl.glRotatef(xval, -1, 0, 0);
    mrend.render();
    gl.glPopMatrix();

    // draw the y value
    float yval = getYValue();
    yval = Math.max(-maxrot, Math.min(maxrot, yval * maxrot));
    gl.glRotatef(yval, -1, 0, 0);
    mrend.render();

    gl.glPopAttrib();
    gl.glPopMatrix(); // #1
  }
Exemple #3
0
  public void display(GLAutoDrawable glDrawable) {
    GL gl = glDrawable.getGL();

    // Store old matrices
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    gl.glViewport(0, 0, glDrawable.getWidth(), glDrawable.getHeight());

    // Store enabled state and disable lighting, texture mapping and the depth buffer
    gl.glPushAttrib(GL.GL_ENABLE_BIT);
    gl.glDisable(GL.GL_BLEND);
    gl.glDisable(GL.GL_LIGHTING);
    gl.glDisable(GL.GL_TEXTURE_2D);
    gl.glDisable(GL.GL_DEPTH_TEST);

    // Retrieve the current viewport and switch to orthographic mode
    IntBuffer viewPort = BufferUtil.newIntBuffer(4);
    gl.glGetIntegerv(GL.GL_VIEWPORT, viewPort);
    glu.gluOrtho2D(0, viewPort.get(2), viewPort.get(3), 0);

    // Render the text
    gl.glColor3f(1, 1, 1);

    int x = OFFSET;
    int maxx = 0;
    int y = OFFSET + CHAR_HEIGHT;

    if (keyboardEntries.size() > 0) {
      gl.glRasterPos2i(x, y);
      glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS);
      maxx =
          Math.max(
              maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS));

      y += OFFSET;
      x += INDENT;
      for (int i = 0; i < keyboardEntries.size(); i++) {
        gl.glRasterPos2f(x, y);
        String text = (String) keyboardEntries.get(i);
        glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, text);
        maxx = Math.max(maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, text));
        y += OFFSET;
      }
    }

    if (mouseEntries.size() > 0) {
      x = maxx + OFFSET;
      y = OFFSET + CHAR_HEIGHT;
      gl.glRasterPos2i(x, y);
      glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, MOUSE_CONTROLS);

      y += OFFSET;
      x += INDENT;
      for (int i = 0; i < mouseEntries.size(); i++) {
        gl.glRasterPos2f(x, y);
        glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, (String) mouseEntries.get(i));
        y += OFFSET;
      }
    }

    // Restore enabled state
    gl.glPopAttrib();

    // Restore old matrices
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopMatrix();
  }
Exemple #4
0
  @Override
  public void render(final DrawContext dc) {
    //      _lastDC = dc;

    runFrameWorkers();

    final GTexture texture = getTexture();
    if ((texture == null) || !texture.hasGLTexture()) {
      return;
    }

    final GL gl = dc.getGL();

    gl.glPushAttrib(
        GL.GL_DEPTH_BUFFER_BIT
            | GL.GL_COLOR_BUFFER_BIT
            | GL.GL_ENABLE_BIT
            | GL.GL_TEXTURE_BIT
            | GL.GL_TRANSFORM_BIT
            | GL.GL_VIEWPORT_BIT
            | GL.GL_CURRENT_BIT);

    gl.glEnable(GL.GL_BLEND);
    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    gl.glDisable(GL.GL_DEPTH_TEST);

    // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)
    // into the GL projection matrix.
    final Rectangle viewport = dc.getView().getViewport();
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    final double maxwh = Math.max(_textureWidth, _textureHeight);
    gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    // Translate and scale
    final float scale = computeScale(viewport);
    final Vec4 locationSW = computeLocation(viewport, scale);
    gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
    // Scale to 0..1 space
    gl.glScalef(scale, scale, 1f);
    gl.glScaled(_textureWidth, _textureHeight, 1d);

    _lastScreenBounds = calculateScreenBounds(viewport, locationSW, scale);

    texture.enable();
    texture.bind();
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);

    gl.glColor4f(1, 1, 1, calculateOpacity());
    dc.drawUnitQuad(texture.getImageTexCoords());

    texture.disable();

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopMatrix();

    gl.glPopAttrib();
  }
Exemple #5
0
 public void restoreGLState() {
   restoreGLMatrices();
   gl.glPopAttrib();
 }
Exemple #6
0
 public void restoreView() {
   restoreGLMatrices();
   gl.glPopAttrib();
 }
Exemple #7
0
  public void prerenderToTexture(GL gl) {
    int texSize = 256;
    final int[] tmp = new int[1];
    gl.glGenTextures(1, tmp, 0);
    textureID = tmp[0];
    gl.glBindTexture(GL_TEXTURE_2D, textureID);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    gl.glTexImage2D(
        GL_TEXTURE_2D, 0, GL_RGBA, texSize, texSize, 0, GL_BGRA, GL_UNSIGNED_BYTE, null);

    final int[] fbo = new int[1];
    gl.glGenFramebuffersEXT(1, IntBuffer.wrap(fbo));
    gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[0]);
    gl.glFramebufferTexture2DEXT(
        GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureID, 0);

    gl.glDrawBuffers(1, IntBuffer.wrap(new int[] {GL_COLOR_ATTACHMENT0_EXT}));

    final int[] rba = new int[1];
    gl.glGenRenderbuffersEXT(1, IntBuffer.wrap(rba));
    gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rba[0]);
    gl.glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texSize, texSize);
    gl.glFramebufferRenderbufferEXT(
        GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rba[0]);

    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glPushAttrib(GL_VIEWPORT_BIT);
    gl.glViewport(0, 0, texSize, texSize);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glOrtho(0, texSize, 0, texSize, 0, 10);
    gl.glMatrixMode(GL.GL_MODELVIEW);

    Set<MapElement> map = State.getInstance().getMapInfo().queryElements(detailLevel, bounds, true);

    gl.glDisable(GL_TEXTURE_2D);
    gl.glColor3f(1, 1, 1);
    for (MapElement element : map) {
      if (element instanceof Street) {
        drawLine(
            gl,
            ((Street) element).getDrawingSize() / (float) Projection.getZoomFactor(detailLevel),
            ((Street) element).getNodes());
      }
    }
    gl.glColor3f(0.3f, 0.3f, 0.3f);
    for (MapElement element : map) {
      if ((element instanceof Area) && (((Area) element).getWayInfo().isBuilding())) {
        gl.glBegin(GL_POLYGON);
        for (Node node : ((Area) element).getNodes()) {
          Coordinates pos = getLocalCoordinates(node.getPos());
          gl.glVertex3f(pos.getLongitude(), pos.getLatitude(), 0f);
        }
        gl.glEnd();
      }
    }

    gl.glEnable(GL_TEXTURE_2D);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopAttrib();
    gl.glPopMatrix();

    gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    gl.glDeleteFramebuffersEXT(1, fbo, 0);
    gl.glDeleteRenderbuffersEXT(1, rba, 0);
  }
  // Rendering
  public void draw(DrawContext dc) {
    GL gl = dc.getGL();

    boolean attribsPushed = false;
    boolean modelviewPushed = false;
    boolean projectionPushed = false;

    try {
      gl.glPushAttrib(
          GL.GL_DEPTH_BUFFER_BIT
              | GL.GL_COLOR_BUFFER_BIT
              | GL.GL_ENABLE_BIT
              | GL.GL_TEXTURE_BIT
              | GL.GL_TRANSFORM_BIT
              | GL.GL_VIEWPORT_BIT
              | GL.GL_CURRENT_BIT);
      attribsPushed = true;

      gl.glDisable(GL.GL_TEXTURE_2D); // no textures

      gl.glEnable(GL.GL_BLEND);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
      gl.glDisable(GL.GL_DEPTH_TEST);

      double width = this.size.width;
      double height = this.size.height;

      // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)
      // into the GL projection matrix.
      java.awt.Rectangle viewport = dc.getView().getViewport();
      gl.glMatrixMode(javax.media.opengl.GL.GL_PROJECTION);
      gl.glPushMatrix();
      projectionPushed = true;
      gl.glLoadIdentity();
      double maxwh = width > height ? width : height;
      gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);

      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glPushMatrix();
      modelviewPushed = true;
      gl.glLoadIdentity();

      // Scale to a width x height space
      // located at the proper position on screen
      double scale = this.computeScale(viewport);
      Vec4 locationSW = this.computeLocation(viewport, scale);
      gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
      gl.glScaled(scale, scale, 1);

      // Compute scale size in real world
      Position referencePosition = dc.getViewportCenterPosition();
      if (referencePosition != null) {
        Vec4 groundTarget = dc.getGlobe().computePointFromPosition(referencePosition);
        Double distance = dc.getView().getEyePoint().distanceTo3(groundTarget);
        this.pixelSize = dc.getView().computePixelSizeAtDistance(distance);
        Double scaleSize = this.pixelSize * width * scale; // meter
        String unitLabel = "m";
        if (this.unit.equals(UNIT_METRIC)) {
          if (scaleSize > 10000) {
            scaleSize /= 1000;
            unitLabel = "Km";
          }
        } else if (this.unit.equals(UNIT_IMPERIAL)) {
          scaleSize *= 3.280839895; // feet
          unitLabel = "ft";
          if (scaleSize > 5280) {
            scaleSize /= 5280;
            unitLabel = "mile(s)";
          }
        }

        // Rounded division size
        int pot = (int) Math.floor(Math.log10(scaleSize));
        if (!Double.isNaN(pot)) {
          int digit = Integer.parseInt(String.format("%.0f", scaleSize).substring(0, 1));
          double divSize = digit * Math.pow(10, pot);
          if (digit >= 5) divSize = 5 * Math.pow(10, pot);
          else if (digit >= 2) divSize = 2 * Math.pow(10, pot);
          double divWidth = width * divSize / scaleSize;

          // Draw scale
          if (!dc.isPickingMode()) {
            // Set color using current layer opacity
            Color backColor = this.getBackgroundColor(this.color);
            float[] colorRGB = backColor.getRGBColorComponents(null);
            gl.glColor4d(
                colorRGB[0],
                colorRGB[1],
                colorRGB[2],
                (double) backColor.getAlpha() / 255d * this.getOpacity());
            gl.glTranslated((width - divWidth) / 2, 0d, 0d);
            this.drawScale(dc, divWidth, height);

            colorRGB = this.color.getRGBColorComponents(null);
            gl.glColor4d(colorRGB[0], colorRGB[1], colorRGB[2], this.getOpacity());
            gl.glTranslated(-1d / scale, 1d / scale, 0d);
            this.drawScale(dc, divWidth, height);

            // Draw label
            String label = String.format("%.0f ", divSize) + unitLabel;
            gl.glLoadIdentity();
            gl.glDisable(GL.GL_CULL_FACE);
            drawLabel(
                dc,
                label,
                locationSW.add3(
                    new Vec4(divWidth * scale / 2 + (width - divWidth) / 2, height * scale, 0)));
          } else {
            // Picking
            this.pickSupport.clearPickList();
            this.pickSupport.beginPicking(dc);
            // Draw unique color across the map
            Color color = dc.getUniquePickColor();
            int colorCode = color.getRGB();
            // Add our object(s) to the pickable list
            this.pickSupport.addPickableObject(colorCode, this, referencePosition, false);
            gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
            gl.glTranslated((width - divWidth) / 2, 0d, 0d);
            this.drawRectangle(dc, divWidth, height);
            // Done picking
            this.pickSupport.endPicking(dc);
            this.pickSupport.resolvePick(dc, dc.getPickPoint(), this);
          }
        }
      }
    } finally {
      if (projectionPushed) {
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glPopMatrix();
      }
      if (modelviewPushed) {
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glPopMatrix();
      }
      if (attribsPushed) gl.glPopAttrib();
    }
  }