1

私はチュートリアルhttp://www.learnopengles.comに従い、 OpenGL ES の操作方法をさらに学習しましたが、球体を表示するのに苦労しています。

Blender で測地線球を作成し、頂点と描画順序をインポートしましたが、球を呼び出すたびにアプリがクラッシュします。

完全なレンダリング ファイルへのリンクを含めますが、問題があると思われる重要な点についても指摘します。

ここでバッファが作成されます。球または球の描画順序ポイントをバッファリングする方法にアプリの問題があるかどうかはわかりません。

// Initialize the buffers.
    mCubePositions = ByteBuffer.allocateDirect(cubePositionData.length * mBytesPerFloat)
    .order(ByteOrder.nativeOrder()).asFloatBuffer();                            
    mCubePositions.put(cubePositionData).position(0);

    mSpherePositions = ByteBuffer.allocateDirect(spherePositionData.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
    mSpherePositions.put(spherePositionData).position(0);

    ByteBuffer dlb = ByteBuffer.allocateDirect(sphereDrawOrder.length * 2).order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(sphereDrawOrder);
    drawListBuffer.position(0);


    mCubeColors = ByteBuffer.allocateDirect(cubeColorData.length * mBytesPerFloat)
    .order(ByteOrder.nativeOrder()).asFloatBuffer();                            
    mCubeColors.put(cubeColorData).position(0);

    mCubeNormals = ByteBuffer.allocateDirect(cubeNormalData.length * mBytesPerFloat)
    .order(ByteOrder.nativeOrder()).asFloatBuffer();                            
    mCubeNormals.put(cubeNormalData).position(0);

そして、これが球体を描画するクラスです。球の色や法線がないので、それらの部分を削除しました。それがモヤモヤする原因なの?

private void drawSphere()
{       
    // Pass in the position information
    mSpherePositions.position(0);       
    GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
            0, mSpherePositions);        

    GLES20.glEnableVertexAttribArray(mPositionHandle);        

    // Pass in the color information


    // Pass in the normal information


    // 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]);

    // Draw the sphere.
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, sphereDrawOrder.length,
            GLES20.GL_UNSIGNED_SHORT, drawListBuffer);                              
}

クラッシュするたびに、 //Draw the sphere の後のコードに何か問題があることがわかります。何らかの理由で glDrawElements が好きではありません。

参照用の完全なレンダリング スクリプトは次のとおりです: http://pastebin.com/Y1WU27hz

これについて何か洞察があれば、私は感謝します。

4

0 に答える 0