[Solved] OpenTK Static VBO Help
Posted: Tue Aug 14, 2012 12:59 am
I'm having a problem learning to use VBO's mainly drawing, Hoping that someone with alot more experience with OpenGL/TK can help.
This is the working code (pseudo C#) i used the OpenTK static vbo example for a template to VBO's
but didn't want to use interleaved arrays or a vertex struct
now i dont get how that works because if its pointing by bytes
a stride of 8 starting at a point of 8 would still be in the vertices array
GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float), new IntPtr(0));
GL.TexCoordPointer(2, TexCoordPointerType.Float, 4 * sizeof(float), new IntPtr(8));
would be wrong and the correct way would be
GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float), new IntPtr(0));
GL.TexCoordPointer(2, TexCoordPointerType.Float, 2 * sizeof(float), new IntPtr(48));
and i have tried GL.BindBuffer before each pointer but the textureCoords still read from vertices
and using an array as a parameter in the pointers doesn't work either
I'm hoping i just messed up on how it all works and its not a problem with OpenTK :P
This is the working code (pseudo C#) i used the OpenTK static vbo example for a template to VBO's
but didn't want to use interleaved arrays or a vertex struct
Code: Select all
float[] vertices =
{
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f
};
float[] textureCoords =
{
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f
};
short[] indices = { 0, 1, 2, 0, 2, 3 };
int vertexBuffer;
int textureBuffer;
int indexBuffer;
void Initialize()
{
//48 bytes
GL.GenBuffers(1, out vertexBuffer);
GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * BlittableValueType.StrideOf(vertices)), vertices, BufferUsageHint.StaticDraw);
//32 bytes
GL.GenBuffers(1, out textureBuffer);
GL.BindBuffer(BufferTarget.TextureBuffer, textureBuffer);
GL.BufferData(BufferTarget.TextureBuffer, (IntPtr)(textureCoords.Length * BlittableValueType.StrideOf(textureCoords)), textureCoords, BufferUsageHint.StaticDraw);
//16 bytes
GL.GenBuffers(1, out indexBuffer);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(short)), indices, BufferUsageHint.StaticDraw);
}
void Draw()
{
GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float), new IntPtr(0));
GL.EnableClientState(ArrayCap.VertexArray);
GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, textureID);
GL.TexCoordPointer(2, TexCoordPointerType.Float, 4 * sizeof(float), new IntPtr(8));
GL.EnableClientState(ArrayCap.TextureCoordArray);
GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedShort, new IntPtr(0));
}
a stride of 8 starting at a point of 8 would still be in the vertices array
GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float), new IntPtr(0));
GL.TexCoordPointer(2, TexCoordPointerType.Float, 4 * sizeof(float), new IntPtr(8));
would be wrong and the correct way would be
GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float), new IntPtr(0));
GL.TexCoordPointer(2, TexCoordPointerType.Float, 2 * sizeof(float), new IntPtr(48));
and i have tried GL.BindBuffer before each pointer but the textureCoords still read from vertices
and using an array as a parameter in the pointers doesn't work either
I'm hoping i just messed up on how it all works and its not a problem with OpenTK :P