private void ApplyNormalMatrix(OpenGL gl) { gl.UniformMatrix3(Uniforms["NormalMatrix"], 1, false, NormalMatrix.to_array()); }
private void DrawTrefoilCelShaded(OpenGL gl) { // Use the shader program. gl.UseProgram(shaderProgram.ProgramObject); // Set the variables for the shader program. gl.Uniform3(toonUniforms.DiffuseMaterial, 0f, 0.75f, 0.75f); gl.Uniform3(toonUniforms.AmbientMaterial, 0.04f, 0.04f, 0.04f); gl.Uniform3(toonUniforms.SpecularMaterial, 0.5f, 0.5f, 0.5f); gl.Uniform1(toonUniforms.Shininess, 50f); // Set the light position. gl.Uniform3(toonUniforms.LightPosition, 1, new float[4] { 0.25f, 0.25f, 1f, 0f }); // Set the matrices. gl.UniformMatrix4(toonUniforms.Projection, 1, false, projection.AsColumnMajorArrayFloat); gl.UniformMatrix4(toonUniforms.Modelview, 1, false, modelView.AsColumnMajorArrayFloat); gl.UniformMatrix3(toonUniforms.NormalMatrix, 1, false, normalMatrix.AsColumnMajorArrayFloat); // Bind the vertex and index buffer. gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBuffer); gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer); gl.EnableVertexAttribArray(attrPosition); gl.EnableVertexAttribArray(attrNormal); // Draw the geometry, straight from the vertex buffer. gl.VertexAttribPointer(attrPosition, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Zero); int normalOffset = Marshal.SizeOf(typeof(Vertex)); gl.VertexAttribPointer(attrNormal, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Add(new IntPtr(0), normalOffset)); gl.DrawElements(OpenGL.GL_TRIANGLES, (int)trefoilKnot.IndexCount, OpenGL.GL_UNSIGNED_SHORT, IntPtr.Zero); }