Jun 6, 2012 at 11:17 PM
Edited Jun 8, 2012 at 12:23 PM
I've been trying to get buffer objects to work for the past several days, and I've tried this code:
which I got from this discussion:
But when I compile it, I just get an empty white box. There's no errors, but there's no triangles, either. What could cause a problem like
that? Is something wrong with the buffer initialization? The gl.DrawElements call?
Also, gl.DrawElements won't let me just give three parameters like it has in that example code. Intellisense has them as (uint mode, int
count, uint type, IntPtr indices). Has it somehow been updated since that discussion was created? Trying the code with gl.DrawElements(OpenGL.GL_TRIANGLES, indices.Length, OpenGL.GL_UNSIGNED_INT, new IntPtr(0)); results in the white box.
Also, Dave, was the sample mentioned in that discussion ever released? It sounds like it would be useful when it comes to learning Vertex Buffer
Update - I'm pretty sure it's not a problem with the buffer initialization, since I can use gl.DrawArrays just fine, and the problem only comes up when
I uncomment gl.DrawElements. The part that's getting me is the last parameter in the gl.DrawElements function, that IntPtr. Using more unsafe code to get an IntPtr that points to the first int of the indices array results in a black box, not a
white one, so I guess that's progress. :)
I've seen some tutorials that say the index array can only be a ubyte, ushort, or uint array. If that's the case, how come gl.DrawElements wants
an IntPtr as the fourth argument and not UIntPtr?
The actual code inside openGLControl_OpenGlDraw for gl.DrawElements is:
fixed (int* inters = indices)
var interPtr = new IntPtr(inters);
gl.DrawElements(OpenGL.GL_TRIANGLES, 3, OpenGL.GL_FLOAT, interPtr);