Exemplo n.º 1
0
  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();
    }
  }
Exemplo n.º 2
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)));
      }
    }
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
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;
    }
  }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
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);
  }
Exemplo n.º 7
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);
  }
Exemplo n.º 8
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;
  }
Exemplo n.º 9
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();
 }
Exemplo n.º 10
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);
  }
Exemplo n.º 11
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);
  }