Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. private void GenBuffers()
  2. {
  3. //This is our vertex data, just positions
  4. Vector3[] meshVerts =
  5. {
  6. new Vector3(-1f, -1f, -1f),
  7. new Vector3(1f, -1f, -1f),
  8. new Vector3(1f, 1f, -1f),
  9. new Vector3(-1f, 1f, -1f),
  10. new Vector3(-1f, -1f, 1f),
  11. new Vector3(1f, -1f, 1f),
  12. new Vector3(1f, 1f, 1f),
  13. new Vector3(-1f, 1f, 1f),
  14. };
  15.  
  16. //These are indexes (like the collision mesh uses)
  17. int[] meshIndexes =
  18. {
  19. //front
  20. 0, 7, 3,
  21. 0, 4, 7,
  22. //back
  23. 1, 2, 6,
  24. 6, 5, 1,
  25. //left
  26. 0, 2, 1,
  27. 0, 3, 2,
  28. //right
  29. 4, 5, 6,
  30. 6, 7, 4,
  31. //top
  32. 2, 3, 6,
  33. 6, 3, 7,
  34. //bottom
  35. 0, 1, 5,
  36. 0, 5, 4
  37. };
  38.  
  39. //Generate a buffer on the GPU and get the ID to it
  40. GL.GenBuffers(1, out _glVbo);
  41.  
  42. //This "binds" the buffer. Once a buffer is bound, all actions are relative to it until another buffer is bound.
  43. GL.BindBuffer(BufferTarget.ArrayBuffer, _glVbo);
  44.  
  45. //This uploads data to the currently bound buffer from the CPU -> GPU. This only needs to be done with the data changes (ie: you edited a vertexes position on the cpu side)
  46. GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(meshVerts.Length * Vector3.SizeInBytes), meshVerts,
  47. BufferUsageHint.StaticDraw);
  48.  
  49. //Now we're going to repeat the same process for the Element buffer, which is what OpenGL calls indicies. (Notice how it's basically identical?)
  50. GL.GenBuffers(1, out _glEbo);
  51. GL.BindBuffer(BufferTarget.ElementArrayBuffer, _glEbo);
  52. GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(meshIndexes.Length * 4), meshIndexes,
  53. BufferUsageHint.StaticDraw);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement