Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void GenBuffers()
- {
- //This is our vertex data, just positions
- Vector3[] meshVerts =
- {
- new Vector3(-1f, -1f, -1f),
- new Vector3(1f, -1f, -1f),
- new Vector3(1f, 1f, -1f),
- new Vector3(-1f, 1f, -1f),
- new Vector3(-1f, -1f, 1f),
- new Vector3(1f, -1f, 1f),
- new Vector3(1f, 1f, 1f),
- new Vector3(-1f, 1f, 1f),
- };
- //These are indexes (like the collision mesh uses)
- int[] meshIndexes =
- {
- //front
- 0, 7, 3,
- 0, 4, 7,
- //back
- 1, 2, 6,
- 6, 5, 1,
- //left
- 0, 2, 1,
- 0, 3, 2,
- //right
- 4, 5, 6,
- 6, 7, 4,
- //top
- 2, 3, 6,
- 6, 3, 7,
- //bottom
- 0, 1, 5,
- 0, 5, 4
- };
- //Generate a buffer on the GPU and get the ID to it
- GL.GenBuffers(1, out _glVbo);
- //This "binds" the buffer. Once a buffer is bound, all actions are relative to it until another buffer is bound.
- GL.BindBuffer(BufferTarget.ArrayBuffer, _glVbo);
- //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)
- GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(meshVerts.Length * Vector3.SizeInBytes), meshVerts,
- BufferUsageHint.StaticDraw);
- //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?)
- GL.GenBuffers(1, out _glEbo);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, _glEbo);
- GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(meshIndexes.Length * 4), meshIndexes,
- BufferUsageHint.StaticDraw);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement