什么是"偏移"在GLES20.glVertexAttribPointer参数/与glDrawElements,和哪里PTR /指标从何而来? [英] What's the "offset" parameter in GLES20.glVertexAttribPointer/glDrawElements, and where does ptr/indices come from?

查看:1862
本文介绍了什么是"偏移"在GLES20.glVertexAttribPointer参数/与glDrawElements,和哪里PTR /指标从何而来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与OpenGL ES 2.0的Andr​​oid中玩耍,并期待通过的文档的GLES20 我碰到下面的方法:

I'm playing around with OpenGL ES 2.0 in Android, and looking through the docs 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)

这两种方法是采取缓存对象道理给我,但其他两个没有。他们究竟是怎么了指数/ attibute值(分别),以及什么是偏移的偏移? (我认为这两个问题都有相同的答案。)

The two methods that take Buffer objects make sense to me, but the other two don't. Where do they get the indices/attibute-values (respectively), and what is offset an offset into? (I assume these two questions have the same answer.)

推荐答案

在原型偏移意味着你要提交在此之前call.That应该如果您正在使用VBO的(顶点缓冲对象)可以使用的索引数组。使用glBindBuffer绑定索引缓冲区,并指定偏移如果需要的话,在未来的呼叫。

Offset in the prototype means that you are submitting the INDEX array in prior to this call.That should be used if you are using VBO's(Vertex Buffer Objects).Use glBindBuffer to bind the index buffer and specify an offset if needed in the next call.

首先,你需要绑定缓存(索引缓冲在这里),你可以从那里您的元素开始指定偏移。

First you need to bind the buffer(Index buffer here) and you can specify from where your elements start with an 'offset'.

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)

这意味着,您所提交的顶点缓冲区,在此之前的呼叫,你可以指定它应该在缓冲区中的偏移量。 请检查下面的链接获取更多帮助。 <一href="http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-2.3:-Rendering.html">http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-2.3:-Rendering.html

This means that you are submitting vertex buffer in prior to this call and you can specify the offset from where it should take with in the buffer. Please check the following link for additional help. http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-2.3:-Rendering.html

正如你所料,都具有同样的原因:)。希望这会有所帮助!

As you expected, The both have the same reason :) .Hope this helps!

更新:需要创建一个缓冲器来绑定it.This可以通过以下步骤来完成

Update: you need to create a buffer to bind it.This can be done by the following steps.

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

检查该链接,创建一个VBO。 <一href="http://www.opengl.org/wiki/Vertex_Buffer_Object">http://www.opengl.org/wiki/Vertex_Buffer_Object

Check this link for creating a VBO. http://www.opengl.org/wiki/Vertex_Buffer_Object

对于补偿类型:偏移量是作为指针传递,但参数用于它的整数值,所以我们传递一个整数转换为void *

Regarding the Offset type: The offset is passed as a pointer, but the parameter is used for its integer value, so we pass an integer cast to void*.

这篇关于什么是&QUOT;偏移&QUOT;在GLES20.glVertexAttribPointer参数/与glDrawElements,和哪里PTR /指标从何而来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆