/**
   * Puts the input texture through the Program chain, returning the processed output Texture which
   * can then be placed on a Geom, etc.
   *
   * @param gl
   * @return A Texture that's been processed by the attached shader Programs
   */
  public Texture apply() {
    GL2 gl = getGL();
    // sanity check
    if (programs.size() == 0) {
      return inputTexture;
    }

    // if first time, generate FBO
    if (fboId < 0) {
      System.out.println("GENERATE...");
      if (!generateFBO(gl)) {
        System.err.println("couldn't generate FBO!");
        return null;
      }
    }

    // if first time, install shaders
    for (Program program : this.programs) {
      if (program.programId <= 0) {
        program.install();
      }
    }

    writeAttachment = GL_COLOR_ATTACHMENT0;
    readAttachment = GL_COLOR_ATTACHMENT1;

    readTextureId = texture2.getTextureObject();
    writeTextureId = texture1.getTextureObject();
    // readTexture = texture2;
    // writeTexture = texture1;

    // bind fbo
    gl.glBindFramebuffer(GL_FRAMEBUFFER, fboId);
    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    gl.glViewport(0, 0, fboWidth, fboHeight);

    // use first program to process inputTexture into texture2
    drawTextureToOffScreenTextureUsingShader(
        inputTexture.getTextureObject(), writeAttachment, programs.get(0));

    swapPingPong(); // make the write texture our new *read* texture

    // loop through the rest of our shaders
    for (int i = 1; i < programs.size(); i++) {
      drawTextureToOffScreenTextureUsingShader(readTextureId, writeAttachment, programs.get(i));
      swapPingPong();
    }

    gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    int www = RenderUtils.getViewport()[2];
    int hhh = RenderUtils.getViewport()[3];

    gl.glViewport(0, 0, www, hhh);

    if (readTextureId == texture1.getTextureObject()) {
      return texture1;
    } else {
      return texture2;
    }
  }
  /**
   * Binds a given texture to the first color target This is useful when we want to render to a
   * dynamic cube map texture.
   *
   * <p>You can write to them by using the `gl_FragData[]` array from your shaders. While bound for
   * rendering, the specified textures cannot be used for texturing operations.
   */
  public void bindGiven(GL2 gl, int textureTarget, int textureHandle, int colorTextureIndex)
      throws OpenGLException {
    /* Save state and adjust viewport if this is the first bind. */
    if (!mIsBound) {
      gl.glPushAttrib(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_VIEWPORT_BIT);
      gl.glGetIntegerv(GL2.GL_FRAMEBUFFER_BINDING, mPreviousBinding, 0);
      gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, getHandle());
      gl.glViewport(0, 0, mWidth, mHeight);
      mIsBound = true;
    }

    /* Attach the given texture */
    gl.glFramebufferTexture2D(
        GL2.GL_FRAMEBUFFER,
        GL2.GL_COLOR_ATTACHMENT0 + colorTextureIndex,
        textureTarget,
        textureHandle,
        0);

    /* Set draw buffer to the requested color attachment. */
    gl.glDrawBuffer(GL2.GL_COLOR_ATTACHMENT0 + colorTextureIndex);

    /* Make sure it worked. */
    OpenGLException.checkOpenGLError(gl);
  }
  @Override
  public void reshape(GLAutoDrawable drawable, int arg1, int arg2, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();

    // Computing the aspect ratio
    float aspect = (float) width / height;

    // Setting the viewport, the area that is displayed, to cover the whole window
    gl.glViewport(0, 0, width, height);

    // Setting the perspective projection with an aspect that matches that of the viewport
    // Choose Projection Matrix
    gl.glMatrixMode(GL_PROJECTION);

    // Resets the Projection Matrix
    gl.glLoadIdentity();

    // gluPerspective(fovy, aspect, zNear, zFar);
    // Instructions taken from http://www.opengl.org/sdk/docs/man2/xhtml/glTranslate.xml
    // fovy : Specifies the field of view angle, in degrees, in the y direction.
    // aspect : Specifies the aspect ratio that determines the field of view in the x direction. The
    // aspect ratio is the ratio of x (width) to y (height).
    // zNear : Specifies the distance from the viewer to the near clipping plane (always positive).
    // zFar : Specifies the distance from the viewer to the far clipping plane (always positive).
    glu.gluPerspective(45.0, aspect, 0.1, 100.0);
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glLoadIdentity();
  }
  public boolean bind() {
    GL2 gl = getGL();
    // if first time, generate FBO
    if (fboId < 0) {
      System.out.println("GENERATE...");
      if (!generateFBO(gl)) {
        System.err.println("couldn't generate FBO!");
        return false;
      }
    }

    writeAttachment = GL_COLOR_ATTACHMENT0; // _EXT;
    readAttachment = GL_COLOR_ATTACHMENT1; // _EXT;

    readTextureId = texture2.getTextureObject();
    writeTextureId = texture1.getTextureObject();

    // bind fbo
    // gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
    gl.glBindFramebuffer(GL_FRAMEBUFFER, fboId);
    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    gl.glViewport(0, 0, fboWidth, fboHeight);

    return true;
  }
  /**
   * Binds a single color texture of this FBO for rendering.
   *
   * <p>You can write to this texture by setting either `gl_FragColor` or `gl_FragData[0]` from your
   * shaders. While bound for rendering, the specified texture cannot be used for texturing
   * operations.
   */
  public void bindOne(GL2 gl, int colorTextureIndex) throws OpenGLException {
    /* Sanity check. */
    if (colorTextureIndex < 0 || colorTextureIndex >= getColorTextureCount()) {
      throw new AssertionError(
          "Color texture index out of range: required that 0 <= "
              + colorTextureIndex
              + " < "
              + getColorTextureCount()
              + ".");
    }

    /* Save state and adjust viewport if this is the first bind. */
    if (!mIsBound) {
      gl.glPushAttrib(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_VIEWPORT_BIT);
      gl.glGetIntegerv(GL2.GL_FRAMEBUFFER_BINDING, mPreviousBinding, 0);
      gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, getHandle());
      gl.glViewport(0, 0, mWidth, mHeight);
      mIsBound = true;
    }

    /* Set draw buffer to the requested color attachment. */
    gl.glDrawBuffer(GL2.GL_COLOR_ATTACHMENT0 + colorTextureIndex);

    /* Make sure it worked. */
    OpenGLException.checkOpenGLError(gl);
  }
Exemple #6
0
  /* (non-Javadoc)
   * @see javax.media.opengl.GLEventListener#reshape(javax.media.opengl.GLAutoDrawable, int, int, int, int)
   */
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    this.width = width;
    this.height = height;
    //        GL gl = drawable.getGL();
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    double ratio = (double) width / (double) height;
    double w = 2;
    double h = 2;
    if (width < height) {
      h = h / ratio;
    } else {
      w = w * ratio;
    }

    int mode = Options.getProjectionMode();
    if (mode == Options.PERSPECTIVE) {
      // 	For Perspective projection
      glu.gluPerspective(45, (double) (width) / (double) (height), 0.001, 1000);
    } else if (mode == Options.ORTHOGRAPHIC) {
      // For Orthogonal projection
      gl.glOrtho(-1 * w, w, -1 * h, h, -10000, 10000);
    }
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    for (Iterator<GLBrush> it = displayList.iterator(); it.hasNext(); ) {
      GLBrush brush = it.next();
      brush.setScreenSize(width, height);
    }
  }
Exemple #7
0
  public void init(GLAutoDrawable drawable) {
    drawable.setGL(new DebugGL2(drawable.getGL().getGL2()));
    final GL2 gl = drawable.getGL().getGL2();
    // drawable.getGL().getGL2();
    gl.glViewport(0, 0, SCREENW, SCREENH);

    // Clear color buffer with black
    // gl.glClearColor(1.0f, 0.5f, 1.0f, 1.0f);
    gl.glClearColor(.0f, .0f, .0f, 1.0f);
    gl.glClearDepth(1.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);

    gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER);
    shader.init(gl);
    int programName = shader.getID();
    gl.glBindAttribLocation(programName, Object3D.VERTEXPOSITION, "inposition");
    gl.glBindAttribLocation(programName, Object3D.VERTEXCOLOR, "incolor");
    gl.glBindAttribLocation(programName, Object3D.VERTEXNORMAL, "innormal");
    gl.glBindAttribLocation(programName, Object3D.VERTEXTEXCOORD0, "intexcoord0");
    shader.link(gl);
    uniformMat = gl.glGetUniformLocation(programName, "mat");
    uniformLight = gl.glGetUniformLocation(programName, "lightdir");
    gl.glUseProgram(programName);
    gl.glUniform3f(uniformLight, 0f, 10f, -10f);
    obj.init(gl, mats, programName);
    gl.glUseProgram(0);
  }
  /**
   * Binds several specified color textures of this FBO for rendering.
   *
   * <p>You can write to them by using the `gl_FragData[]` array from your shaders. While bound for
   * rendering, the specified textures cannot be used for texturing operations.
   */
  public void bindSome(GL2 gl, int indices[]) throws OpenGLException {
    /* Save state and adjust viewport if this is the first bind. */
    if (!mIsBound) {
      gl.glPushAttrib(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_VIEWPORT_BIT);
      gl.glGetIntegerv(GL2.GL_FRAMEBUFFER_BINDING, mPreviousBinding, 0);
      gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, getHandle());
      gl.glViewport(0, 0, mWidth, mHeight);
      mIsBound = true;
    }

    /* Set draw buffers to all color attachments. */
    int bindings[] = new int[indices.length];

    for (int i = 0; i < indices.length; ++i) {
      if (indices[i] >= getColorTextureCount()) {
        throw new OpenGLException(
            "FBO bind index "
                + indices[i]
                + " out of range; only "
                + getColorTextureCount()
                + " color textures.");
      }

      bindings[i] = GL2.GL_COLOR_ATTACHMENT0 + indices[i];
    }

    gl.glDrawBuffers(indices.length, bindings, 0);

    /* Make sure it worked. */
    OpenGLException.checkOpenGLError(gl);
  }
  public void unbind() {
    GL2 gl = getGL();
    gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    int www = RenderUtils.getViewport()[2];
    int hhh = RenderUtils.getViewport()[3];

    gl.glViewport(0, 0, www, hhh);
  }
Exemple #10
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   glu.gluPerspective(60.0, (float) w / (float) h, 1.0, 20.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
 }
Exemple #11
0
 @Override
 public void reshape(GLAutoDrawable dr, int x, int y, int width, int height) {
   GL2 gl = dr.getGL().getGL2();
   gl.glViewport(x, y, width, height);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   glu.gluPerspective(45.0f, (float) width / (float) height, 1.0, 100.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
 }
Exemple #12
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glViewport(0, 0, w, h);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(0.0, 3.0, 0.0, 3.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Exemple #13
0
 public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
   width = arg3;
   height = arg4;
   GL2 gl = arg0.getGL().getGL2();
   gl.glViewport(0, 0, width, height);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   gl.glOrtho(0.0, 800, 0.0, 200, -100.0, 100.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
  public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glViewport(0, 0, w, h);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45.0, 1.0, 0.25, 25.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);
  }
Exemple #15
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   if (w <= h)
     gl.glOrtho(-2.5, 2.5, -2.5 * (float) h / (float) w, 2.5 * (float) h / (float) w, -10.0, 10.0);
   else
     gl.glOrtho(-2.5 * (float) w / (float) h, 2.5 * (float) w / (float) h, -2.5, 2.5, -10.0, 10.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
 }
Exemple #16
0
  public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();

    height = (height == 0) ? 1 : height;

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45, (float) width / height, 1, 1000);
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Exemple #17
0
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();

    viewFrustum.setRight(canvas.getDIPWidth());
    viewFrustum.setBottom(canvas.getDIPHeight());

    gl.glViewport(x, y, width, height);
    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    gl.glLoadIdentity();
    viewFrustum.setProjectionMatrix(gl);

    relayout();
  }
  public void drawTextureToOffScreenTexture(int texId, int attachment)
        // public void drawTextureToOffScreenTextureUsingShader(Texture tex, int attachment, Program
        // program)
      {
    GL2 gl = getGL();

    // program.bind(gl);

    gl.glBindTexture(GL_TEXTURE_2D, texId);
    // gl.glBindTexture(GL_TEXTURE_2D, tex.getTextureObject());
    // gl.glDrawBuffer(attachment);
    gl.glBindFramebuffer(GL_FRAMEBUFFER, attachment); // think this is the new way...

    gl.glEnable(GL_TEXTURE_2D);
    // gl.glActiveTexture(GL_TEXTURE0);
    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    gl.glViewport(0, 0, fboWidth, fboHeight);

    // gl.glUniform1i(program.uniform("theTexture"), 0);
    // set projection to ortho
    gl.glMatrixMode(GL_PROJECTION);
    gl.glTranslatef(1f, 1f, 1f);

    gl.glPushMatrix();
    {
      gl.glLoadIdentity();
      RenderUtils.getGLU().gluOrtho2D(0, fboWidth, fboHeight, 0);

      gl.glMatrixMode(gl.GL_MODELVIEW);

      gl.glPushMatrix();
      {
        gl.glLoadIdentity();

        gl.glColor4f(1f, 1f, 1f, 1f);
        drawSquare(gl, 0, 0, fboWidth, fboHeight);
      }
      gl.glPopMatrix();

      gl.glMatrixMode(gl.GL_PROJECTION);
    }
    gl.glPopMatrix();

    gl.glMatrixMode(gl.GL_MODELVIEW);

    gl.glDisable(GL_TEXTURE_2D);
    // program.unbind(gl);
  }
Exemple #19
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    gl = drawable.getGL().getGL2();
    if (height < 1) {
      height = 1;
    }
    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(FPCamera.FOV, h, FPCamera.NEAR, FPCamera.FAR);

    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Exemple #20
0
  /**
   * Call-back handler for window re-size event. Also called when the drawable is first set to
   * visible.
   */
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
    graphicsManager.setGraphics(gl);

    // Set the view port (display area) to cover the entire window
    gl.glViewport(0, 0, width, height);

    // Setup perspective projection, with aspect ratio matches viewport
    gl.glMatrixMode(GL_PROJECTION); // choose projection matrix
    gl.glLoadIdentity(); // reset projection matrix
    glu.gluOrtho2D(0, realWidth, 0, realHeight);

    // Enable the model-view transform
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glLoadIdentity(); // reset
  }
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

    GL2 gl = drawable.getGL().getGL2();
    GLU glu = new GLU();

    // avoid a divide by zero error!
    if (height <= 0) height = 1;

    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45.0f, h, 1.0, 20.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Exemple #22
0
  public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();

    height = (height == 0) ? 1 : height;
    swidth = width; // Set Scissor Width To Window Width
    sheight = height; // Set Scissor Height To Window Height

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); // Select The Projection
    // Matrix
    gl.glLoadIdentity(); // Reset The Projection Matrix
    gl.glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f); // Create Ortho 640x480
    // View (0,0 At Top
    // Left)
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); // Select The Modelview
    // Matrix
    gl.glLoadIdentity();
  }
  /**
   * Call-back handler for window re-size event. Also called when the drawable is first set to
   * visible.
   */
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context

    if (height == 0) height = 1; // prevent divide by zero
    float aspect = (float) width / height;

    // Set the view port (display area) to cover the entire window
    gl.glViewport(0, 0, width, height);

    // Setup perspective projection, with aspect ratio matches viewport
    gl.glMatrixMode(GL_PROJECTION); // choose projection matrix
    gl.glLoadIdentity(); // reset projection matrix
    glu.gluPerspective(45.0, aspect, 0.1, 100.0); // fovy, aspect, zNear, zFar

    // Enable the model-view transform
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glLoadIdentity(); // reset
  }
  @Override
  public void init(GLAutoDrawable glAutoDrawable) {
    gl = glAutoDrawable.getGL().getGL2();
    glu = new GLU();
    glut = new GLUT();

    gl.glClearColor(0.549f, 0.675f, 0.227f, 0.0f);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(left, right, bottom, top);
    gl.glViewport((int) bottom, (int) left, (int) top, (int) right);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glColor3f(.357f, .184f, .478f);

    maxFrames = 50 * ifsFiles.size() + 1000;
    base = gl.glGenLists(maxFrames);
    currentDrawList = base;

    ifsfile = "CS371/assignments/assignment02/tri.ifs";
    loadifs();
  }
Exemple #25
0
  /**
   * Binds all color textures of this FBO for rendering.
   *
   * <p>You can write to them by using the `gl_FragData[]` array from your shaders. While bound for
   * rendering, the specified textures cannot be used for texturing operations.
   */
  public void bindAll(GL2 gl) throws OpenGLException {
    /* Save state and adjust viewport if this is the first bind. */
    if (!mIsBound) {
      gl.glPushAttrib(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_VIEWPORT_BIT);
      gl.glGetIntegerv(GL2.GL_FRAMEBUFFER_BINDING, mPreviousBinding, 0);
      gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, getHandle());
      gl.glViewport(0, 0, mWidth, mHeight);
      mIsBound = true;
    }

    /* Set draw buffers to all color attachments. */
    int bindings[] = new int[getColorTextureCount()];

    for (int i = 0; i < getColorTextureCount(); ++i) {
      bindings[i] = GL2.GL_COLOR_ATTACHMENT0 + i;
    }

    gl.glDrawBuffers(getColorTextureCount(), bindings, 0);

    /* Make sure it worked. */
    OpenGLException.checkOpenGLError(gl);
  }
  @Override
  public void draw(IDelegateView view, DrawContext dc, DrawableSceneController sc) {
    GL2 gl = dc.getGL().getGL2();
    init(gl);

    if (distortionShader.isCreationFailed()) {
      view.draw(dc, sc);
      return;
    }

    Rectangle oldViewport = view.getViewport();

    hmd.beginFrameTiming(++frameCount);
    {
      Posef[] eyePoses = hmd.getEyePoses(frameCount, eyeOffsets);
      // RiftLogger.logPose(eyePoses);

      renderEyes = true;
      frameBuffer.bind(gl);
      {
        sc.clearFrame(dc);

        for (int i = 0; i < ovrEye_Count; i++) {
          int eye = hmd.EyeRenderOrder[i];
          Posef pose = eyePoses[eye];
          this.eyePoses[eye].Orientation = pose.Orientation;
          this.eyePoses[eye].Position = pose.Position;

          this.eye = eye;

          gl.glViewport(
              eyeRenderViewport[eye].Pos.x,
              eyeRenderViewport[eye].Pos.y,
              eyeRenderViewport[eye].Size.w,
              eyeRenderViewport[eye].Size.h);

          sc.applyView(dc);
          sc.draw(dc);
        }
      }
      frameBuffer.unbind(gl);
      renderEyes = false;

      OGLStackHandler oglsh = new OGLStackHandler();
      oglsh.pushAttrib(gl, GL2.GL_ENABLE_BIT);
      oglsh.pushClientAttrib(gl, GL2.GL_CLIENT_VERTEX_ARRAY_BIT);
      try {
        gl.glViewport(0, 0, hmd.Resolution.w, hmd.Resolution.h);
        gl.glDisable(GL2.GL_DEPTH_TEST);

        gl.glEnable(GL2.GL_TEXTURE_2D);
        gl.glActiveTexture(GL2.GL_TEXTURE0);
        gl.glBindTexture(GL2.GL_TEXTURE_2D, frameBuffer.getTexture().getId());
        for (int eyeNum = 0; eyeNum < ovrEye_Count; eyeNum++) {
          OvrMatrix4f[] timeWarpMatricesRowMajor = new OvrMatrix4f[2];
          hmd.getEyeTimewarpMatrices(eyeNum, eyePoses[eyeNum], timeWarpMatricesRowMajor);
          distortionShader.use(
              gl,
              uvScaleOffset[eyeNum][0].x,
              -uvScaleOffset[eyeNum][0].y,
              uvScaleOffset[eyeNum][1].x,
              1 - uvScaleOffset[eyeNum][1].y,
              timeWarpMatricesRowMajor[0].M,
              timeWarpMatricesRowMajor[1].M);

          gl.glClientActiveTexture(GL2.GL_TEXTURE0);
          gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
          gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
          gl.glEnableClientState(GL2.GL_COLOR_ARRAY);

          gl.glBindBuffer(
              GL2.GL_ARRAY_BUFFER, distortionObjects[eyeNum][DistortionObjects.vbo.ordinal()]);
          {
            int stride = 10 * 4;
            gl.glVertexPointer(4, GL2.GL_FLOAT, stride, 0);
            gl.glTexCoordPointer(2, GL2.GL_FLOAT, stride, 4 * 4);
            gl.glColorPointer(4, GL2.GL_FLOAT, stride, 6 * 4);

            gl.glBindBuffer(
                GL2.GL_ELEMENT_ARRAY_BUFFER,
                distortionObjects[eyeNum][DistortionObjects.ibo.ordinal()]);
            {
              gl.glDrawElements(GL2.GL_TRIANGLES, indicesCount, GL2.GL_UNSIGNED_INT, 0);
            }
            gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0);
          }
          gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);

          distortionShader.unuse(gl);
        }
      } finally {
        oglsh.pop(gl);
      }
    }
    hmd.endFrameTiming();

    // apply the old viewport, and ensure that the view is updated for the next picking round
    gl.glViewport(oldViewport.x, oldViewport.y, oldViewport.width, oldViewport.height);
    sc.applyView(dc);

    view.firePropertyChange(
        AVKey.VIEW, null, view); // make the view draw repeatedly for oculus rotation
  }
Exemple #27
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
 }