Java 切换到使用交错VBO-编译但不绘制任何内容-opengl es 2.0
我刚刚尝试切换到使用交错VBO。我已经完成了创建交错VBO的过程,它似乎具有正确的init信息 VVV NNN TT等 下面是初始化缓冲区的代码Java 切换到使用交错VBO-编译但不绘制任何内容-opengl es 2.0,java,android,rendering,opengl-es-2.0,vbo,Java,Android,Rendering,Opengl Es 2.0,Vbo,我刚刚尝试切换到使用交错VBO。我已经完成了创建交错VBO的过程,它似乎具有正确的init信息 VVV NNN TT等 下面是初始化缓冲区的代码 VertexBuffer = Loader.vertexBuffer; final int buffers[] = new int[1]; GLES20.glGenBuffers(1, buffers, 0); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]); GLES20
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);
在使用VBOs之前,我让矩阵计算出来,因为这是可行的,我正确地看到了所有的句柄
我的应用程序运行起来好像模型在那里,但只是不可见。例如,我正在移动一个模型,当它到达某个位置时,有人告诉我,我无法像移动到VBOs之前那样看到它
如果需要上传其他内容,请告诉我。如有任何建议,将不胜感激
更新
我想问题可能在于我创建交错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);
}
我不知道我在上面的代码中遇到了什么问题,我是如何重新编写代码来使用索引缓冲区的,并在另一个问题中提交的。发现
除了我在另一个问题中给出的答案外,它还应该为任何一个正在挣扎的人提供一个清晰的介绍VBO和IBO的方式i rob,在不同的VertexAttributePointer中设置的步幅/大小偏移中似乎存在一些问题。您能否报告设置不同mPositionDataSize、mNormalDataSize、MTextureCoordinatedTaskize的方式。函数参数的计算方法应该是0 x sizeoffloat、3 x sizeoffloat、6 x sizeoffloat。像这样的。尝试检查或报告这两个变量。再见。MaurizioHi@MaurizioBenedetti在类private final int mBytesPerFloat=4的开头将这些设置为final int;私有最终int mPositionDataSize=3;私有最终整数mNormalDataSize=3;私有最终int mTextureCoordinateDataSize=2;当你说这是一种非常肮脏的计算方法,也就是说createvertexbuffer方法?有更好的方法吗?@MaurizioBenedetti我已经检查了缓冲区和填充方式。我认为问题不存在,所以我又回到了步幅/尺寸上。你还有什么建议吗?嗨,罗布。我再次检查了你的代码,看起来都不错。只是一个简短的提示,你在哪里绑定纹理?由于您正在传递纹理坐标,我猜frag_颜色是基于纹理计算的。我无法在代码中看到着色器或纹理绑定。我建议回顾一下这一部分。在使用着色器的情况下,可以尝试非常简单地强制frag_颜色为固定值,即白色表示黑屏或黑色表示白屏,以查看是否至少处理了几何体信息。
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);
}