Created
July 6, 2016 16:50
-
-
Save Nihlus/42686ea4d369ff7a731403944fa43dc7 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
public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix) | |
{ | |
if (!IsInitialized) | |
{ | |
return; | |
} | |
GL.UseProgram(this.Plain2DShaderID); | |
// Render the object | |
// Send the vertices to the shader | |
GL.EnableVertexAttribArray(0); | |
GL.BindBuffer(BufferTarget.ArrayBuffer, this.VertexBufferID); | |
GL.VertexAttribPointer( | |
0, | |
2, | |
VertexAttribPointerType.Float, | |
false, | |
0, | |
0); | |
// Send the UV coordinates to the shader | |
GL.EnableVertexAttribArray(1); | |
GL.BindBuffer(BufferTarget.ArrayBuffer, this.UVBufferID); | |
GL.VertexAttribPointer( | |
1, | |
2, | |
VertexAttribPointerType.Float, | |
false, | |
0, | |
0); | |
// Set the texture ID as a uniform sampler in unit 0 | |
GL.ActiveTexture(TextureUnit.Texture0); | |
GL.BindTexture(TextureTarget.Texture2D, this.GLTextureID); | |
int textureVariableHandle = GL.GetUniformLocation(this.Plain2DShaderID, "imageTextureSampler"); | |
int textureUnit = 0; | |
GL.Uniform1(textureVariableHandle, 1, ref textureUnit); | |
// Set the model view matrix | |
Matrix4 modelTranslation = Matrix4.CreateTranslation(new Vector3(0.0f, 0.0f, 0.0f)); | |
Matrix4 modelScale = Matrix4.Scale(new Vector3(1.0f, 1.0f, 1.0f)); | |
//Matrix4 modelViewProjection = modelScale * modelTranslation * viewMatrix * projectionMatrix; | |
Matrix4 modelViewProjection = modelScale * modelTranslation * viewMatrix * projectionMatrix; | |
// Send the model matrix to the shader | |
int projectionShaderVariableHandle = GL.GetUniformLocation(this.Plain2DShaderID, "ModelViewProjection"); | |
GL.UniformMatrix4(projectionShaderVariableHandle, false, ref modelViewProjection); | |
// Finally, draw the image | |
GL.BindBuffer(BufferTarget.ElementArrayBuffer, this.VertexIndexBufferID); | |
GL.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0); | |
// Release the attribute arrays | |
GL.DisableVertexAttribArray(0); | |
GL.DisableVertexAttribArray(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment