我刚尝试过切换使用Interleaved VBO。我已经完成了创建Interleaved VBO的过程,看起来它有正确的信息init。
以下是初始化缓冲区的代码
VertexBuffer = Loader.vertexBuffer;
final int buffers[] = new int[1];
GLES20.glGenBuffers(1, buffers, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, VertexBuffer.capacity(), VertexBuffer, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
mBufferIdx = buffers[0];
VertexBuffer.limit(0);
VertexBuffer = null;
这是我绘制模型的代码
final int stride = (mPositionDataSize + mNormalDataSize + mTextureCoordinateDataSize) * mBytesPerFloat;
// Pass in the position information
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBufferIdx);
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, stride, 0);
// Pass in the normal information
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBufferIdx);
GLES20.glEnableVertexAttribArray(mNormalHandle);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false, stride, mPositionDataSize * mBytesPerFloat);
// Pass in the texture information
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBufferIdx);
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, GLES20.GL_FLOAT, false,
stride, (mPositionDataSize + mNormalDataSize) * mBytesPerFloat);
// Clear the currently bound buffer (so future OpenGL calls do not use this buffer).
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
// Draw .
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, NumVertices);
在使用VBO之前,我在离开矩阵时工作正常,我正在正确地使用所有句柄。
我的应用程序似乎运行就像模型在那里但只是看不见。例如,我正在移动一个模型并被告知它何时到达某个位置,我只是不能像我在移动到VBO之前那样看到它。
如果我需要上传任何其他内容,请告诉我。任何建议将不胜感激。
UPDATE!
我认为问题可能在于我在这里创建交错的VBO的方式是代码
private void createVertexBuffer(float[] VertexList, float[] NormalList, float[] TextureList)
{
final int vertexDataSize = VertexList.length + NormalList.length + TextureList.length;
this.vertexBuffer = ByteBuffer.allocateDirect(vertexDataSize * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();
int PositionOffset = 0;
int NormalOffset = 0;
int TextureOffset = 0;
for(int i = 0; i < NumVerts; i++)
{
this.vertexBuffer.put(VertexList, PositionOffset, mPositionDataSize);
PositionOffset += mPositionDataSize;
this.vertexBuffer.put(NormalList, NormalOffset, mNormalDataSize);
NormalOffset += mNormalDataSize;
this.vertexBuffer.put(TextureList, TextureOffset, mTextureCoordinateDataSize);
TextureOffset += mTextureCoordinateDataSize;
}
this.vertexBuffer.position(0);
}
我可能做错了什么?
更新代码
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_LightPos");
//mColorHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Color");
Cube1.mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
Cube1.mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
Cube1.mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
Cube1.mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");
Cube1.SetTexture();
Cube1.SetIdentity();
Cube1.SetPosition();
Cube1.SetScale(10.0f, 10.0f, 10.0f);
Cube1.SetRotation(RotationAngle, 0.0f, 0.0f, 1.0f);
Cube1.DrawModel(mProjectionMatrix, mViewMatrix, mMVPMatrix, mMVPMatrixHandle, mMVMatrixHandle, mLightPosHandle, mLightPosInEyeSpace);
public void SetTexture()
{
// 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);
}
答案 0 :(得分:0)
我不确定我的问题是什么在上面的代码中我怎么写我的代码来使用索引缓冲区并在另一个问题中提交。找到here
除了我在另一个问题中给出的答案外,它应该为任何正在挣扎的人提供一个明确的方式来介绍VBO和IBO