Pages

VertexBuffer Class

Keeping inline with the last post, here is a class i use for rendering in my programs
I still intend on making another that uses arrays rather than lists, but this does the job for now :D

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/// <summary>
/// The type of vertex to use in buffer aswell as their value in bytes
/// </summary>
public enum VertexFormat
{
    XY = 8,                  //2D Vertex
    XY_COLOR = 12,           //2D Vertex with color
    XYZ = 12,                //Vertex
    XYZ_COLOR = 16,          //VertexColor
    XYZ_UV = 20,             //VertexUV
    XYZ_UV_COLOR = 24,       //VertexUVColor
    XYZ_NORMAL_UV = 32,      //VertexNormalUV
    XYZ_NORMAL_UV_COLOR = 36 //VertexNormalUVColor
}

public class VertexBuffer
{
    public VertexFormat Format { get; private set; }
    public int Stride { get; private set; }
    public int TriangleCount { get { return index_data.Count / 3; } }
    public int VertexCount { get { return vertex_data.Count / Stride; } }
    public int ByteCount { get { return vertex_data.Count; } }
    public bool IsLoaded { get; private set; }
    public BufferUsageHint UsageHint { get; set; }

    public int VBO { get { return id_vbo; } }
    public int EBO { get { return id_ebo; } }

    private int id_vbo;
    private int id_ebo;

    protected List<byte> vertex_data;
    protected List<ushort> index_data;

    public byte[] Vertices { get { return vertex_data.ToArray(); } }
    public ushort[] Indices { get { return index_data.ToArray(); } }

    public VertexBuffer(VertexFormat format)
    {
        Format = format;
        Stride = (int)format;
        UsageHint = BufferUsageHint.DynamicDraw;

        vertex_data = new List<byte>();
        index_data = new List<ushort>();
    }

    public void Clear()
    {
        vertex_data.Clear();
        index_data.Clear();
    }

    public void SetFormat(VertexFormat format)
    {
        Format = format;
        Stride = (int)format;
        Clear();
    }

    public void Set(byte[] vertices, ushort[] indices)
    {
        Clear();
        vertex_data.AddRange(vertices);
        if (indices != null)
            index_data.AddRange(indices);
    }

    /// <summary>
    /// Load vertex buffer
    /// :: store in memory
    /// </summary>
    public void Load()
    {
        if (IsLoaded) return;

        int count = vertex_data.Count / Stride;
        //VBO
        GL.GenBuffers(1, out id_vbo);
        GL.BindBuffer(BufferTarget.ArrayBuffer, id_vbo);
        GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(count * Stride), vertex_data.ToArray(), UsageHint);
        GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

        GL.GenBuffers(1, out id_ebo);
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, id_ebo);
        GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(index_data.Count * sizeof(short)), index_data.ToArray(), UsageHint);
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

        IsLoaded = true;
    }

    /// <summary>
    /// Reload the buffer data without destroying the buffers pointer to OpenGL
    /// </summary>
    public void Reload()
    {
        if (!IsLoaded) return;

        int count = vertex_data.Count / Stride;

        GL.BindBuffer(BufferTarget.ArrayBuffer, id_vbo);
        GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(count * Stride), IntPtr.Zero, UsageHint);
        GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(count * Stride), vertex_data.ToArray(), UsageHint);
        GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

        GL.BindBuffer(BufferTarget.ElementArrayBuffer, id_ebo);
        GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(index_data.Count * sizeof(short)), IntPtr.Zero, UsageHint);
        GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(index_data.Count * sizeof(short)), index_data.ToArray(), UsageHint);
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
    }

    /// <summary>
    /// Unload vertex buffer from OpenGL
    /// :: release memory
    /// </summary>
    public void Unload()
    {
        if (!IsLoaded) return;

        int count = vertex_data.Count / Stride;

        GL.BindBuffer(BufferTarget.ArrayBuffer, id_vbo);
        GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(count * Stride), IntPtr.Zero, UsageHint);

        GL.BindBuffer(BufferTarget.ElementArrayBuffer, id_ebo);
        GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(index_data.Count * sizeof(short)), IntPtr.Zero, UsageHint);

        GL.DeleteBuffers(1, ref id_vbo);
        GL.DeleteBuffers(1, ref id_ebo);

        IsLoaded = false;
    }

    public void Bind()
    {
        if (!IsLoaded) return;

        GL.BindBuffer(BufferTarget.ArrayBuffer, id_vbo);

        if (Format == VertexFormat.XY)
        {
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.VertexPointer(2, VertexPointerType.Float, Stride, new IntPtr(0));
        }
        else if (Format == VertexFormat.XY_COLOR)
        {
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            GL.VertexPointer(2, VertexPointerType.Float, Stride, new IntPtr(0));
            GL.ColorPointer(4, ColorPointerType.UnsignedByte, Stride, new IntPtr(8));
        }
        else if (Format == VertexFormat.XYZ)
        {
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.VertexPointer(3, VertexPointerType.Float, Stride, new IntPtr(0));
        }
        else if (Format == VertexFormat.XYZ_COLOR)
        {
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            GL.VertexPointer(3, VertexPointerType.Float, Stride, new IntPtr(0));
            GL.ColorPointer(4, ColorPointerType.UnsignedByte, Stride, new IntPtr(12));
        }
        else if (Format == VertexFormat.XYZ_UV)
        {
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.VertexPointer(3, VertexPointerType.Float, Stride, new IntPtr(0));
            GL.TexCoordPointer(2, TexCoordPointerType.Float, Stride, new IntPtr(12));
        }
        else if (Format == VertexFormat.XYZ_UV_COLOR)
        {
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            GL.VertexPointer(3, VertexPointerType.Float, Stride, new IntPtr(0));
            GL.TexCoordPointer(2, TexCoordPointerType.Float, Stride, new IntPtr(12));
            GL.ColorPointer(4, ColorPointerType.UnsignedByte, Stride, new IntPtr(20));
        }
        else if (Format == VertexFormat.XYZ_NORMAL_UV)
        {
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.NormalArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.VertexPointer(3, VertexPointerType.Float, Stride, new IntPtr(0));
            GL.NormalPointer(NormalPointerType.Float, Stride, new IntPtr(12));
            GL.TexCoordPointer(2, TexCoordPointerType.Float, Stride, new IntPtr(24));
        }
        else if (Format == VertexFormat.XYZ_NORMAL_UV_COLOR)
        {
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.NormalArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            GL.VertexPointer(3, VertexPointerType.Float, Stride, new IntPtr(0));
            GL.NormalPointer(NormalPointerType.Float, Stride, new IntPtr(12));
            GL.TexCoordPointer(2, TexCoordPointerType.Float, Stride, new IntPtr(24));
            GL.ColorPointer(4, ColorPointerType.UnsignedByte, Stride, new IntPtr(32));
        }

        GL.BindBuffer(BufferTarget.ElementArrayBuffer, id_ebo);
        GL.DrawElements(BeginMode.Triangles, index_data.Count, DrawElementsType.UnsignedShort, IntPtr.Zero);

        GL.DisableClientState(ArrayCap.VertexArray);
        GL.DisableClientState(ArrayCap.NormalArray);
        GL.DisableClientState(ArrayCap.TextureCoordArray);
        GL.DisableClientState(ArrayCap.ColorArray);
    }

    public void Dispose()
    {
        Unload();
        Clear();
        vertex_data = null;
        index_data = null;
    }

    public void Join(VertexBuffer buffer)
    {
        int count = vertex_data.Count / Stride;

        //Vertices
        vertex_data.AddRange(buffer.vertex_data.ToArray());

        //Indices
        ushort[] indices = buffer.index_data.ToArray();
        for (int i = 0; i < indices.Length; i++)
        {
            indices[i] += (ushort)count;
        }

        index_data.AddRange(indices);
    }

    /// <summary>
    /// Add indices in order of vertices length,
    /// this is if you dont want to set indices and just index from vertex-index
    /// </summary>
    public void IndexFromLength(bool cw = false)
    {
        int count = vertex_data.Count / Stride;
        ushort[] indices = new ushort[count];
        for (int i = 0; i < count; i++)
        {
            indices[i] = (ushort)i;
        }

        if (cw)
            Array.Reverse(indices);

        AddIndices(indices);
    }

    public void AddIndex(ushort indexA, ushort indexB, ushort indexC)
    {
        index_data.Add(indexA);
        index_data.Add(indexB);
        index_data.Add(indexC);
    }

    public void AddIndices(ushort[] indices)
    {
        index_data.AddRange(indices);
    }

    /// <summary>
    /// XY
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    public void AddVertex(float x, float y)
    {
        if (Format != VertexFormat.XY)
            throw new FormatException("vertex must be of the same format type as buffer");

        vertex_data.AddRange(BitConverter.GetBytes(x));
        vertex_data.AddRange(BitConverter.GetBytes(y));
    }

    /// <summary>
    /// XY_COLOR
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="color"></param>
    public void AddVertex(float x, float y, uint color)
    {
        if (Format != VertexFormat.XY_COLOR)
            throw new FormatException("vertex must be of the same format type as buffer");

        vertex_data.AddRange(BitConverter.GetBytes(x));
        vertex_data.AddRange(BitConverter.GetBytes(y));
        vertex_data.AddRange(BitConverter.GetBytes(color));
    }

    /// <summary>
    /// XYZ
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="z"></param>
    public void AddVertex(float x, float y, float z)
    {
        if (Format != VertexFormat.XYZ)
            throw new FormatException("vertex must be of the same format type as buffer");

        vertex_data.AddRange(BitConverter.GetBytes(x));
        vertex_data.AddRange(BitConverter.GetBytes(y));
        vertex_data.AddRange(BitConverter.GetBytes(z));
    }

    /// <summary>
    /// XYZ_COLOR
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="z"></param>
    /// <param name="color"></param>
    public void AddVertex(float x, float y, float z, uint color)
    {
        if (Format != VertexFormat.XYZ_COLOR)
            throw new FormatException("vertex must be of the same format type as buffer");

        vertex_data.AddRange(BitConverter.GetBytes(x));
        vertex_data.AddRange(BitConverter.GetBytes(y));
        vertex_data.AddRange(BitConverter.GetBytes(z));
        vertex_data.AddRange(BitConverter.GetBytes(color));
    }

    /// <summary>
    /// XYZ_UV
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="z"></param>
    /// <param name="u"></param>
    /// <param name="v"></param>
    public void AddVertex(float x, float y, float z, float u, float v)
    {
        if (Format != VertexFormat.XYZ_UV)
            throw new FormatException("vertex must be of the same format type as buffer");

        vertex_data.AddRange(BitConverter.GetBytes(x));
        vertex_data.AddRange(BitConverter.GetBytes(y));
        vertex_data.AddRange(BitConverter.GetBytes(z));
        vertex_data.AddRange(BitConverter.GetBytes(u));
        vertex_data.AddRange(BitConverter.GetBytes(v));
    }

    /// <summary>
    /// XYZ_UV_COLOR
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="z"></param>
    /// <param name="u"></param>
    /// <param name="v"></param>
    /// <param name="color"></param>
    public void AddVertex(float x, float y, float z, float u, float v, uint color)
    {
        if (Format != VertexFormat.XYZ_UV_COLOR)
            throw new FormatException("vertex must be of the same format type as buffer");

        vertex_data.AddRange(BitConverter.GetBytes(x));
        vertex_data.AddRange(BitConverter.GetBytes(y));
        vertex_data.AddRange(BitConverter.GetBytes(z));
        vertex_data.AddRange(BitConverter.GetBytes(u));
        vertex_data.AddRange(BitConverter.GetBytes(v));
        vertex_data.AddRange(BitConverter.GetBytes(color));
    }

    /// <summary>
    /// XYZ_NORMAL_UV
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="z"></param>
    /// <param name="nx"></param>
    /// <param name="ny"></param>
    /// <param name="nz"></param>
    /// <param name="u"></param>
    /// <param name="v"></param>
    public void AddVertex(float x, float y, float z, float nx, float ny, float nz, float u, float v)
    {
        if (Format != VertexFormat.XYZ_NORMAL_UV)
            throw new FormatException("vertex must be of the same format type as buffer");

        vertex_data.AddRange(BitConverter.GetBytes(x));
        vertex_data.AddRange(BitConverter.GetBytes(y));
        vertex_data.AddRange(BitConverter.GetBytes(z));
        vertex_data.AddRange(BitConverter.GetBytes(nx));
        vertex_data.AddRange(BitConverter.GetBytes(ny));
        vertex_data.AddRange(BitConverter.GetBytes(nz));
        vertex_data.AddRange(BitConverter.GetBytes(u));
        vertex_data.AddRange(BitConverter.GetBytes(v));
    }

    /// <summary>
    /// XYZ_NORMAL_UV_COLOR
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="z"></param>
    /// <param name="nx"></param>
    /// <param name="ny"></param>
    /// <param name="nz"></param>
    /// <param name="u"></param>
    /// <param name="v"></param>
    /// <param name="color"></param>
    public void AddVertex(float x, float y, float z, float nx, float ny, float nz, float u, float v, uint color)
    {
        if (Format != VertexFormat.XYZ_NORMAL_UV_COLOR)
            throw new FormatException("vertex must be of the same format type as buffer");

        vertex_data.AddRange(BitConverter.GetBytes(x));
        vertex_data.AddRange(BitConverter.GetBytes(y));
        vertex_data.AddRange(BitConverter.GetBytes(z));
        vertex_data.AddRange(BitConverter.GetBytes(nx));
        vertex_data.AddRange(BitConverter.GetBytes(ny));
        vertex_data.AddRange(BitConverter.GetBytes(nz));
        vertex_data.AddRange(BitConverter.GetBytes(u));
        vertex_data.AddRange(BitConverter.GetBytes(v));
        vertex_data.AddRange(BitConverter.GetBytes(color));
    }
}

Usage Example


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
private VertexBuffer buffer;

public void Load()
{
    buffer = new VertexBuffer(VertexFormat.XYZ_COLOR);
    buffer.AddVertex(  0.0f,    0.0f, 0.0f, 0xFF0000FF);
    buffer.AddVertex(100.0f,    0.0f, 0.0f, 0xFF00FF00);
    buffer.AddVertex(  0.0f, -100.0f, 0.0f, 0xFFFF0000);
    buffer.AddIndices(new ushort[3] { 2, 1, 0 });
    buffer.Load();
}

public void Render()
{
    GL.Translate(-50, 50, -100);
    buffer.Bind();
}

OpenTK Vertex Buffer Object [VBO]

Hope it help's

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//A simple 3D vertex
public struct Vertex
{
    public float X, Y, Z;
    public Vertex(float x, float y, float z)
    {
        X = x; Y = y; Z = z;
    }

    //The stride of this vertex
    //3 floats 4 bytes each
    //if you dont like counting bytes you can get this value a few different ways
    //System.Runtime.InteropServices.Marshal.SizeOf(new Vertex());
    //OpenTK.BlittableValueType.StrideOf(new Vertex());
    public const int Stride = 12;
}

//ID of the vertex buffer we will use
private int ID_VBO;
//ID of the element buffer
private int ID_EBO;

//You are not limited to using a struct
//you can use (float[], byte[], int[]) really anything that can hold data
//then you could stride the array with
//Vertices.Length * sizeof(float)
private Vertex[] Vertices;
//I use ushort, for the simple reasons of
//i know im never going to index a negative value
//and 65,535 is a good vertex limit
//but you can use whatever just remember the max_value is your limit
private ushort[] Indices;

//Keep in mind that you are using memory for everything
//the best way to think about any GL buffer is as if its byte[] or ByteArray/ByteBuffer

//Only need to call this once, place it in your programs initialize/load method
private void InitializeVBO()
{
    //Initialize vertex data and index data

    //Simple triangle in CW winding
    Vertices = new Vertex[3]
    {
        new Vertex(  0.0f,   0.0f, 0.0f),
        new Vertex(100.0f,   0.0f, 0.0f),
        //gl y coords are reversed depending on what direction you consider is down
        new Vertex(  0.0f, -100.0f, 0.0f)
    };

    //Index data for what order to draw vertices
    Indices = new ushort[3]
    {
        //This is also something to keep in mind
        //reversing your winding has no performance advantage, 
        //dont let someone tell you otherwise, all data gets read the same way
        //its always easier to change a few indices than edit vertices
        //since you are most likely in CCW winding since that is GL's default
        //i reversed it since the vertices are in CW :D
        //you can change GL's default winding by GL.FrontFace
        0, 1, 2
    };
            
    //Setting up the vertex buffer
    //data has to be initialize before this part.
            
    //Generate a single buffer
    GL.GenBuffers(1, out ID_VBO);
    //Tell gl we are going to be using this buffer as an Array_Buffer for vertex data
    GL.BindBuffer(BufferTarget.ArrayBuffer, ID_VBO);
    //Add our vertex data to it, essentially the same thing as Array.Copy if it were a byte[]
    //1: targeting the Array_Buffer
    //2: for this we will need the full length in bytes of our vertex data
    //3: the data we want in this new buffer
    //4: we are only going to set this once so our usage will be static and draw/write
    //basically in full we're are telling gl that we want a write-only buffer that is locked :P
    GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * Vertex.Stride), Vertices, BufferUsageHint.StaticDraw);
    //This is just good practice
    GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

    //Generate another single buffer
    GL.GenBuffers(1, out ID_EBO);
    //Tell gl we are going to be using this buffer as an Element_Buffer for indexing data already bound to an Array_Buffer
    GL.BindBuffer(BufferTarget.ElementArrayBuffer, ID_EBO);
    //the same as above only changing the data
    GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(Indices.Length * sizeof(ushort)), Indices, BufferUsageHint.StaticDraw);
    GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
}

//This will need to be called everyframe you want to see the buffer data so use in OnRenderFrame
//or any method with a GL render context.
public void RenderVBO()
{
    GL.PushMatrix();

    //So you can see it onscreen :P
    GL.Translate(-50, 50, -100);

    //We dont have color data so it will resort to the last use GL_Color
    GL.Color3(1.0f, 1.0f, 1.0f);

    //since we only have position data thats all that needs to be writen to gl
    //if you enable another as in ArrayCap.ColorArray and have no color data
    //you will get an outofbounds/outofmemory exception because there is not data to read
    //so good practice to enable/disable so you dont run into that problem when using
    //different types of vertices :D
    //Although if you know what type you are going to use throughout the whole process
    //you can remove enable/disable from this method and add enable to your init function
    GL.EnableClientState(ArrayCap.VertexArray);

    //Bind our vertex data
    GL.BindBuffer(BufferTarget.ArrayBuffer, ID_VBO);
    //Tell gl where to start reading our position data in the length of out Vertex.Stride
    //so we will begin reading 3 floats with a length of 12 starting at 0
    GL.VertexPointer(3, VertexPointerType.Float, Vertex.Stride, 0);

    GL.BindBuffer(BufferTarget.ElementArrayBuffer, ID_EBO);
    //tell gl to draw from the bound Array_Buffer in the form of triangles with a length of indices of type ushort starting at 0
    GL.DrawElements(BeginMode.Triangles, Indices.Length, DrawElementsType.UnsignedShort, 0);

    //unlike above you will have to unbind after the data is indexed else the Element_Buffer would have nothing to index
    GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
    GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

    //Remember to disable
    GL.DisableClientState(ArrayCap.VertexArray);

    GL.PopMatrix();
}

Also some good references
http://www.opengl.org/wiki/Vertex_Specification
http://www.opengl.org/wiki/Buffer_Object
http://www.opentk.com/doc/graphics/geometry/vertex-buffer-objects