Lau*_*ves 4 android opengl-es opengl-es-2.0
我正在使用Android中的OpenGL ES 2.0,并查看GLES20的文档,我遇到了以下方法:
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)
Run Code Online (Sandbox Code Playgroud)
采用Buffer
对象的两种方法对我有意义,但另外两种方法没有.他们在哪里获得指数/ attibute-values(分别),以及什么是offset
偏移?(我假设这两个问题有相同的答案.)
原型中的偏移意味着您在此调用之前提交了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 */
);
Run Code Online (Sandbox Code Playgroud)
对于
public static void glVertexAttribPointer(
int indx, int size, int type, boolean normalized, int stride, int offset)
Run Code Online (Sandbox Code Playgroud)
这意味着您在此调用之前提交顶点缓冲区,并且可以指定缓冲区中应该使用的偏移量.请查看以下链接以获取更多帮助. 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
Run Code Online (Sandbox Code Playgroud)
检查此链接以创建VBO.http://www.opengl.org/wiki/Vertex_Buffer_Object
关于偏移类型:偏移量作为指针传递,但参数用于其整数值,因此我们将整数强制转换为void*.
归档时间: |
|
查看次数: |
5563 次 |
最近记录: |