I know it's probably better to use VBO instead, but I have personal reasons to use Vertex Arrays (beside my curiosity)
In C++, here the vertex arrays is used:
// "vertices" is an array of Vertex Struct
const char* data = reinterpret_cast<const char*>(vertices);
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0));
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 8));
glColorPointer(4, GL_FLOAT, sizeof(Vertex), data + 16));
glDrawArrays(GL_QUADS, 0, vertexCount);
the pointer passed and worked nicely in C++, however, I can't make it work in C# with OpenTK. I followed the official documentation and ended up with this codes:
Vertex[] vertices = // .. Fill some vertex here
unsafe
{
fixed (Vertex* data = vertices)
{
GL.VertexPointer(2, VertexPointerType.Float, Vertex.Stride, new IntPtr(data + 0));
GL.TexCoordPointer(2, TexCoordPointerType.Float, Vertex.Stride, new IntPtr(data + 8));
GL.ColorPointer(4, ColorPointerType.Float, Vertex.Stride, new IntPtr(data + 16));
// Draw the Vertices
GL.DrawArrays(PrimitiveType.Quads,
0,
vertices.length);
GL.Finish(); // Force OpenGL to finish rendering while the arrays are still pinned.
}
}
What I got is only blank white, nothing displayed.
I tried to use same vertices with my VBO implementation also similar vertices pointers code, it's working properly, so I think its not setup code fault and I'm sure Vertex.Stride
returning valid stride of Vertex
struct.
Any Ideas?