编辑2:
解决方案:复制粘贴错误:发送颜色缓冲区作为位置缓冲区。
解析代表金字塔的 .obj(波前),在必要的地方进行三角测量,将其全部传递到缓冲区中。缓冲区如下所示:
顶点缓冲区:
private FloatBuffer mPositionBuffer = null;
// from looping through buffer + print:
#0 = -0.5, 0.0, -0.5
#3 = 0.5, 0.0, -0.5
#6 = 0.5, 0.0, 0.5
#9 = -0.5, 0.0, 0.5
#12 = 0.5, 0.0, 0.5
#15 = 0.5, 0.0, -0.5
#18 = 0.0, 1.0, 0.0
#21 = 0.5, 0.0, -0.5
#24 = -0.5, 0.0, -0.5
#27 = 0.0, 1.0, 0.0
#30 = -0.5, 0.0, -0.5
#33 = -0.5, 0.0, 0.5
#36 = 0.0, 1.0, 0.0
#39 = -0.5, 0.0, 0.5
#42 = 0.5, 0.0, 0.5
#45 = 0.0, 1.0, 0.0
颜色缓冲器:
private ByteBuffer mColorBuffer = null;
#0 = 1, 1, 1, 1
#4 = 1, 1, 1, 1
#8 = 1, 1, 1, 1
#12 = 1, 1, 1, 1
#16 = 1, 1, 1, 1
#20 = 1, 1, 1, 1
#24 = 1, 1, 1, 1
#28 = 1, 1, 1, 1
#32 = 1, 1, 1, 1
#36 = 1, 1, 1, 1
#40 = 1, 1, 1, 1
#44 = 1, 1, 1, 1
#48 = 1, 1, 1, 1
#52 = 1, 1, 1, 1
#56 = 1, 1, 1, 1
#60 = 1, 1, 1, 1
普通缓冲区:
private FloatBuffer mNormalBuffer = null;
#0 = 0.0, 0.0, 0.0
#3 = 1.0, 0.0, 0.0
#6 = 1.0, 1.0, 0.0
#9 = 0.0, 1.0, 0.0
#12 = 0.0, 0.0, 0.0
#15 = 1.0, 0.0, 0.0
#18 = 0.5, 1.0, 0.0
#21 = 0.0, 0.0, 0.0
#24 = 1.0, 0.0, 0.0
#27 = 0.5, 1.0, 0.0
#30 = 0.0, 0.0, 0.0
#33 = 1.0, 0.0, 0.0
#36 = 0.5, 1.0, 0.0
#39 = 0.0, 0.0, 0.0
#42 = 1.0, 0.0, 0.0
#45 = 0.5, 1.0, 0.0
指数缓冲区:
private ShortBuffer mIndexBuffer = null;
#0 = 0, 1, 3
#3 = 1, 2, 3
#6 = 4, 5, 6
#9 = 7, 8, 9
#12 = 10, 11, 12
#15 = 13, 14, 15
在我的脑海中组合顶点+面时,它等于一个金字塔,就像它应该的那样。简单的模型。我是这样画的:
// data above are put in these buffers
mColorBuffer.position(0);
mNormalBuffer.position(0);
mIndexBuffer.position(0);
mPositionBuffer.position(0);
GLES20.glVertexAttribPointer(mShader.getGLLocation(BaseShader.A_POSITION), 3, GLES20.GL_FLOAT, false,
0, mColorBuffer);
GLES20.glEnableVertexAttribArray(mShader.getGLLocation(BaseShader.A_POSITION));
GLES20.glVertexAttribPointer(mShader.getGLLocation(BaseShader.A_COLOR), 4, GLES20.GL_BYTE, false,
0, mColorBuffer);
GLES20.glEnableVertexAttribArray(mShader.getGLLocation(BaseShader.A_COLOR));
GLES20.glVertexAttribPointer(mShader.getGLLocation(BaseShader.A_NORMAL), 3, GLES20.GL_FLOAT, false,
0, mNormalBuffer);
GLES20.glEnableVertexAttribArray(mShader.getGLLocation(BaseShader.A_NORMAL));
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(mShader.getGLLocation(BaseShader.U_MVPMATRIX), 1, false, mMVPMatrix, 0);
GLES20.glDrawElements(GLES20.GL_TRIANGLE_FAN, mIndexBuffer.capacity(), GLES20.GL_UNSIGNED_SHORT, mIndexBuffer);
但是有一个对象,它看起来并不像金字塔,因此“摇晃”,即如果我翻译它(没有旋转,但代码看起来像这样(并且在绘图之前执行):
Matrix.translateM(mModelMatrix, 0, mTranslation[0], mTranslation[1], mTranslation[2]);
Matrix.scaleM(mModelMatrix, 0, mScale[0], mScale[1], mScale[1]);
Matrix.rotateM(mModelMatrix, 0, mRotation[0], 0, 1, 0);
Matrix.rotateM(mModelMatrix, 0, mRotation[1], 1, 0, 0);
Matrix.rotateM(mModelMatrix, 0, mRotation[2], 0, 0, 1);
Matrix.multiplyMM(mMVMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
在我看来,索引好像没有正确传输?不幸的是,只画了金字塔的一侧。
我必须为 glDrawElements 函数使用其他值吗?如果需要,我可以发布翻译动画的屏幕截图或屏幕截图。非常感谢您的帮助!
编辑:
如果这与它有任何关系:
我打电话给这些:
GLES20.glClearColor(0, 0, 0, 1);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glDepthFunc(GLES20.GL_LEQUAL);