Exemple #1
0
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    glut = new GLUT();
    //
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    makeStripeImage();

    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);

    gl.glGenTextures(1, texName, 0);
    gl.glBindTexture(GL2.GL_TEXTURE_1D, texName[0]);

    gl.glTexParameterf(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
    gl.glTexParameterf(
        GL2.GL_TEXTURE_1D, //
        GL2.GL_TEXTURE_MAG_FILTER,
        GL.GL_LINEAR);
    gl.glTexParameterf(
        GL2.GL_TEXTURE_1D, //
        GL2.GL_TEXTURE_MIN_FILTER,
        GL.GL_LINEAR);
    gl.glTexImage1D(
        GL2.GL_TEXTURE_1D,
        0,
        GL2.GL_RGBA,
        stripeImageWidth, //
        0,
        GL2.GL_RGB,
        GL.GL_UNSIGNED_BYTE,
        stripeImageBuf);

    gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE);
    currentCoeff = xequalzero;
    currentGenMode = GL2.GL_OBJECT_LINEAR;
    currentPlane = GL2.GL_OBJECT_PLANE;
    gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR);
    gl.glTexGendv(GL2.GL_S, GL2.GL_OBJECT_PLANE, currentCoeff, 0);

    // gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthFunc(GL.GL_LESS);
    gl.glEnable(GL2.GL_TEXTURE_GEN_S);
    gl.glEnable(GL2.GL_TEXTURE_1D);
    gl.glEnable(GL.GL_CULL_FACE);
    gl.glEnable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glEnable(GL2.GL_AUTO_NORMAL);
    gl.glEnable(GL2.GL_NORMALIZE);
    gl.glFrontFace(GL.GL_CW);
    gl.glCullFace(GL.GL_BACK);
    gl.glMaterialf(GL.GL_FRONT, GL2.GL_SHININESS, 64.0f);
  }
Exemple #2
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();
 }
  public boolean generateFBO(GL2 gl) {
    if (fboWidth < 0 || fboHeight < 0) {
      fboWidth = inputTexture.getWidth();
      fboHeight = inputTexture.getHeight();
    }

    System.err.println("(********* in generateFBO...");
    boolean fboUsed;

    this.texture1 = TextureIO.newTexture(GL_TEXTURE_2D);
    this.texture1.bind();

    gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    // gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    // gl.glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap
    // gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    // gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    gl.glTexImage2D(
        GL_TEXTURE_2D, 0, GL_RGBA, fboWidth, fboHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
    // gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fboWidth, fboHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
    // null);
    gl.glBindTexture(GL_TEXTURE_2D, 0);

    this.texture2 = TextureIO.newTexture(GL_TEXTURE_2D);
    this.texture2.bind();

    gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    // gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    // gl.glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap
    // gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    // gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    gl.glTexImage2D(
        GL_TEXTURE_2D, 0, GL_RGBA, fboWidth, fboHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
    // gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fboWidth, fboHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
    // null);
    gl.glBindTexture(GL_TEXTURE_2D, 0);

    // create a renderbuffer object to store depth info
    //    int[] rboBindId = new int[1];
    //    gl.glGenRenderbuffersEXT(1, rboBindId, 0);
    //    this.rboId = rboBindId[0];
    //    gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, this.rboId);
    //    gl.glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, fboWidth, fboHeight);
    //    gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

    // create a framebuffer object and attach the color texture and depth renderbuffer
    int[] fboBindId = new int[1];
    gl.glGenFramebuffers(1, fboBindId, 0);
    this.fboId = fboBindId[0];

    gl.glBindFramebuffer(GL_FRAMEBUFFER, this.fboId);

    int textureLevel = 0; // not using mipmaps so only first level is available
    // attach the texture to FBO color attachment point
    gl.glFramebufferTexture2D(
        GL_FRAMEBUFFER,
        GL_COLOR_ATTACHMENT0,
        GL_TEXTURE_2D,
        this.texture1.getTextureObject(),
        textureLevel);
    // attach the renderbuffer to depth attachment point
    // gl.glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
    // GL_RENDERBUFFER_EXT, this.rboId);

    // attach the texture to FBO color attachment point
    gl.glFramebufferTexture2D(
        GL_FRAMEBUFFER,
        GL_COLOR_ATTACHMENT1,
        GL_TEXTURE_2D,
        this.texture2.getTextureObject(),
        textureLevel);
    // attach the renderbuffer to depth attachment point
    // gl.glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
    // GL_RENDERBUFFER_EXT, this.rboId);

    // check FBO status
    int status = gl.glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (status != GL_FRAMEBUFFER_COMPLETE) {
      fboUsed = false;
      System.out.println("GL_FRAMEBUFFER_COMPLETE_EXT failed, CANNOT use FBO\n");
    } else {
      fboUsed = true;
      System.out.printf("GL_FRAMEBUFFER_COMPLETE_EXT OK, using FBO\n");
      System.out.printf("fbo offScreenWidth =%d\n", fboWidth);
      System.out.printf("fbo offScreenHeight =%d\n", fboHeight);
      System.out.printf("fbo texture1 id=%d\n", this.texture1.getTextureObject());
      System.out.printf("fbo texture2 id=%d\n", this.texture2.getTextureObject());
      System.out.printf("fbo id=%d\n", fboId);
      System.out.printf("fbo's rbo id=%d\n", rboId);
    }

    // switch back to window-system-provided framebuffer
    gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);

    return fboUsed;
  }