コード例 #1
0
ファイル: Tile3D.java プロジェクト: route-a-lot/route-a-lot
  /**
   * Renders the tile to the given context, in the process building all needed resources.
   *
   * @param gl
   */
  public void render(GL gl) {
    projection = ProjectionFactory.getCurrentProjection();
    heightmap = State.getInstance().getLoadedHeightmap();

    // BUILD TEXTURES IF NECESSARY
    if (!gl.glIsTexture(textureID)) {
      textureID = createTexture(gl, getImage(), false);
      // prerenderToTexture(gl);
    }
    if (!gl.glIsTexture(grainTextureID)) {
      createGrainTexture(gl);
    }
    // RENDER TILE FROM DISPLAY LIST, OR ELSE BUILD DISPLAY LIST
    if (gl.glIsList(displaylistID)) {
      gl.glCallList(displaylistID);
    } else {
      displaylistID = gl.glGenLists(1);
      gl.glNewList(displaylistID, GL_COMPILE_AND_EXECUTE);
      gl.glActiveTexture(GL_TEXTURE0);
      gl.glEnable(GL_TEXTURE_2D);
      gl.glBindTexture(GL_TEXTURE_2D, grainTextureID);
      gl.glActiveTexture(GL_TEXTURE1);
      gl.glEnable(GL_TEXTURE_2D);
      gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
      gl.glBindTexture(GL_TEXTURE_2D, textureID);

      gl.glColor3f(1, 1, 1);
      float[] color = new float[3];
      float hRes = HEIGHT_RESOLUTION - 1;
      float stepSize = bounds.getWidth() / hRes;
      Coordinates pos = new Coordinates();
      for (int x = 0; x < hRes; x++) {
        gl.glBegin(GL_TRIANGLE_STRIP);
        for (int y = 0; y <= hRes; y++) {
          for (int i = 0; i < 2; i++) {
            pos.setLatitude(bounds.getTop() + y * stepSize);
            pos.setLongitude(bounds.getLeft() + (x + i) * stepSize);
            gl.glMultiTexCoord2f(
                GL_TEXTURE0, (x + i) / (float) GRAIN_RESOLUTION, y / (float) GRAIN_RESOLUTION);
            gl.glMultiTexCoord2f(GL_TEXTURE1, (x + i) / hRes, y / hRes);
            float height = heights[x + HEIGHT_BORDER + i][y + HEIGHT_BORDER];
            getHeightColor(color, height);
            float shade = getShade(x + i, y, stepSize);
            gl.glColor3f(color[0] * shade, color[1] * shade, color[2] * shade);
            gl.glVertex3f(pos.getLongitude(), pos.getLatitude(), height);
          }
        }
        gl.glEnd();
      }
      gl.glDisable(GL_TEXTURE_2D);
      gl.glActiveTexture(GL_TEXTURE0);
      renderPOIs(gl);
      gl.glEndList();
    }
  }
コード例 #2
0
ファイル: Tile3D.java プロジェクト: route-a-lot/route-a-lot
 @Override
 public void prerender() {
   super.prerender();
   projection = ProjectionFactory.getCurrentProjection();
   Bounds geoBounds =
       new Bounds(
           projection.getGeoCoordinates(bounds.getTopLeft()),
           projection.getGeoCoordinates(bounds.getBottomRight()),
           true);
   State.getInstance().getLoadedHeightmap().reduceSection(geoBounds, getHeights(), HEIGHT_BORDER);
   minHeight = heights[0][0];
   maxHeight = heights[0][0];
   for (int x = 0; x < heights.length; x++) {
     for (int y = 0; y < heights[x].length; y++) {
       if (heights[x][y] < minHeight) {
         minHeight = heights[x][y];
       }
       if (heights[x][y] > maxHeight) {
         maxHeight = heights[x][y];
       }
     }
   }
 }