@Override
  protected void paintColorScale(GL2 gl, Axis1D axis, int width, int height) {
    if (colorTexture != null && axis instanceof TaggedAxis1D) {
      TaggedAxis1D taggedAxis = (TaggedAxis1D) axis;

      colorTexture.prepare(gl, 0);

      int count = updateCoordinateBuffers(taggedAxis, width, height);

      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
      gl.glPolygonMode(GL2.GL_FRONT, GL2.GL_FILL);

      gl.glEnable(GL2.GL_TEXTURE_1D);

      gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
      gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);

      gl.glVertexPointer(2, GL2.GL_FLOAT, 0, vertexCoords.rewind());
      gl.glTexCoordPointer(1, GL2.GL_FLOAT, 0, textureCoords.rewind());

      try {
        gl.glDrawArrays(GL2.GL_QUAD_STRIP, 0, count);
      } finally {
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisable(GL2.GL_TEXTURE_1D);
      }
    }

    gl.glDisable(GL2.GL_TEXTURE_1D);

    outlineColorQuad(gl, axis, width, height);
  }
Exemple #2
0
  @Override
  protected void render(GL g) {
    GL2 gl = g.getGL2();

    gl.glColor3f(.5f, .5f, .5f);

    // =======================================\\
    // Retained Mode \\
    // =======================================\\
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL2.GL_FLOAT, 0, vertexBuffer);

    if (normal) {
      gl.glEnableClientState(GL2.GL_NORMAL_ARRAY);
      gl.glNormalPointer(GL2.GL_FLOAT, 0, normalBuffer);
    }

    if (texture) {
      gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
      gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, textureBuffer);
    } else gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);

    for (IntBuffer face : faces) {
      if (face.capacity() == 3)
        gl.glDrawElements(GL2.GL_TRIANGLES, face.capacity(), GL2.GL_UNSIGNED_INT, face);
      else if (face.capacity() == 4)
        gl.glDrawElements(GL2.GL_QUADS, face.capacity(), GL2.GL_UNSIGNED_INT, face);
      else gl.glDrawElements(GL2.GL_POLYGON, face.capacity(), GL2.GL_UNSIGNED_INT, face);
    }

    gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);

    if (normal) gl.glDisableClientState(GL2.GL_NORMAL_ARRAY);

    if (texture) gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);

    if (drawBox) bbox.draw(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
  }