thomasfn

GL3: Mesh

Sep 1st, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public void Compile()
  2. {
  3. // Generate the positions VBO
  4. GL.GenBuffers(1, out iVBOPositions);
  5. GL.BindBuffer(BufferTarget.ArrayBuffer, iVBOPositions);
  6. Vector3[] positions = lstPositions.ToArray();
  7. GL.BufferData<Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(positions.Length * Vector3.SizeInBytes), positions, BufferUsageHint.StaticDraw);
  8. positions = null;
  9.  
  10. // Generate the normals VBO
  11. GL.GenBuffers(1, out iVBONormals);
  12. GL.BindBuffer(BufferTarget.ArrayBuffer, iVBONormals);
  13. Vector3[] normals = lstNormals.ToArray();
  14. GL.BufferData<Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(normals.Length * Vector3.SizeInBytes), normals, BufferUsageHint.StaticDraw);
  15. normals = null;
  16.  
  17. // Generate the indices VBO
  18. GL.GenBuffers(1, out iVBOIndices);
  19. GL.BindBuffer(BufferTarget.ElementArrayBuffer, iVBOIndices);
  20. uint[] indices = lstIndices.ToArray();
  21. GL.BufferData<uint>(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(uint)), indices, BufferUsageHint.StaticDraw);
  22. indices = null;
  23.  
  24. // Generate the VAO
  25. GL.GenVertexArrays(1, out iVAO);
  26. GL.BindVertexArray(iVAO);
  27. GL.BindBuffer(BufferTarget.ArrayBuffer, iVBOPositions);
  28. GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, true, 0, 0);
  29. GL.BindBuffer(BufferTarget.ArrayBuffer, iVBONormals);
  30. GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, true, 0, 0);
  31.  
  32. // Cleanup
  33. GL.BindVertexArray(0);
  34. GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
  35. GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment