Пример #1
0
    private void initBuffers(GL3 gl) {
      // IDs for 2 buffers
      int[] buffArray = new int[2];
      gl.glGenBuffers(buffArray.length, buffArray, 0);
      vbo = buffArray[0];
      assert vbo > 0;

      // Bind buffer and upload data
      gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo);
      gl.glBufferData(
          GL3.GL_ARRAY_BUFFER,
          vertexColorData.length * Buffers.SIZEOF_FLOAT,
          vertexColorDataBuffer,
          GL3.GL_STATIC_DRAW);
      gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);

      // Buffer with the 3 indices required for one triangle
      ibo = buffArray[1];
      assert ibo > 0;
      gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, ibo);
      gl.glBufferData(
          GL3.GL_ELEMENT_ARRAY_BUFFER,
          indices.length * Buffers.SIZEOF_SHORT,
          indicesBuffer,
          GL3.GL_STATIC_DRAW);
      gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, 0);
    }
Пример #2
0
  /**
   * Constructor that creates a Vertex Buffer Object with the specified GLSL attributes. (typically
   * location, texture coordinates, normals, etc.)
   *
   * @param gl The global openGL instance.
   * @param attribs One or more attributes that represent this VBO, @see GLSLAttrib
   */
  public VBO(GL3 gl, GLSLAttrib... attribs) {
    this.attribs = attribs;

    // Generate a new internal OpenGL VBO pointer
    this.vboPointer = Buffers.newDirectIntBuffer(1);
    gl.glGenVertexArrays(1, this.vboPointer);
    gl.glBindVertexArray(this.vboPointer.get(0));

    // Generate a new internal OpenGL Array Buffer pointer
    this.bufferPointer = Buffers.newDirectIntBuffer(1);
    gl.glGenBuffers(1, this.bufferPointer);
    gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, this.bufferPointer.get(0));

    // Allocate enough memory
    int size = 0;
    for (final GLSLAttrib attrib : attribs) {
      size += attrib.buffer.capacity() * Buffers.SIZEOF_FLOAT;
    }

    gl.glBufferData(GL3.GL_ARRAY_BUFFER, size, (Buffer) null, GL3.GL_STATIC_DRAW);

    // Copy the GLSL Attribute data into the internal OpenGL buffer
    int nextStart = 0;
    for (final GLSLAttrib attrib : attribs) {
      gl.glBufferSubData(
          GL3.GL_ARRAY_BUFFER,
          nextStart,
          attrib.buffer.capacity() * Buffers.SIZEOF_FLOAT,
          attrib.buffer);
      nextStart += attrib.buffer.capacity() * Buffers.SIZEOF_FLOAT;
    }
  }
  private void initializeVertexBuffer(GL3 gl3) {
    gl3.glGenBuffers(1, IntBuffer.wrap(vertexBufferObject));

    gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBufferObject[0]);
    {
      FloatBuffer buffer = GLBuffers.newDirectFloatBuffer(vertexData);

      gl3.glBufferData(GL3.GL_ARRAY_BUFFER, vertexData.length * 4, buffer, GL3.GL_STATIC_DRAW);
    }
    gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
  }