Esempio n. 1
0
  private void renderBlast(GL2 gl) {
    GLU glu = new GLU();

    Shader shader = Shader.get("dissolve");
    if (shader != null) {
      shader.enable(gl);

      shader.setSampler(gl, "cloudSampler", 0);
      shader.setUniform(gl, "dissolveFactor", 1.0f - ((float) blastDuration / 60.0f));
    }

    gl.glEnable(GL2.GL_TEXTURE_2D);

    GLUquadric sphere = glu.gluNewQuadric();

    glu.gluQuadricDrawStyle(sphere, GLU.GLU_FILL);
    glu.gluQuadricTexture(sphere, true);

    gl.glPushMatrix();
    {
      noiseSampler.bind(gl);
      noiseSampler.setTexParameterf(gl, GL2.GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);

      gl.glTranslatef(bound.c.x, bound.c.y, bound.c.z);

      glu.gluSphere(sphere, blastRadius, 24, 24);
    }
    gl.glPopMatrix();
  }
Esempio n. 2
0
 private void enableStates(final GL2 gl, final boolean enable) {
   if (enable) {
     if (null != tex) {
       tex.bind(gl);
     }
     gl.glEnable(GL.GL_DEPTH_TEST);
     gl.glDepthFunc(GL.GL_LESS); // default
     // gl.glEnable(GL2.GL_TEXTURE_GEN_S);
     // gl.glEnable(GL2.GL_TEXTURE_1D);
     gl.glEnable(GL.GL_TEXTURE_2D);
     gl.glEnable(GL.GL_CULL_FACE);
     gl.glEnable(GLLightingFunc.GL_LIGHTING);
     gl.glEnable(GLLightingFunc.GL_LIGHT0);
     gl.glEnable(GL2.GL_AUTO_NORMAL);
     gl.glEnable(GLLightingFunc.GL_NORMALIZE);
     gl.glFrontFace(GL.GL_CW);
     gl.glCullFace(GL.GL_BACK); // default
     gl.glMaterialf(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, 64.0f);
     gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
   } else {
     if (null != tex) {
       gl.glBindTexture(tex.getTarget(), 0);
     }
     gl.glDisable(GL.GL_DEPTH_TEST);
     // gl.glDisable(GL2.GL_TEXTURE_GEN_S);
     // gl.glDisable(GL2.GL_TEXTURE_1D);
     gl.glDisable(GL.GL_TEXTURE_2D);
     gl.glDisable(GL.GL_CULL_FACE);
     gl.glDisable(GLLightingFunc.GL_LIGHTING);
     gl.glDisable(GLLightingFunc.GL_LIGHT0);
     gl.glDisable(GL2.GL_AUTO_NORMAL);
     gl.glDisable(GLLightingFunc.GL_NORMALIZE);
     gl.glFrontFace(GL.GL_CCW); // default
   }
 }
    /**
     * Update the texture if the native WebView window has changed.
     *
     * @param dc Draw context
     */
    @Override
    protected void updateIfNeeded(DrawContext dc) {
      // Return immediately if the native WebViewWindow object isn't initialized, and wait to update
      // until the
      // native object is initialized. This method is called after the texture is bound, so we'll
      // get another
      // chance to update as long as the WebView generates repaint events when it changes.
      long webViewWindowPtr = WindowsWebView.this.webViewWindowPtr;
      if (webViewWindowPtr == 0) return;

      // Return immediately if the texture isn't in the texture cache, and wait to update until the
      // texture is
      // initialized and placed in the cache. This method is called after the texture is bound, so
      // we'll get
      // another chance to update as long as the WebView generates repaint events when it changes.
      Texture texture = this.getTextureFromCache(dc);
      if (texture == null) return;

      // Load the WebViewWindow's current display pixels into the currently bound OGL texture if our
      // update time
      // is different than the WebViewWindow's update time.
      long newUpdateTime = WindowsWebViewJNI.getUpdateTime(webViewWindowPtr);
      if (newUpdateTime != this.updateTime) {
        WindowsWebViewJNI.loadDisplayInGLTexture(webViewWindowPtr, texture.getTarget());
        this.updateTime = newUpdateTime;
      }
    }
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    // need a valid GL context for this ..

    /** OpenGL .. texture.updateSubImage(textureData, 0, 20, 20, 20, 20, 100, 100); */

    // Now draw one quad with the texture
    if (null != texture) {
      texture.enable();
      texture.bind();
      gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
      TextureCoords coords = texture.getImageTexCoords();
      gl.glBegin(GL2.GL_QUADS);
      gl.glTexCoord2f(coords.left(), coords.bottom());
      gl.glVertex3f(0, 0, 0);
      gl.glTexCoord2f(coords.right(), coords.bottom());
      gl.glVertex3f(1, 0, 0);
      gl.glTexCoord2f(coords.right(), coords.top());
      gl.glVertex3f(1, 1, 0);
      gl.glTexCoord2f(coords.left(), coords.top());
      gl.glVertex3f(0, 1, 0);
      gl.glEnd();
      texture.disable();
    }
  }
  @Override
  public boolean drawImage(
      Image img,
      int dx1,
      int dy1,
      int dx2,
      int dy2,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      Color bgcolor,
      ImageObserver observer) {
    Texture texture = getTexture(img, observer);
    if (texture == null) {
      return false;
    }

    float height = texture.getHeight();
    float width = texture.getWidth();
    begin(texture, null, bgcolor);
    applyTexture(texture, dx1, dy1, dx2, dy2, sx1 / width, sy1 / height, sx2 / width, sy2 / height);
    end(texture);

    return true;
  }
  protected void applyTexture(Texture texture) {
    int width = texture.getWidth();
    int height = texture.getHeight();
    TextureCoords coords = texture.getImageTexCoords();

    applyTexture(
        texture, 0, 0, width, height, coords.left(), coords.top(), coords.right(), coords.bottom());
  }
Esempio n. 7
0
  /**
   * Called back immediately after the OpenGL context is initialized. Can be used to perform
   * one-time initialization. Run only once.
   */
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
    glu = new GLU(); // get GL Utilities
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
    gl.glClearDepth(1.0f); // set clear depth value to farthest
    gl.glEnable(GL_DEPTH_TEST); // enables depth testing
    gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction
    gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting

    // Load the texture image
    try {
      // Create a OpenGL Texture object from (URL, mipmap, file suffix)
      // Use URL so that can read from JAR and disk file.
      texture =
          TextureIO.newTexture(
              this.getClass().getResource(textureFileName), false, textureFileType);
    } catch (GLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Use linear filter for texture if image is larger than the original texture
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // Use linear filter for texture if image is smaller than the original texture
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    // Texture image flips vertically. Shall use TextureCoords class to retrieve
    // the top, bottom, left and right coordinates, instead of using 0.0f and 1.0f.
    TextureCoords textureCoords = texture.getImageTexCoords();
    textureTop = textureCoords.top();
    textureBottom = textureCoords.bottom();
    //      textureLeft = textureCoords.left();
    //      textureRight = textureCoords.right();

    // Enable the texture
    texture.enable(gl);
    // gl.glEnable(GL_TEXTURE_2D);

    // we want back facing polygons to be filled completely and that we want front
    // facing polygons to be outlined only.
    gl.glPolygonMode(GL_BACK, GL_FILL); // Back Face Is Filled In
    gl.glPolygonMode(GL_FRONT, GL_LINE); // Front Face Is Drawn With Lines

    for (int x = 0; x < numPoints; x++) { // Loop Through The Y Plane
      for (int y = 0; y < numPoints; y++) {
        // Apply The Wave To Our Mesh
        // xmax is 45. Get 9 after dividing by 5. Subtract 4.5 to centralize.
        points[x][y][0] = (float) x / 5.0f - 4.5f;
        points[x][y][1] = (float) y / 5.0f - 4.5f;
        // Sine wave pattern
        points[x][y][2] = (float) (Math.sin(Math.toRadians(x / 5.0f * 40.0f)));
      }
    }
  }
 public void dispose(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   if (null != texture) {
     texture.disable();
     texture.destroy(gl);
   }
   if (null != textureData) {
     textureData.destroy();
   }
 }
Esempio n. 9
0
 private Texture loadTexture(GL3 gl, String file) throws GLException, IOException {
   ByteArrayOutputStream os = new ByteArrayOutputStream();
   ImageIO.write(ImageIO.read(new File(file)), "png", os);
   InputStream fis = new ByteArrayInputStream(os.toByteArray());
   Texture newTexture = TextureIO.newTexture(fis, true, TextureIO.PNG);
   newTexture.setTexParameteri(gl, GL3.GL_TEXTURE_WRAP_S, GL3.GL_REPEAT);
   newTexture.setTexParameteri(gl, GL3.GL_TEXTURE_WRAP_T, GL3.GL_REPEAT);
   newTexture.setTexParameteri(gl, GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_LINEAR);
   newTexture.setTexParameteri(gl, GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_LINEAR_MIPMAP_LINEAR);
   System.out.println("Must flip: " + newTexture.getMustFlipVertically());
   return newTexture;
 }
Esempio n. 10
0
  /**
   * Called back immediately after the OpenGL context is initialized. Can be used to perform
   * one-time initialization. Run only once.
   */
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
    glu = new GLU(); // get GL Utilities
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
    gl.glClearDepth(1.0f); // set clear depth value to farthest
    // Do not enable depth test
    //      gl.glEnable(GL_DEPTH_TEST); // enables depth testing
    //      gl.glDepthFunc(GL_LEQUAL);  // the type of depth test to do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction
    gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting

    // Load the texture image
    try {
      // Use URL so that can read from JAR and disk file.
      BufferedImage image = ImageIO.read(this.getClass().getResource(textureFileName));

      // Create a OpenGL Texture object
      texture = AWTTextureIO.newTexture(GLProfile.getDefault(), image, false);
      // Use linear filter if image is larger than the original texture
      gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      // Use linear filter if image is smaller than the original texture
      gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    } catch (GLException | IOException e) {
      e.printStackTrace();
    }

    // Texture image flips vertically. Shall use TextureCoords class to retrieve
    // the top, bottom, left and right coordinates, instead of using 0.0f and 1.0f.
    TextureCoords textureCoords = texture.getImageTexCoords();
    textureCoordTop = textureCoords.top();
    textureCoordBottom = textureCoords.bottom();
    textureCoordLeft = textureCoords.left();
    textureCoordRight = textureCoords.right();

    // Enable the texture
    texture.enable(gl);
    texture.bind(gl);
    // gl.glEnable(GL_TEXTURE_2D);

    // Enable blending
    gl.glEnable(GL_BLEND);
    gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    // Allocate the stars
    for (int i = 0; i < stars.length; i++) {
      stars[i] = new Star();
      // Linearly distributed according to the star number
      stars[i].distance = ((float) i / numStars) * 5.0f;
    }
  }
Esempio n. 11
0
  @Override
  public void dispose(final GLAutoDrawable drawable) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();
    if (null != texture) {
      texture.disable(gl);
      texture.destroy(gl);
    }
    if (null != textureData) {
      textureData.destroy();
    }

    pmvMatrixUniform = null;
    pmvMatrix = null;
    st.destroy(gl);
    st = null;
  }
Esempio n. 12
0
  @Override
  public final void drawTexture(
      final GL gl,
      Texture texture,
      final float x,
      float y,
      float z,
      int texturex,
      int texturey,
      int width,
      int height,
      float scale) {
    Check.notNull(gl, "GL cannot be null");
    Check.notNull(texture, "Texture cannot be null");

    final TextureCoords coords =
        texture.getSubImageTexCoords(texturex, texturey, texturex + width, texturey + height);

    // Compute position and size
    quad.xl = x;
    quad.xr = quad.xl + (scale * width);
    quad.yb = y;
    quad.yt = quad.yb + (scale * height);
    quad.z = z;
    quad.sl = coords.left();
    quad.sr = coords.right();
    quad.tb = coords.bottom();
    quad.tt = coords.top();

    // Draw quad
    pipeline.addQuad(gl, quad);
  }
Esempio n. 13
0
 public void bind(GL3 gl, int textureUnit) {
   if (!isInitialised) {
     logger.error("Attempted to bind an uninitalised Vertex Buffer");
     return;
   }
   gl.glActiveTexture(GL3.GL_TEXTURE0 + textureUnit);
   texture.bind(gl);
 }
Esempio n. 14
0
 public void clean(GL3 gl) {
   if (isWrapSDirty) {
     texture.setTexParameteri(gl, GL3.GL_TEXTURE_WRAP_S, wrapS.glType);
     isWrapSDirty = false;
   }
   if (isWrapTDirty) {
     texture.setTexParameteri(gl, GL3.GL_TEXTURE_WRAP_T, wrapT.glType);
     isWrapTDirty = false;
   }
   if (isMinFilterDirty) {
     texture.setTexParameteri(gl, GL3.GL_TEXTURE_MIN_FILTER, minFilter.glType);
     isMinFilterDirty = false;
   }
   if (isMagFilterDirty) {
     texture.setTexParameteri(gl, GL3.GL_TEXTURE_MAG_FILTER, magFilter.glType);
     isMagFilterDirty = false;
   }
 }
Esempio n. 15
0
  public void initalise(GL3 gl, TextureData td) {
    if (isInitialised) {
      logger.warn(
          "Reinitialised Texture that was already initialsed, This is probably a code error!!");
    }

    texture = new com.jogamp.opengl.util.texture.Texture(gl, td);
    texture.enable(gl);
    isInitialised = true;
  }
Esempio n. 16
0
  @Override
  public void display(final GLAutoDrawable drawable) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    st.useProgram(gl, true);
    interleavedVBO.enableBuffer(gl, true);
    if (!keepTextureBound && null != texture) {
      gl.glActiveTexture(GL.GL_TEXTURE0 + textureUnit);
      texture.enable(gl);
      texture.bind(gl);
    }

    gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);

    if (!keepTextureBound && null != texture) {
      texture.disable(gl);
    }
    interleavedVBO.enableBuffer(gl, false);
    st.useProgram(gl, false);
  }
Esempio n. 17
0
  @Override
  public void draw(GL2 gl, Texture textureCiel) {
    GLU glu = new GLU();
    GLUT glut = new GLUT();

    gl.glEnable(GL_BLEND);
    // gl.glEnable(GL_SMOOTH);
    // gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    gl.glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SMOOTH);
    gl.glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

    //		gl.glEnable(GL_TEXTURE_GEN_S);
    //		gl.glEnable(GL_TEXTURE_GEN_T);
    //		gl.glEnable(GL_TEXTURE_GEN_R);
    //
    //		gl.glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
    //		gl.glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
    //		gl.glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);

    float[] rgba = {1f, 1f, 1f};
    gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT, rgba, 0);
    gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, rgba, 0);
    gl.glMaterialf(GL2.GL_FRONT, GL2.GL_SHININESS, 0.0f);

    textureCiel.enable(gl);
    textureCiel.bind(gl);

    glut.glutSolidSphere(256, 20, 20);

    textureCiel.disable(gl);

    gl.glDisable(GL_TEXTURE_GEN_S);
    gl.glDisable(GL_TEXTURE_GEN_T);
    gl.glDisable(GL_TEXTURE_GEN_R);

    gl.glDisable(GL_BLEND);
  }
Esempio n. 18
0
  @Override
  protected final int getNextTextureImpl(final GL gl, final TextureFrame nextFrame) {
    if (0 == moviePtr) {
      throw new GLException("FFMPEG native instance null");
    }
    int vPTS = TimeFrameI.INVALID_PTS;
    if (null != gl) {
      final Texture tex = nextFrame.getTexture();
      tex.enable(gl);
      tex.bind(gl);
    }

    /** Try decode up to 10 packets to find one containing video. */
    for (int i = 0; TimeFrameI.INVALID_PTS == vPTS && 10 > i; i++) {
      vPTS =
          natives.readNextPacket0(
              moviePtr, getTextureTarget(), getTextureFormat(), getTextureType());
    }
    if (null != nextFrame) {
      nextFrame.setPTS(vPTS);
    }
    return vPTS;
  }
Esempio n. 19
0
 public void renderObj(GL2 gl) {
   gl.glPushMatrix();
   gl.glEnable(GL2.GL_TEXTURE_2D);
   gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
   gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
   texture.enable(gl);
   texture.bind(gl);
   gl.glDisable(GL2.GL_DEPTH_TEST);
   gl.glColor4d(1, 1, 1, transparancy);
   gl.glScalef(canvas.orthoCoordWidth / 2, canvas.orthoCoordWidth / 2 / canvas.aspectRatio, 1);
   gl.glBegin(GL2.GL_QUADS);
   gl.glTexCoord2f(0, 0);
   gl.glVertex2f(-1, -1);
   gl.glTexCoord2f(1, 0);
   gl.glVertex2f(1, -1);
   gl.glTexCoord2f(1, 1);
   gl.glVertex2f(1, 1);
   gl.glTexCoord2f(0, 1);
   gl.glVertex2f(-1, 1);
   gl.glEnd();
   gl.glEnable(GL2.GL_DEPTH_TEST);
   gl.glDisable(GL2.GL_TEXTURE_2D);
   gl.glPopMatrix();
 }
Esempio n. 20
0
  public void initalise(GL3 gl, String textureResource, boolean generateMipmap) {
    loadTextureDataFromResource(textureResource, generateMipmap);
    if (texture == null) {
      logger.error("Failed to load texure " + textureResource);
      return;
    }

    if (isInitialised) {
      logger.warn(
          "Reinitialised Texture that was already initialsed, This is probably a code error!!");
    }

    texture.enable(gl);
    isInitialised = true;
  }
Esempio n. 21
0
  /**
   * @param buffer
   * @param tile
   * @param pool
   * @return
   */
  private Tile createTile(
      FloatBuffer buffer,
      Rectangle tile,
      GL gl,
      Deque<Texture> pool,
      TablePerspective tablePerspective) {
    final VirtualArray recordVA = tablePerspective.getRecordPerspective().getVirtualArray();
    final VirtualArray dimVA = tablePerspective.getDimensionPerspective().getVirtualArray();
    final ATableBasedDataDomain dataDomain = tablePerspective.getDataDomain();
    final int ilast = tile.y + tile.height;
    final int jlast = tile.x + tile.width;

    // fill buffer
    buffer.rewind();
    for (int i = tile.y; i < ilast; ++i) {
      int recordID = recordVA.get(i);
      for (int j = tile.x; j < jlast; ++j) {
        int dimensionID = dimVA.get(j);
        Color color = blockColorer.apply(recordID, dimensionID, dataDomain, false);
        buffer.put(color.getRGBA());
      }
    }

    // load to texture
    buffer.rewind();
    Texture texture;
    if (!pool.isEmpty()) texture = pool.poll();
    else texture = TextureIO.newTexture(GL.GL_TEXTURE_2D);

    TextureData texData = asTextureData(buffer, tile.width, tile.height);
    texture.updateImage(gl, texData);
    gl.glFlush();
    texData.destroy();

    return new Tile(tile, texture);
  }
Esempio n. 22
0
    public void render(GLGraphics g) {

      texture.bind(g.gl);
      final int clamp =
          (g.gl.isExtensionAvailable(GLExtensions.VERSION_1_2) || !g.gl.isGL2())
              ? GL.GL_CLAMP_TO_EDGE
              : GL2.GL_CLAMP;
      g.gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, clamp);
      g.gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, clamp);

      g.gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
      g.gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);

      // flipped in y-direction
      g.fillImage(texture, tile.x, tile.y + tile.height, tile.width, -tile.height);
    }
Esempio n. 23
0
 /**
  * Bind the texture for use, must be loaded first
  *
  * @param file file that should be bound
  */
 public void bindTexture(GL2 gl, String file) {
   Texture t = textures.get(file);
   if (t != null) t.bind(gl);
 }
Esempio n. 24
0
  public void draw(GL2 gl, GLU glu, GLDrawState ds) {
    final Color4f highColor = new Color4f(0.0f, 1.0f, 0.0f, 1.0f);
    final Color4f lowColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);

    Color4f[][] trueCols = new Color4f[mapHeight][mapWidth];
    //		InternalTerrainTile tiles[][] = ds.getGameMap().getTerrainMatrix();
    // Update colors

    for (int j = 0; j < mapHeight; j++) {
      for (int i = 0; i < mapWidth; i++) {

        // float fluxAmount = getMapHeight(i, j)/64.f;
        //	System.out.println(flux[j/DENSITY][i/DENSITY] + " " + fluxAmount);

        // float fluxAmount = (float)tiles[i/DENSITY][j/DENSITY].getFlux();

        Color4f tintColor = new Color4f();
        Color4f trueColor = new Color4f();

        tintColor.interpolate(lowColor, highColor, 0);
        // System.out.println(actualHeight/maxHeight);

        trueColor.interpolate(cols[j][i], tintColor, 1.0f);
        trueColor.w = cols[j][i].w;
        trueCols[j][i] = trueColor;

        // If void, see through to the background.
        /*if(tiles[i/DENSITY][j/DENSITY] == TerrainType.VOID){
        trueCols[j][i].w = 0.0f;
        }*/

      }
    }
    // System.out.println(map.getTerrainMatrix()[0][0].getFlux() + " " + MAX_FLUX_PER_TILE + " " +
    // trueCols[0][0].x);

    int k = 0;
    for (int j = 0; j < mapHeight; j++) {
      for (int i = 0; i < mapWidth; i++) {
        colors[k] = trueCols[j][i].x;
        colors[k + 1] = trueCols[j][i].y;
        colors[k + 2] = trueCols[j][i].z;
        colors[k + 3] = trueCols[j][i].w;

        float norm =
            (float)
                Math.sqrt(
                    trueCols[j][i].x * trueCols[j][i].x
                        + trueCols[j][i].y * trueCols[j][i].y
                        + trueCols[j][i].z * trueCols[j][i].z);
        float val = (norm < 0.3f) ? 0.0f : 0.9f;
        colorNorm[k] = val;
        colorNorm[k + 1] = val;
        colorNorm[k + 2] = val;
        colorNorm[k + 3] = 1.0f;
        k += 4;
      }
    }

    if (tex == null && texturePath != null) {
      tex = GLGameRenderer.textureCache.getResource(texturePath, texturePath).tex;
      texturePath = null;
    }
    gl.glPushMatrix();
    //	gl.glTranslatef(1.5f, 0.0f, 1.5f);
    if (tex != null) {
      System.out.println("Using texture");
      gl.glEnable(GL2.GL_TEXTURE_2D);
      tex.bind(gl);
      gl.glBegin(GL2.GL_TRIANGLE_STRIP);
      for (int i = 0; i < indices.length; i++) {
        gl.glTexCoord2f(texCoords[indices[i] * 2], texCoords[indices[i] * 2 + 1]);
        gl.glColor4f(
            colorNorm[indices[i] * 4],
            colorNorm[indices[i] * 4 + 1],
            colorNorm[indices[i] * 4 + 2],
            colorNorm[indices[i] * 4 + 3]);
        gl.glNormal3f(
            normals[indices[i] * 3], normals[indices[i] * 3 + 1], normals[indices[i] * 3 + 2]);
        gl.glVertex3f(
            vertices[indices[i] * 3], vertices[indices[i] * 3 + 1], vertices[indices[i] * 3 + 2]);
      }
      gl.glEnd();
    } else {
      gl.glEnable(gl.GL_BLEND);
      gl.glBegin(GL2.GL_TRIANGLE_STRIP);
      for (int i = 0; i < indices.length; i++) {
        gl.glColor4f(
            colors[indices[i] * 4],
            colors[indices[i] * 4 + 1],
            colors[indices[i] * 4 + 2],
            colors[indices[i] * 4 + 3]);
        gl.glNormal3f(
            normals[indices[i] * 3], normals[indices[i] * 3 + 1], normals[indices[i] * 3 + 2]);
        gl.glVertex3f(
            vertices[indices[i] * 3], vertices[indices[i] * 3 + 1], vertices[indices[i] * 3 + 2]);
      }
      gl.glEnd();
      gl.glDisable(gl.GL_BLEND);
    }
    gl.glPopMatrix();

    boolean showGrid = RenderConfiguration.showGridlines();
    if (showGrid) {
      gl.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
      gl.glNormal3f(0.0f, 1.0f, 0.0f);
      gl.glLineWidth(1.0f);

      // do the horizontal gridlines
      /*
      gl.glBegin(GL2.GL_LINES);
      for (int j = 1; j < map.getHeight(); ++j) {
      	gl.glVertex3f(0.0f, 0.0f, j);
      	gl.glVertex3f(map.getWidth(), 0.0f, j);
      }
      gl.glEnd();
      */
      gl.glBegin(GL2.GL_LINE_STRIP);
      for (int j = 0; j < mapHeight; j++) {
        if ((j + 1) % DENSITY != 0) {
          continue;
        }
        if ((j + 1) % (DENSITY * 2) == 0) {
          for (int i = 0; i < mapWidth; i++) {
            Vector3f p;
            Vector3f pOne;
            Vector3f pTwo;

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j < mapHeight - 1 && i > 0) {
              pTwo = points[j + 1][i - 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j < mapHeight - 1) {
              pTwo = points[j + 1][i];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
          }
        } else {
          for (int i = mapWidth - 1; i >= 0; i--) {
            Vector3f p;
            Vector3f pOne;
            Vector3f pTwo;

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j < mapHeight - 1) {
              pTwo = points[j + 1][i];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j < mapHeight - 1 && i > 0) {

              pTwo = points[j + 1][i - 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
          }
        }
      }
      gl.glEnd();

      // do the vertical gridlines
      /*
      gl.glBegin(GL2.GL_LINES);
      for (int j = 1; j < map.getWidth(); ++j) {
      	gl.glVertex3f(j, 0.0f, 0.0f);
      	gl.glVertex3f(j, 0.0f, map.getHeight());
      }
      gl.glEnd();
      */
      gl.glBegin(GL2.GL_LINE_STRIP);
      for (int i = 0; i < mapWidth; i++) {
        if ((i + 1) % DENSITY != 0) {
          continue;
        }
        if ((i + 1) % (DENSITY * 2) == 0) {
          for (int j = 0; j < mapHeight; j++) {
            Vector3f p;
            Vector3f pOne;
            Vector3f pTwo;

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j > 0 && i < mapWidth - 1) {
              pTwo = points[j - 1][i + 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (i < mapWidth - 1) {
              pTwo = points[j][i + 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
          }
        } else {
          for (int j = mapHeight - 1; j >= 0; j--) {
            Vector3f p;
            Vector3f pOne;
            Vector3f pTwo;

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (i < mapWidth - 1) {
              pTwo = points[j][i + 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j > 0 && i < mapWidth - 1) {
              pTwo = points[j - 1][i + 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
          }
        }
      }
      gl.glEnd();
    }
  }
Esempio n. 25
0
  /** @param context */
  public void create(IGLElementContext context, TablePerspective tablePerspective) {
    final GL gl = GLContext.getCurrentGL();

    final int numberOfRecords = tablePerspective.getRecordPerspective().getVirtualArray().size();
    final int numberOfDimensions =
        tablePerspective.getDimensionPerspective().getVirtualArray().size();
    dimension = new Dimension(numberOfDimensions, numberOfRecords);

    if (numberOfDimensions <= 0 || numberOfRecords <= 0) {
      takeDown();
      return;
    }

    final int maxSize = resolveMaxSize(gl);

    boolean needXTiling = numberOfDimensions > maxSize;
    boolean needYTiling = numberOfRecords > maxSize;

    // pool of old texture which we might wanna reuse
    final Deque<Texture> pool = new LinkedList<>();
    for (Tile tile : tiles) {
      pool.add(tile.texture);
    }
    tiles.clear();

    if (!needXTiling && !needYTiling) {
      // single tile
      FloatBuffer buffer =
          FloatBuffer.allocate(numberOfDimensions * numberOfRecords * 4); // w*h*rgba
      Rectangle tile = new Rectangle(0, 0, numberOfDimensions, numberOfRecords);
      tiles.add(createTile(buffer, tile, gl, pool, tablePerspective));
    } else if (needXTiling && !needYTiling) {
      // tile in x direction only
      FloatBuffer buffer = FloatBuffer.allocate(maxSize * numberOfRecords * 4); // w*h*rgba
      // fill full
      int lastTile = numberOfDimensions - maxSize;
      for (int i = 0; i < lastTile; i += maxSize) {
        Rectangle tile = new Rectangle(i, 0, maxSize, numberOfRecords);
        tiles.add(createTile(buffer, tile, gl, pool, tablePerspective));
      }
      { // create rest
        int remaining = numberOfDimensions % maxSize;
        Rectangle tile =
            new Rectangle(numberOfDimensions - remaining, 0, remaining, numberOfRecords);
        tiles.add(createTile(buffer, tile, gl, pool, tablePerspective));
      }
    } else if (!needXTiling && needYTiling) {
      // tile in y direction only
      FloatBuffer buffer = FloatBuffer.allocate(numberOfDimensions * maxSize * 4); // w*h*rgba
      // fill full
      int lastTile = numberOfRecords - maxSize;
      for (int i = 0; i < lastTile; i += maxSize) {
        Rectangle tile = new Rectangle(0, i, numberOfDimensions, maxSize);
        tiles.add(createTile(buffer, tile, gl, pool, tablePerspective));
      }
      { // create rest
        int remaining = numberOfRecords % maxSize;
        Rectangle tile =
            new Rectangle(0, numberOfRecords - remaining, numberOfDimensions, remaining);
        tiles.add(createTile(buffer, tile, gl, pool, tablePerspective));
      }
    } else {
      // tile in both directions
      // tile in y direction only
      FloatBuffer buffer = FloatBuffer.allocate(maxSize * maxSize * 4); // w*h*rgba
      // fill full
      int lastTileR = numberOfRecords - maxSize;
      int lastTileD = numberOfDimensions - maxSize;
      for (int i = 0; i < lastTileR; i += maxSize) {
        for (int j = 0; j < lastTileD; j += maxSize) {
          Rectangle tile = new Rectangle(j, i, maxSize, maxSize);
          tiles.add(createTile(buffer, tile, gl, pool, tablePerspective));
        }
        { // create rest
          int remaining = numberOfDimensions % maxSize;
          Rectangle tile = new Rectangle(numberOfDimensions - remaining, i, remaining, maxSize);
          tiles.add(createTile(buffer, tile, gl, pool, tablePerspective));
        }
      }
      { // last line
        int iremaining = numberOfRecords % maxSize;
        int i = numberOfRecords - iremaining;
        for (int j = 0; j < lastTileD; j += maxSize) {
          Rectangle tile = new Rectangle(j, i, maxSize, iremaining);
          tiles.add(createTile(buffer, tile, gl, pool, tablePerspective));
        }
        { // create rest
          int remaining = numberOfDimensions % maxSize;
          Rectangle tile = new Rectangle(numberOfDimensions - remaining, i, remaining, iremaining);
          tiles.add(createTile(buffer, tile, gl, pool, tablePerspective));
        }
      }
    }

    // free remaining elements in pool
    for (Texture tex : pool) tex.destroy(gl);
    pool.clear();
  }
Esempio n. 26
0
  @Override
  public void init(final GLAutoDrawable glad) {
    if (null != textureData) {
      texture = TextureIO.newTexture(glad.getGL(), textureData);
    }
    final GL2ES2 gl = glad.getGL().getGL2ES2();

    initShader(gl, true);

    // setup mgl_PMVMatrix
    pmvMatrix = new PMVMatrix();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrixUniform =
        new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv

    st.ownUniform(pmvMatrixUniform);
    if (!st.uniform(gl, pmvMatrixUniform)) {
      throw new GLException("Error setting PMVMatrix in shader: " + st);
    }
    if (!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", textureUnit))) {
      throw new GLException("Error setting mgl_ActiveTexture in shader: " + st);
    }

    if (null != texture) {
      // fetch the flipped texture coordinates
      texture.getImageTexCoords().getST_LB_RB_LT_RT(s_quadTexCoords, 0, 1f, 1f);
    }

    interleavedVBO =
        GLArrayDataServer.createGLSLInterleaved(
            3 + 4 + 2, GL.GL_FLOAT, false, 3 * 4, GL.GL_STATIC_DRAW);
    {
      interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER);
      interleavedVBO.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER);
      // interleavedVBO.addGLSLSubArray("mgl_Normal",        3, GL.GL_ARRAY_BUFFER);
      interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER);

      final FloatBuffer ib = (FloatBuffer) interleavedVBO.getBuffer();

      for (int i = 0; i < 4; i++) {
        ib.put(s_quadVertices, i * 3, 3);
        ib.put(s_quadColors, i * 4, 4);
        // ib.put(s_cubeNormals,   i*3, 3);
        ib.put(s_quadTexCoords, i * 2, 2);
      }
    }
    interleavedVBO.seal(gl, true);
    interleavedVBO.enableBuffer(gl, false);
    st.ownAttribute(interleavedVBO, true);

    // OpenGL Render Settings
    gl.glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
    gl.glEnable(GL.GL_DEPTH_TEST);

    if (keepTextureBound && null != texture) {
      gl.glActiveTexture(GL.GL_TEXTURE0 + textureUnit);
      texture.enable(gl);
      texture.bind(gl);
    }
    st.useProgram(gl, false);
  }
Esempio n. 27
0
 protected void destroy(Texture texture) {
   texture.destroy(g2d.getGLContext().getGL());
 }
Esempio n. 28
0
  public void draw(GL2 gl, Camera camera, Perspective3D perspective3d) {
    Photo photo = this.photo;

    gl.glDisable(GL2.GL_DEPTH_TEST);
    gl.glColor4f(
        (float) 255 / 255, (float) 255 / 255, (float) 255 / 255, (float) photo.getTransparent());

    // Enable Alpha Blending (disable alpha testing)
    gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
    gl.glEnable(GL2.GL_BLEND);

    gl.glDisable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_TEXTURE_2D);

    // XXX
    String textureName = photo.getPath();

    TextureCoords tc = new TextureCoords(0, 0, 1, 1);
    if (textureName != null) {
      Texture texture = this.textureCacheService.getTexture(gl, textureName);

      //            // switch to texture mode and push a new matrix on the stack
      //            gl.glMatrixMode(GL2.GL_TEXTURE);
      //            gl.glPushMatrix();
      //
      //            // check to see if the texture needs flipping
      //            if (texture.getMustFlipVertically()) {
      //                gl.glScaled(1, -1, 1);
      //                gl.glTranslated(0, -1, 0);
      //            }
      //
      //            // switch to modelview matrix and push a new matrix on the stack
      //            gl.glMatrixMode(GL2.GL_MODELVIEW);
      //            gl.glPushMatrix();
      //
      //            // This is required to repeat textures
      //            gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
      //            gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);

      // enable, bind
      texture.enable(gl);
      texture.bind(gl);

      tc = texture.getImageTexCoords();
    }

    gl.glBegin(GL2.GL_POLYGON);
    //        gl.glColor3f((float)123/256, (float)111/256, (float)100/255);
    //        gl.glColor3f((float) 255/255, (float)255/255, (float)255/255);

    LatLon ll = new LatLon(photo.getLat(), photo.getLon());

    Projection proj = Main.getProjection();

    EastNorth eastNorth = proj.latlon2eastNorth(ll);

    double x = perspective3d.calcX(eastNorth.east());
    double y = photo.getHeight();
    double z = -perspective3d.calcY(eastNorth.north());

    Vector3d angle = photo.getRotate();

    double distance = 500d;

    double width = distance * Math.sin(photo.getAngleWitht() / 2d);
    double height = distance * Math.sin(photo.getAngleHeigth() / 2d);

    Vector3d p1 = new Vector3d(distance, -height, -width);
    Vector3d p2 = new Vector3d(distance, -height, width);
    Vector3d p3 = new Vector3d(distance, height, width);
    Vector3d p4 = new Vector3d(distance, height, -width);

    p1 = transform(angle, p1);
    p2 = transform(angle, p2);
    p3 = transform(angle, p3);
    p4 = transform(angle, p4);

    Point3d c = camera.getPoint();

    // gl.glColor4f((float) 255/255, (float)255/255, (float)255/255, (float) 128/255);
    gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_BLEND);

    gl.glTexCoord2d(tc.left(), tc.bottom());
    gl.glVertex3d(p1.x + x, p1.y + y, p1.z + z);
    gl.glTexCoord2d(tc.right(), tc.bottom());
    gl.glVertex3d(p2.x + x, p2.y + y, p2.z + z);
    gl.glTexCoord2d(tc.right(), tc.top());
    gl.glVertex3d(p3.x + x, p3.y + y, p3.z + z);
    gl.glTexCoord2d(tc.left(), tc.top());
    gl.glVertex3d(p4.x + x, p4.y + y, p4.z + z);

    gl.glEnd();

    gl.glColor3f((float) 0 / 255, (float) 0 / 255, (float) 255 / 255);

    gl.glPushMatrix();

    gl.glTranslated(x, 0.1, z);

    gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE);

    DrawUtil.drawDotY(gl, 0.5, 12);
    gl.glPopMatrix();

    if (textureName != null) {
      Texture texture = this.textureCacheService.getTexture(gl, textureName);

      Texture t = this.textureCacheService.getTexture(gl, textureName);
      // this.textures.get(mesh.materialID);// .get(mesh.materialID);
      if (t != null) {
        t.disable(gl);
      }

      gl.glMatrixMode(GL2.GL_TEXTURE);
      gl.glPopMatrix();

      gl.glMatrixMode(GL2.GL_MODELVIEW);
      gl.glPopMatrix();
    }

    gl.glDisable(GL2.GL_TEXTURE_2D);

    gl.glColor4f((float) 255 / 255, (float) 255 / 255, (float) 255 / 255, (float) 255 / 255);

    gl.glDisable(GL2.GL_BLEND);
    gl.glEnable(GL2.GL_DEPTH_TEST);
  }
Esempio n. 29
0
 public int getGLHandle(GL3 gl) {
   return texture.getTextureObject(gl);
 }
Esempio n. 30
0
 public void destroy(GL3 gl) {
   if (isInitialised) {
     texture.destroy(gl);
     isInitialised = false;
   }
 }