コード例 #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
ファイル: GLState.java プロジェクト: kaosbeat/grid-goggles
  public void copyTex(GLTexture srcTex, GLTexture destTex) {
    float uscale = srcTex.getMaxTextureCoordS();
    float vscale = srcTex.getMaxTextureCoordT();

    float cx = 0.0f;
    float sx = +1.0f;
    if (destTex.isFlippedX()) {
      cx = 1.0f;
      sx = -1.0f;
    }

    float cy = 0.0f;
    float sy = +1.0f;
    if (destTex.isFlippedY()) {
      cy = 1.0f;
      sy = -1.0f;
    }

    gl.glEnable(srcTex.getTextureTarget());

    gl.glActiveTexture(GL.GL_TEXTURE0);
    gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID());

    pushFramebuffer();
    setFramebuffer(FBO);
    FBO.setDrawBuffer(destTex.getTextureTarget(), destTex.getTextureID());

    saveView();
    setOrthographicView(destTex.width, destTex.height);
    gl.glEnable(srcTex.getTextureTarget());
    gl.glActiveTexture(GL.GL_TEXTURE0);
    gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID());
    gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glBegin(GL.GL_QUADS);
    gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 0.0f) * vscale);
    gl.glVertex2f(0.0f, 0.0f);

    gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 0.0f) * vscale);
    gl.glVertex2f(srcTex.width, 0.0f);

    gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 1.0f) * vscale);
    gl.glVertex2f(srcTex.width, srcTex.height);

    gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 1.0f) * vscale);
    gl.glVertex2f(0.0f, srcTex.height);
    gl.glEnd();
    gl.glBindTexture(srcTex.getTextureTarget(), 0);
    restoreView();

    popFramebuffer();
  }
コード例 #3
0
ファイル: Button.java プロジェクト: psikosen/javapop
  public void display(GL gl, float time, int screenWidth, int screenHeight) {
    // TODO: most of this only needs to be done once per frame, not per button.
    if (!visible) {
      return;
    }
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    if (flipx) {
      gl.glTranslatef(1.0f, 0.0f, 0.0f);
      gl.glScalef(-1.0f, 1.0f, 1.0f);
    }
    if (flipy) {
      gl.glTranslatef(0.0f, 1.0f, 0.0f);
      gl.glScalef(1.0f, -1.0f, 1.0f);
    }
    gl.glScalef(1.0f / screenWidth, 1.0f / screenHeight, 1.0f);
    if (isSelected() || (mDown && mOver)) {
      gl.glColor3f(0.6f, 0.6f, 0.8f);
    } else {
      gl.glColor3f(0.8f, 0.8f, 0.8f);
    }
    gl.glActiveTexture(GL.GL_TEXTURE0);
    marble.enable();
    marble.bind();
    gl.glMatrixMode(GL.GL_TEXTURE);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glBegin(GL.GL_POLYGON);

    for (int n = 0; n < buttonShape.npoints; n++) {
      gl.glTexCoord2f(n / 2, (n + n / 2 + 1) % 2);
      gl.glVertex3f(buttonShape.xpoints[n], buttonShape.ypoints[n], -0.5f);
    }
    gl.glEnd();

    tex.enable();
    tex.bind();
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    gl.glBegin(GL.GL_POLYGON);

    for (int n = 0; n < buttonShape.npoints; n++) {
      gl.glTexCoord2f(n / 2, (n + n / 2 + 1) % 2);
      gl.glVertex3f(buttonShape.xpoints[n], buttonShape.ypoints[n], -1.0f);
    }
    gl.glEnd();
    gl.glPopMatrix();

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopMatrix();
  }
コード例 #4
0
  private void display(GL gl, GLU glu, final JoglFrameBufferObject theFBO) {
    final int w = theFBO.getPixelWidth();
    final int h = theFBO.getPixelHeight();

    /* bind position data */
    gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, _myVBO);
    gl.glVertexPointer(4, GL.GL_FLOAT, 0, 0);

    /* bind point size data */
    _myShaderManager.enable(_myPointSpriteShader);
    final int myPointSizeAttrib =
        gl.glGetAttribLocation(_myPointSpriteShader.getOpenGLID(), "vertexAttribute");
    gl.glEnableVertexAttribArray(myPointSizeAttrib);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, _myIBO);
    gl.glVertexAttribPointer(myPointSizeAttrib, 3, GL.GL_FLOAT, false, 0, 0);
    gl.glEnable(GL.GL_VERTEX_PROGRAM_POINT_SIZE_ARB);

    /* --- */
    final JoglFrameBufferObject READ_FBO = _myFBO;
    _myShaderManager.setUniform(
        _myPointSpriteShader,
        "textureVelocity",
        READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureUnit() - GL.GL_TEXTURE0);
    _myShaderManager.setUniform(_myPointSpriteShader, "velocityThreshold", velocity_threshold);
    _myShaderManager.setUniform(_myPointSpriteShader, "sizeThreshold", size_threshold);
    _myShaderManager.setUniform(_myPointSpriteShader, "pointSize", point_size);
    _myShaderManager.setUniform(_myPointSpriteShader, "flowdirection", flow_direction);
    _myShaderManager.setUniform(_myPointSpriteShader, "collisionratio", collision_ratio);

    gl.glActiveTexture(READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureUnit());
    gl.glBindTexture(
        READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureTarget(),
        READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureID());

    JoglUtil.printGLError(gl, glu, "binding texture", true);

    gl.glDrawArrays(GL.GL_POINTS, 0, w * h);

    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
    gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
    gl.glDisableVertexAttribArray(myPointSizeAttrib);
    _myShaderManager.disable();
    gl.glDisable(GL.GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
    gl.glBindTexture(READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureTarget(), 0);

    JoglUtil.printGLError(gl, glu, "display()", true);
  }
コード例 #5
0
ファイル: FFMPEGMediaPlayer.java プロジェクト: Karlqu/jogl
 @Override
 protected void preNextTextureImpl(final GL gl) {
   psm.setUnpackAlignment(gl, 1); // RGBA ? 4 : 1
   gl.glActiveTexture(GL.GL_TEXTURE0 + getTextureUnit());
 }