Created
July 6, 2016 16:49
-
-
Save Nihlus/e45544693a8a7d506ce4ff711f43abea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int GenerateImageVertices() | |
{ | |
// Generate vertex positions | |
uint halfWidth = Image.GetResolution().X / 2; | |
uint halfHeight = Image.GetResolution().Y / 2; | |
/* | |
Vector2 upLeft = new Vector2(-halfWidth, halfHeight); | |
Vector2 upRight = new Vector2(halfWidth, halfHeight); | |
Vector2 downLeft = new Vector2(-halfWidth, -halfHeight); | |
Vector2 downRight = new Vector2(halfWidth, -halfHeight); | |
*/ | |
Vector2 upLeft = new Vector2(-1, 1); | |
Vector2 upRight = new Vector2(1, 1); | |
Vector2 downLeft = new Vector2(-1, -1); | |
Vector2 downRight = new Vector2(1, -1); | |
this.vertexPositions.Clear(); | |
this.vertexPositions.Add(upLeft); | |
this.vertexPositions.Add(upRight); | |
this.vertexPositions.Add(downLeft); | |
this.vertexPositions.Add(downRight); | |
// Buffer the generated vertices in the GPU | |
int bufferID; | |
GL.GenBuffers(1, out bufferID); | |
float[] vertices = GetVerticesAsArray(); | |
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferID); | |
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw); | |
// Generate vertex indices | |
List<ushort> vertexIndices = new List<ushort> {1, 0, 2, 2, 3, 1}; | |
GL.GenBuffers(1, out this.VertexIndexBufferID); | |
GL.BindBuffer(BufferTarget.ElementArrayBuffer, this.VertexIndexBufferID); | |
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(vertexIndices.Count * sizeof(ushort)), vertexIndices.ToArray(), BufferUsageHint.StaticDraw); | |
return bufferID; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment