What is the offset parameter in GLES20.glVertexAttribPointer / glDrawElements and where does ptr / index come from?

I play with OpenGL ES 2.0 on Android and view documents for GLES20 . I came across the following methods:

public static void glDrawElements(
    int mode, int count, int type, Buffer indices)
public static void glDrawElements(
    int mode, int count, int type, int offset)

public static void glVertexAttribPointer(
    int indx, int size, int type, boolean normalized, int stride, Buffer ptr)
public static void glVertexAttribPointer(
    int indx, int size, int type, boolean normalized, int stride, int offset)

Two methods that take objects Buffermake sense to me, but the other two do not. Where do they get indexes / attribute-values ​​(respectively), and what does offsetoffset mean ? (I assume that these two questions have the same answer.)

+4
source share
2 answers

, INDEX . , VBO ( ). glBindBuffer , .

( ), , "".

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_resources.element_buffer);
glDrawElements(
    GL_TRIANGLE_STRIP,  /* mode */
    4,                  /* count */
    GL_UNSIGNED_SHORT,  /* type */
    (void*)0            /* element array buffer offset */
);

 public static void glVertexAttribPointer(
int indx, int size, int type, boolean normalized, int stride, int offset)

, , , . . http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-2.3:-Rendering.html

, :). , !

: . .

     glGenBuffers(); // create a buffer object
     glBindBuffer(); // use the buffer
     glBufferData(); // allocate memory in the buffer

VBO. http://www.opengl.org/wiki/Vertex_Buffer_Object

: , , void *.

+6

public static void glDrawElements(
    int mode, int count, int type, int offset)

VBO.

offset - indexVBO ;

, VBO:

import static android.opengl.GLES20.*;

private static final int SIZEOF_SHORT = 2;

void fillIndices() {
    int indexAmount = ...;
    int sizeBytes = indexAmount * SIZEOF_SHORT;
    ShortBuffer indicesS = ByteBuffer.allocateDirect(sizeBytes).order(ByteOrder.nativeOrder()).asShortBuffer();
    indicesS.put(getShortIndices(indexAmount));

    indicesS.position(0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeBytes, indicesS, GL_STATIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

short[] getShortIndices(int indexAmount) {
    short[] indices = new short[indexAmount];
    // fill indices here
    return indices;
}

glDrawElements()

public void draw(){
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBO);
    glDrawElements(GL_TRIANGLE_STRIP, indexCount, GL_UNSIGNED_SHORT, firstIndex * SIZEOF_SHORT);}
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT GL_UNSIGNED_INT .

0

All Articles