Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Compile()
- {
- // Generate the positions VBO
- GL.GenBuffers(1, out iVBOPositions);
- GL.BindBuffer(BufferTarget.ArrayBuffer, iVBOPositions);
- Vector3[] positions = lstPositions.ToArray();
- GL.BufferData<Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(positions.Length * Vector3.SizeInBytes), positions, BufferUsageHint.StaticDraw);
- positions = null;
- // Generate the normals VBO
- GL.GenBuffers(1, out iVBONormals);
- GL.BindBuffer(BufferTarget.ArrayBuffer, iVBONormals);
- Vector3[] normals = lstNormals.ToArray();
- GL.BufferData<Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(normals.Length * Vector3.SizeInBytes), normals, BufferUsageHint.StaticDraw);
- normals = null;
- // Generate the indices VBO
- GL.GenBuffers(1, out iVBOIndices);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, iVBOIndices);
- uint[] indices = lstIndices.ToArray();
- GL.BufferData<uint>(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(uint)), indices, BufferUsageHint.StaticDraw);
- indices = null;
- // Generate the VAO
- GL.GenVertexArrays(1, out iVAO);
- GL.BindVertexArray(iVAO);
- GL.BindBuffer(BufferTarget.ArrayBuffer, iVBOPositions);
- GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, true, 0, 0);
- GL.BindBuffer(BufferTarget.ArrayBuffer, iVBONormals);
- GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, true, 0, 0);
- // Cleanup
- GL.BindVertexArray(0);
- GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment