Ejemplo n.º 1
0
  private void setupPointers(GL2 gl) {
    int vertices[] = new int[] {25, 25, 100, 325, 175, 25, 175, 325, 250, 25, 325, 325};
    float colors[] =
        new float[] {
          1.0f, 0.2f, 0.2f, 0.2f, 0.2f, 1.0f, 0.8f, 1.0f, 0.2f, 0.75f, 0.75f, 0.75f, 0.35f, 0.35f,
          0.35f, 0.5f, 0.5f, 0.5f
        };

    if (verticesBuf == null) { // IntBuffer tmpVerticesBuf
      verticesBuf = GLBuffers.newDirectIntBuffer(vertices.length);
      verticesBuf.put(vertices);
    }
    if (colorsBuf == null) {
      colorsBuf = GLBuffers.newDirectFloatBuffer(colors.length);
      colorsBuf.put(colors);
    }
    verticesBuf.rewind();
    colorsBuf.rewind();
    //
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
    //
    gl.glVertexPointer(2, GL2.GL_INT, 0, verticesBuf);
    gl.glColorPointer(3, GL.GL_FLOAT, 0, colorsBuf);
  }
  @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);
  }
Ejemplo n.º 3
0
  @Override
  protected void doRender(DrawContext dc) {
    if (!loaded) {
      loaded = true;
      loadAttempts++;
      downloadData();
    }

    if (lastVerticalExaggeration != dc.getVerticalExaggeration() || lastGlobe != dc.getGlobe()) {
      lastVerticalExaggeration = dc.getVerticalExaggeration();
      lastGlobe = dc.getGlobe();
      recalculateVertices(lastGlobe, lastVerticalExaggeration);
      recalculateColors();
    }

    GL2 gl = dc.getGL().getGL2();

    int push = GL2.GL_CLIENT_VERTEX_ARRAY_BIT;
    if (colors != null) {
      push |= GL2.GL_COLOR_BUFFER_BIT;
    }
    if (getOpacity() < 1.0) {
      push |= GL2.GL_CURRENT_BIT;
    }
    gl.glPushClientAttrib(push);

    if (colors != null) {
      gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
      gl.glColorPointer(4, GL2.GL_DOUBLE, 0, colors.rewind());
    }
    if (getOpacity() < 1.0) {
      setBlendingFunction(dc);
    }

    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL2.GL_DOUBLE, 0, vertices.rewind());

    gl.glDrawElements(
        GL2.GL_TRIANGLE_STRIP, indices.limit(), GL2.GL_UNSIGNED_INT, indices.rewind());

    gl.glColor4d(1, 1, 1, 1);
    gl.glPopClientAttrib();
  }
Ejemplo n.º 4
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
  }
Ejemplo n.º 6
0
  private void drawCube() {
    float[] vertices =
        new float[] {
          0.500000f,
          0.500000f,
          0.500000f,
          -0.500000f,
          0.500000f,
          0.500000f,
          0.500000f,
          -0.500000f,
          0.500000f,
          -0.500000f,
          -0.500000f,
          0.500000f,
          0.500000f,
          0.500000f,
          -0.500000f,
          -0.500000f,
          0.500000f,
          -0.500000f,
          0.500000f,
          -0.500000f,
          -0.500000f,
          -0.500000f,
          -0.500000f,
          -0.500000f
        };

    int[] indices =
        new int[] {
          0, 1, 2, 3, 2, 1, 0, 2, 4, 6, 4, 2, 0, 4, 1, 5, 1, 4, 7, 5, 6, 4, 6, 5, 7, 6, 3, 2, 3, 6,
          7, 3, 5, 1, 5, 3
        };

    float[] normals =
        new float[] {
          0.577350f,
          0.577350f,
          0.577350f,
          -0.333333f,
          0.666667f,
          0.666667f,
          0.666667f,
          -0.333333f,
          0.666667f,
          -0.666667f,
          -0.666667f,
          0.333333f,
          0.666667f,
          0.666667f,
          -0.333333f,
          -0.666667f,
          0.333333f,
          -0.666667f,
          0.333333f,
          -0.666667f,
          -0.666667f,
          -0.577350f,
          -0.577350f,
          -0.577350f
        };

    float[] colors =
        new float[] {
          0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
          1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f
        };

    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL2.GL_NORMAL_ARRAY);
    gl.glEnableClientState(GL2.GL_COLOR_ARRAY);

    FloatBuffer pointsFloatBuffer = Buffers.newDirectFloatBuffer(vertices);
    IntBuffer indicesIntBuffer = Buffers.newDirectIntBuffer(indices);
    FloatBuffer colorsFloatBuffer = Buffers.newDirectFloatBuffer(colors);
    FloatBuffer normalsFloatBuffer = Buffers.newDirectFloatBuffer(normals);

    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, whiteMaterial);

    gl.glVertexPointer(3, GL.GL_FLOAT, 0, pointsFloatBuffer);
    gl.glNormalPointer(GL.GL_FLOAT, normals.length, normalsFloatBuffer);
    gl.glColorPointer(3, GL.GL_FLOAT, 0, colorsFloatBuffer);
    //		//gl.glPolygonMode (GL2.GL_FRONT, GL2.GL_FILL);
    //		gl.glPolygonMode (GL2.GL_BACK, GL2.GL_LINE);
    gl.glDrawElements(GL.GL_TRIANGLES, indices.length, GL.GL_UNSIGNED_INT, indicesIntBuffer);

    gl.glDisableClientState(GL2.GL_COLOR_ARRAY);
    gl.glDisableClientState(GL2.GL_NORMAL_ARRAY);
    gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
  }