OpenGL ES 2.0的填充顶点和索引缓冲区 [英] opengl es 2.0 populating the Vertex and index Buffer

查看:622
本文介绍了OpenGL ES 2.0的填充顶点和索引缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个愚蠢的问题,但我觉得我要问,所以我能理解OpenGL的缓冲区是如何工作的。

我有两个缓冲区,顶点缓冲和索引缓冲。为了填补这些缓冲区我解析OBJ文件。

解析数据后我填的是缓冲与我认为是正确的数据,数据的顺序。

然而,当我调试code I看到缓冲区一些奇怪的事情。

首先顶点缓冲区。我把在Vbuffer前3的值
0.99,-0.99,-0.7741
然而,当我通过值steping检查缓冲区的
-92,112,125
这是因为这是一个FloatBuffer但作为一个字节的缓冲区?

  this.vertexBuffer = ByteBuffer.allocateDirect(VertexList.length * mBytesPerFloat).order(ByteOrder.nativeOrder())asFloatBuffer()。
    this.vertexBuffer.put(VertexList时);
    this.vertexBuffer.position(0);

索引缓冲区是不同的,我把在
4,1,2
当我检查我似乎在每个值之间得到一个额外的0
4,0,1,0,2

  this.IndexBuffer = ByteBuffer.allocateDirect(IndexList.length * 2).order(ByteOrder.nativeOrder())asShortBuffer();
    this.IndexBuffer.put(IndexList);
    this.IndexBuffer.position(0);

在此缓冲区我可以读取数据ShortBuffer即使它的一个字节的缓冲区。
另外,为什么是所有其他价值0?

任何理解这种帮助将是AP preciated。

更新!

这是我的全code从OBJ文件解析数据和填充缓冲区。这被放入缓冲区中的数据似乎是正确的。

 公共类RBLoadModelFromFile
{
/ **多少每浮动字节。 * /
私人最终诠释mBytesPerFloat = 4;私人上下文的背景下;
公共FloatBuffer vertexBuffer;
公共ShortBuffer IndexBuffer;
公众持股量[]顶点;
公众持股量[]法线;
公众持股量[]乌布苏;
公共短[]工业;
私人的ArrayList<短期和GT; indicies;
公众诠释NumVertices;
公众诠释NumIndicies;公共RBLoadModelFromFile(上下文C)
{
    上下文= C;
}
公共无效loadModel(字符串文件名)
{    ArrayList的< RBVector3> tempVertices =新的ArrayList< RBVector3>();
    ArrayList的< RBVector3> tempNormals =新的ArrayList< RBVector3>();
    ArrayList的< RBVector3> tempUVs =新的ArrayList< RBVector3>();    ArrayList的<短期和GT; vertexIndices =新的ArrayList<短期和GT;();
    ArrayList的<短期和GT; normalIndices =新的ArrayList<短期和GT;();
    ArrayList的<短期和GT; textureIndices =新的ArrayList<短期和GT;();
    indicies =新的ArrayList<短期和GT;();    尝试{
        AssetManager经理= context.getAssets();
        读者的BufferedReader =新的BufferedReader(新的InputStreamReader(manager.open(文件名)));
        串线;
        而((行= reader.readLine())!= NULL)
        {
            如果(line.startsWith(V))
            {
                RBVector3 tempVert =新RBVector3(0F,0F,0F);
                tempVert.add(Float.valueOf(line.split()[2]),Float.valueOf(line.split()[3]),Float.valueOf(line.split()[4] ));
                tempVertices.add(tempVert);
            }
            否则如果(line.startsWith(VN))
            {
                RBVector3 tempNorm =新RBVector3(0F,0F,0F);
                tempNorm.add(Float.valueOf(line.split()[1]),Float.valueOf(line.split()[2]),Float.valueOf(line.split()[3] ));
                tempNormals.add(tempNorm);
            }
            否则如果(line.startsWith(VT))
            {
                RBVector3 tempUV =新RBVector3(0F,0F,0F);
                tempUV.add(Float.valueOf(line.split()[1]),Float.valueOf(line.split()[2]),0F);
                tempUVs.add(tempUV);
            }
            否则如果(line.startsWith(F))
            {
                TMP的String [] = line.split();
                vertexIndices.add(Short.valueOf(TMP [1] .split(/)[0]));
                textureIndices.add(Short.valueOf(TMP [1] .split(/)[1]));
                normalIndices.add(Short.valueOf(TMP [1] .split(/)[2]));                vertexIndices.add(Short.valueOf(TMP [2] .split(/)[0]));
                textureIndices.add(Short.valueOf(TMP [2] .split(/)[1]));
                normalIndices.add(Short.valueOf(TMP [2] .split(/)[2]));                vertexIndices.add(Short.valueOf(TMP [3] .split(/)[0]));
                textureIndices.add(Short.valueOf(TMP [3] .split(/)[1]));
                normalIndices.add(Short.valueOf(TMP [3] .split(/)[2]));
            }
        }
        IND =新的短[vertexIndices.size()+ normalIndices.size()+ textureIndices.size()];
        顶点=新浮[(vertexIndices.size()* 3)+(normalIndices.size()* 3)+(textureIndices.size()* 2)];
        ArrayList的<浮球GT; vertInfo =新的ArrayList<浮球GT;();
        的for(int i = 0; I< vertexIndices.size();我++)
        {
            短V = vertexIndices.get(ⅰ);
            vertInfo.add(tempVertices.get(V-1).X);
            vertInfo.add(tempVertices.get(V-1).Y);
            vertInfo.add(tempVertices.get(V-1).Z);
            indicies.add((短)(V-1));
            短N = normalIndices.get(I)
            vertInfo.add(tempNormals.get(N-1).X);
            vertInfo.add(tempNormals.get(N-1).Y);
            vertInfo.add(tempNormals.get(N-1).Z);
            indicies.add((短)(N-1));
            短T = textureIndices.get(I)
            vertInfo.add(tempUVs.get(T-1).X);
            vertInfo.add(tempUVs.get(T-1).Y);
            indicies.add((短)(T-1));
        }
        的for(int i = 0; I< indicies.size();我++)
        {
            的ind [I] = indicies.get(ⅰ);
        }
        的for(int i = 0; I< vertInfo.size();我++)
        {
            顶点[I] = vertInfo.get(ⅰ);
        }
        createIndexBuffer(IND);
        createVertexBuffer(顶点);
        NumIndicies = Ind.length;
        NumVertices = vertices.length;
    }
    赶上(例外五)
    {
        Log.d(调试,错误,E);
    }
}
私人无效createVertexBuffer(浮法[] VertexList时)
{
    。this.vertexBuffer = ByteBuffer.allocateDirect(VertexList.length * mBytesPerFloat).order(ByteOrder.nativeOrder())asFloatBuffer();
    this.vertexBuffer.put(VertexList时);
    this.vertexBuffer.position(0);
}
私人无效createIndexBuffer(短[] IndexList)
{
    this.IndexBuffer = ByteBuffer.allocateDirect(IndexList.length * 2).order(ByteOrder.nativeOrder())asShortBuffer();
    this.IndexBuffer.put(IndexList);
    this.IndexBuffer.position(0);
}
}

和这里是我试图解析一个简单的立方体OBJ文件

  v -0.500000 -0.500000 0.500000
v 0.500000 -0.500000 0.500000
v -0.500000 0.500000 0.500000
v 0.500000 0.500000 0.500000
v -0.500000 0.500000 -0.500000
v 0.500000 0.500000 -0.500000
v -0.500000 -0.500000 -0.500000
v 0.500000 -0.500000 -0.500000VT 0.000000 0.000000
VT 1.000000 0.000000
VT 0.000000 1.000000
VT 1.000000 1.000000VN 0.000000 0.000000 1.000000
VN 0.000000 1.000000 0.000000
VN 0.000000 0.000000 -1.000000
VN 0.000000 0.000000 -1.000000
VN 1.000000 0.000000 0.000000
VN -1.000000 0.000000 0.000000˚F1/1/1 2/2/1 3/3/1
˚F3/3/1 2/2/1 4/4/1
˚F3/1/2 4/2/2 5/3/2
˚F5/3/2 4/2/2 6/4/2
˚F5/4/3 6/3/3 7/2/3
˚F7/2/3 6/3/3 8/1/3
˚F7/1/4 8/2/4 1/3/4
˚F1/3/4 8/2/4 2/4/4
˚F2/1/5 8/2/5 4/3/5
˚F4/3/5 8/2/5 6/4/5
˚F7/1/6 1/2/6 5/3/6
˚F5/3/6 1/2/6 3/4/6

我现在得到的东西画,但顶点似乎路要走。

这是我现在的画法

 公共无效DrawModel(浮动[] mProjectionMatrix,浮动[] mViewMatrix,浮动[] mMVPMatrix,INT mProgramHandle,诠释mMVPMatrixHandle,诠释mMVMatrixHandle,诠释mLightPosHandle,浮动[] mLightPosInEyeSpace)
{    mPositionHandle = GLES20.glGetAttribLocation(mProgramHandlea_Position);
    mNormalHandle = GLES20.glGetAttribLocation(mProgramHandlea_Normal);
    mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandleu_Texture);
    mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandlea_TexCoordinate);    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);    //绑定纹理到本机。
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,mTextureDataHandle);
    //告诉质地均匀采样通过结合纹理单元0使用这种纹理着色器。
    GLES20.glUniform1i(mTextureUniformHandle,0);    //这个乘以模型矩阵视图矩阵,并将结果保存在MVP矩阵
    //(目前包含型号*视图)。
    Matrix.multiplyMM(mMVPMatrix,0,mViewMatrix,0,mModelMatrix,0);    //把在模型视图矩阵。
    GLES20.glUniformMatrix4fv(mMVMatrixHandle,1,假,mMVPMatrix,0);    //这个乘以投影矩阵模型视图矩阵,并将结果保存在MVP矩阵
    //(现在包含模型*查看*投影)。
    Matrix.multiplyMM(mMVPMatrix,0,mProjectionMatrix,0,mMVPMatrix,0);    //传入联合矩阵。
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle,1,假,mMVPMatrix,0);    //转至眼睛空间光源位置。
    GLES20.glUniform3f(mLightPosHandle,mLightPosInEyeSpace [0],mLightPosInEyeSpace [1],mLightPosInEyeSpace [2]);    //顶点坐标
    VertexBuffer.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(mPositionHandle,3,GLES20.GL_FLOAT,假的,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES,VertexBuffer);
    GLES20.glEnableVertexAttribArray(mPositionHandle);    //正常的信息
    VertexBuffer.position(TRIANGLE_VERTICES_DATA_NOR_OFFSET);
    GLES20.glVertexAttribPointer(mNormalHandle,3,GLES20.GL_FLOAT,假的,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES,VertexBuffer);
    GLES20.glEnableVertexAttribArray(mNormalHandle);//纹理坐标
    VertexBuffer.position(TRIANGLE_VERTICES_DATA_TEX_OFFSET);
    GLES20.glVertexAttribPointer(mTextureCoordinateHandle,2,GLES20.GL_FLOAT,假的,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES,VertexBuffer);
    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);//GLES20.glEnableVertexAttribArray(shader.maTextureHandle);    //使用指标绘制
    GLES20.glDrawElements(GLES20.GL_TRIANGLES,NumIndicies,GLES20.GL_UNSIGNED_SHORT,IndexBuffer);
    // checkGlError(glDrawElements);
}


解决方案

好吧,我终于成功地解决我的问题渲染。快速感谢@MaurizioBenedetti,因为他曾这样评价,并回答了我的一些问题,这些问题使我得到我在哪里。

首先我所投入的缓冲区是正确的在一定程度上。我的问题就来了,因为我创建了一个交错的顶点缓冲 - 这意味着数据已经在正确的顺序VVVNNNTT。然后我去创造它包含实际的索引数据这是indicies一个无交错缓冲

索引缓冲区

例如,如果面孔包含2/4/6 4/7/9 2/1/3那么我的索引缓存包含在这些精确值,但因为我的顶点缓冲区交错它应该containd数的有序列表indicies。

因此​​,这意味着如果上面的脸是唯一indicies然后索引缓冲区应载有
0,1,2,3,4,5,6,7,8

总结一下上面code,当我填充顶点信息

我应该说这样的事情

  indicies.add(指数++);

而不是分配每个indicie值

我希望这是明确的人谁是停留在这样的事情,并希望有所帮助。

This may seem like a silly question but i feel i need to ask it so i can understand how openGl buffers work.

I have two buffers , vertex buffer and index buffer. To fill these buffers i am parsing an obj file.

After parsing the data i fill the buffers with what i think is the correct data and order of data.

However when i debug the code i see some strange things in the buffers.

Firstly the vertex buffer. The first 3 values that i put in the Vbuffer are 0.99,-0.99,-0.7741 However when i check the buffer by steping through the values are -92,112,125 is this because this is a FloatBuffer but as a byte buffer?

    this.vertexBuffer = ByteBuffer.allocateDirect(VertexList.length *   mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();                             
    this.vertexBuffer.put(VertexList);
    this.vertexBuffer.position(0);

The index buffer is different i put in 4,1,2 and when i check it i seem to get an extra 0 between each value 4,0,1,0,2

    this.IndexBuffer = ByteBuffer.allocateDirect(IndexList.length * 2).order(ByteOrder.nativeOrder()).asShortBuffer();
    this.IndexBuffer.put(IndexList);
    this.IndexBuffer.position(0);

in this buffer i can read the data as ShortBuffer even though its a byte buffer. Also why is every other value a 0?

Any help understanding this would be appreciated.

UPDATE!

This is my full code for parsing the data from an obj file and filling the buffers. The data that gets put into the buffers appears to be correct.

public class RBLoadModelFromFile 
{
/** How many bytes per float. */
private final int mBytesPerFloat = 4;   

private Context context;
public FloatBuffer vertexBuffer;
public ShortBuffer IndexBuffer;
public float[] vertices;
public float[] normals;
public float[] uVs;
public short[] Ind;
private ArrayList<Short> indicies;
public int NumVertices;
public int NumIndicies;

public RBLoadModelFromFile(Context c) 
{
    context = c;
}


public void loadModel(String filename) 
{

    ArrayList<RBVector3> tempVertices = new ArrayList<RBVector3>();        
    ArrayList<RBVector3> tempNormals = new ArrayList<RBVector3>();
    ArrayList<RBVector3> tempUVs = new ArrayList<RBVector3>();

    ArrayList<Short> vertexIndices = new ArrayList<Short>();
    ArrayList<Short> normalIndices = new ArrayList<Short>();
    ArrayList<Short> textureIndices = new ArrayList<Short>();
    indicies = new ArrayList<Short>();

    try {
        AssetManager manager = context.getAssets();
        BufferedReader reader = new BufferedReader(new InputStreamReader(manager.open(filename)));
        String line;
        while ((line = reader.readLine()) != null) 
        {
            if (line.startsWith("v  ")) 
            {    
                RBVector3 tempVert = new RBVector3(0f,0f,0f);
                tempVert.add(Float.valueOf(line.split(" ")[2]),Float.valueOf(line.split(" ")[3]),Float.valueOf(line.split(" ")[4]));
                tempVertices.add(tempVert); 
            }
            else if (line.startsWith("vn")) 
            {
                RBVector3 tempNorm = new RBVector3(0f,0f,0f);
                tempNorm.add(Float.valueOf(line.split(" ")[1]),Float.valueOf(line.split(" ")[2]),Float.valueOf(line.split(" ")[3]));
                tempNormals.add(tempNorm);                              
            }
            else if (line.startsWith("vt")) 
            {
                RBVector3 tempUV = new RBVector3(0f,0f,0f);
                tempUV.add(Float.valueOf(line.split(" ")[1]),Float.valueOf(line.split(" ")[2]), 0f);
                tempUVs.add(tempUV);                            
            }
            else if (line.startsWith("f"))
            {                
                String tmp[] = line.split(" ");     
                vertexIndices.add(Short.valueOf(tmp[1].split("/")[0]));
                textureIndices.add(Short.valueOf(tmp[1].split("/")[1]));
                normalIndices.add(Short.valueOf(tmp[1].split("/")[2]));

                vertexIndices.add(Short.valueOf(tmp[2].split("/")[0]));
                textureIndices.add(Short.valueOf(tmp[2].split("/")[1]));
                normalIndices.add(Short.valueOf(tmp[2].split("/")[2]));

                vertexIndices.add(Short.valueOf(tmp[3].split("/")[0]));
                textureIndices.add(Short.valueOf(tmp[3].split("/")[1]));
                normalIndices.add(Short.valueOf(tmp[3].split("/")[2]));
            }
        }
        Ind = new short[vertexIndices.size() + normalIndices.size() + textureIndices.size()];
        vertices = new float[(vertexIndices.size() * 3) + (normalIndices.size() * 3) + (textureIndices.size() * 2)];
        ArrayList<Float> vertInfo = new ArrayList<Float>();
        for (int i = 0; i < vertexIndices.size(); i++) 
        {            
            Short v = vertexIndices.get(i);
            vertInfo.add(tempVertices.get(v-1).x);
            vertInfo.add(tempVertices.get(v-1).y);
            vertInfo.add(tempVertices.get(v-1).z);
            indicies.add((short) (v-1));
            Short n = normalIndices.get(i);
            vertInfo.add(tempNormals.get(n-1).x);
            vertInfo.add(tempNormals.get(n-1).y);
            vertInfo.add(tempNormals.get(n-1).z);
            indicies.add((short) (n-1));
            Short t = textureIndices.get(i);
            vertInfo.add(tempUVs.get(t-1).x);
            vertInfo.add(tempUVs.get(t-1).y);
            indicies.add((short) (t-1));
        }
        for(int i = 0; i < indicies.size(); i++)
        {
            Ind[i] = indicies.get(i);
        }
        for (int i = 0; i < vertInfo.size(); i++) 
        { 
            vertices[i] = vertInfo.get(i);
        }
        createIndexBuffer(Ind);
        createVertexBuffer(vertices);
        NumIndicies = Ind.length;
        NumVertices = vertices.length;
    }
    catch (Exception e)
    {
        Log.d("DEBUG", "Error.", e);
    }
}
private void createVertexBuffer(float[] VertexList)
{
    this.vertexBuffer = ByteBuffer.allocateDirect(VertexList.length * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();                               
    this.vertexBuffer.put(VertexList);
    this.vertexBuffer.position(0);
}
private void createIndexBuffer(short[] IndexList)
{
    this.IndexBuffer = ByteBuffer.allocateDirect(IndexList.length * 2).order(ByteOrder.nativeOrder()).asShortBuffer();
    this.IndexBuffer.put(IndexList);
    this.IndexBuffer.position(0);
}
}

and here is a simple cube obj file that i am trying to parse

v  -0.500000 -0.500000 0.500000
v  0.500000 -0.500000 0.500000
v  -0.500000 0.500000 0.500000
v  0.500000 0.500000 0.500000
v  -0.500000 0.500000 -0.500000
v  0.500000 0.500000 -0.500000
v  -0.500000 -0.500000 -0.500000
v  0.500000 -0.500000 -0.500000

vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000

vn 0.000000 0.000000 1.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 -1.000000 0.000000
vn 1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000

f 1/1/1 2/2/1 3/3/1
f 3/3/1 2/2/1 4/4/1
f 3/1/2 4/2/2 5/3/2
f 5/3/2 4/2/2 6/4/2
f 5/4/3 6/3/3 7/2/3
f 7/2/3 6/3/3 8/1/3
f 7/1/4 8/2/4 1/3/4
f 1/3/4 8/2/4 2/4/4
f 2/1/5 8/2/5 4/3/5
f 4/3/5 8/2/5 6/4/5
f 7/1/6 1/2/6 5/3/6
f 5/3/6 1/2/6 3/4/6

I am now getting something draw but the vertices seems to be way off.

this is now my drawing method

public void DrawModel(float[] mProjectionMatrix, float[] mViewMatrix, float[] mMVPMatrix, int mProgramHandle, int mMVPMatrixHandle, int mMVMatrixHandle, int mLightPosHandle, float[] mLightPosInEyeSpace)
{

    mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
    mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
    mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
    mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle); 
    // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0.
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
    // (which currently contains model * view).
    Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

    // Pass in the modelview matrix.
    GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);

    // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix
    // (which now contains model * view * projection).
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

    // Pass in the combined matrix.
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    // Pass in the light position in eye space.
    GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);        

    // the vertex coordinates
    VertexBuffer.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, VertexBuffer);
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // the normal info
    VertexBuffer.position(TRIANGLE_VERTICES_DATA_NOR_OFFSET);
    GLES20.glVertexAttribPointer(mNormalHandle, 3, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, VertexBuffer);
    GLES20.glEnableVertexAttribArray(mNormalHandle);

// texture coordinates
    VertexBuffer.position(TRIANGLE_VERTICES_DATA_TEX_OFFSET);
    GLES20.glVertexAttribPointer(mTextureCoordinateHandle, 2, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, VertexBuffer);
    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);//GLES20.glEnableVertexAttribArray(shader.maTextureHandle);

    // Draw with indices
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, NumIndicies , GLES20.GL_UNSIGNED_SHORT, IndexBuffer);
    //checkGlError("glDrawElements");
}

解决方案

Ok i have finally managed to solve my rendering issue. quick thanks to @MaurizioBenedetti as he has commented and answered some of my questions which has helped me get to where i am.

Firstly what i am putting into the buffers is correct to some extent. My Problem comes because i create a interleaved vertex buffer - this means the data is already in the correct order VVVNNNTT. Then i went and created the index buffer which contained the actual index data which is the indicies for a none interleaved buffer

for example if the faces contained 2/4/6 4/7/9 2/1/3 then my index buffer contained these exact values but because my vertex buffer is interleaved it should have containd an ordered list of the number of indicies.

So this means if the above faces were the only indicies then the index buffer should have contained 0,1,2,3,4,5,6,7,8

to sum up in the above code when i populate the vertex info

I should have said something like this

indicies.add(index++);

Instead of assigning each indicie value

I hope this is clear for anyone who is stuck on this sort of thing and will hopefully help.

这篇关于OpenGL ES 2.0的填充顶点和索引缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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