2011-10-23 11 views
0

Opeでメッシュを描画しようとしました GL.DrawElementsを呼び出すときに次の例外があります。MonoTouch/OpenGL ES:GL.DrawElementsで描画するときの例外

// Bind buffers 
GL.BindBuffer(All.ArrayBufferBinding, _ElementsBuffer); 
GL.BindBuffer(All.ElementArrayBufferBinding, _IndexBuffer); 

for (int i = 0; i < _Data.Length; i++) 
{ 
    VertexData data = _Data[i]; 
    // Using fixed size here, just using 3 floats for the drawing 
    GL.VertexAttribPointer(i, data.Size, data.Type, data.Normalized, 12, new IntPtr(0)); 
    GL.EnableVertexAttribArray(i); 
} 

// Draw elements 
GL.DrawElements(All.Triangles, _Triangles, All.UnsignedShort, IntPtr.Zero); 

// Unbind buffers 
GL.BindBuffer(All.ArrayBufferBinding, 0); 
GL.BindBuffer(All.ElementArrayBufferBinding, 0); 

そしてここで、初期化のためのコードです:

public VertexBuffer(UInt16[] indices, Byte[] data, params VertexData[] vertexData) 
{ 
    _Data = vertexData; 
    _Triangles = indicies.Length/3; 

    // Generate buffer id's 
    Int32[] buffers = new Int32[2]; 
    GL.GenBuffers(2, buffers); 
    _IndexBuffer = buffers[0]; 
    _ElementsBuffer = buffers[1]; 



    unsafe 
    { 
     // Bind indices buffer 
     GL.BindBuffer(All.ElementArrayBufferBinding, _IndexBuffer); 

     // Buffer indices 
     fixed (UInt16* f = indices) 
     { 
      GL.BufferData(All.ElementArrayBuffer, 
         new IntPtr(2 * indices.Length), 
         new IntPtr((void*)f), 
         All.StaticDraw); 

     } 

     // Bind data buffer 
     GL.BindBuffer(All.ArrayBufferBinding, _ElementsBuffer); 

     // Buffer vertex data 
     fixed (Byte* f = data) { 
      GL.BufferData(All.ArrayBuffer, 
         new IntPtr(data.Length), 
         new IntPtr((void*)f), 
         All.StaticDraw); 
     } 
    } 


    // Unbind buffers 
    GL.BindBuffer(All.ArrayBufferBinding, 0); 
    GL.BindBuffer(All.ElementArrayBufferBinding, 0); 
} 

編集:フォーマットの問題...と、スタックオーバーフローが私を望んでいないが、描画コードザッツ

Stacktrace: 

at (wrapper managed-to-native) OpenTK.Graphics.ES20.GL/Core.DrawElements(OpenTK.Graphics.ES20.All,int,OpenTK.Graphics.ES20.All,intptr) <IL 0x00026, 0xffffffff> 
at OpenTK.Graphics.ES20.GL.DrawElements (OpenTK.Graphics.ES20.All,int,OpenTK.Graphics.ES20.All,intptr) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/OpenGLES/OpenTK/Graphics/ES20.iPhone/GL.cs:1659 
at App.PipedreamWrapper.Resource.Model.VertexBuffer.Render() [0x00067] in /Users/felixk/Projects/Windkraft/App/PipedreamWrapper/Resource/Model/VertexBuffer.cs:74 

何かをコミットする。

+0

おそらくあなたのエラーではありませんが、現時点で有効になっている頂点属性はすべて同じデータから同じオフセットを使用して同じバッファ**と**からデータを取り込みます。これは機能しますが、おそらくあなたがそれを望む方法ではありません。また、頂点が1つしかない三角形のセットを描画しているため、完全な三角形もありません。したがって、エラーが発生しなくても、何も描画されません。 –

+0

変更しましたが、それでも同じエラーです。 –

+0

私はあなたに言ったことは誤りではない。とにかくそれは間違っていた。 –

答えて

1

「ElementArrayBufferBinding」は何かをバインドするために使用されていません。代わりに、私は "ElementArrayBuffer"を使用する必要があります。

+0

もちろん、 'ArrayBuffer'と同じです。 –

関連する問題