2011-10-23 17 views
0

我嘗試使用Ope繪製網格 調用GL.DrawElements時,出現以下異常。MonoTouch/OpenGL ES:使用GL.DrawElements繪製時出現異常

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 

那繪圖代碼:

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

編輯:格式問題...和堆棧溢出不想我犯下一些事。

+0

可能不是你的錯誤,但目前所有啓用頂點attribs從相同的緩衝區**和**使用相同的偏移量來源數據,所以從完全相同的數據。這有效,但可能不是你想要的。此外,你正在畫一組只有1個頂點的三角形,所以甚至沒有一個完整的三角形。所以,即使你沒有得到一個錯誤,也沒有任何東西會被畫出來。 –

+0

改變了它,仍然是一樣的錯誤。 –

+0

我跟你說過這不是錯誤。但無論如何,這是錯誤的。 –

回答

1

事實證明「ElementArrayBufferBinding」不用於綁定某些東西。相反,我必須使用「ElementArrayBuffer」。

+0

當然,'ArrayBuffer'也一樣。 –

相關問題