Exemple #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);
  }
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);
  }