private void AddData(OpenGL gl) { NMHTBufferGroup group = new NMHTBufferGroup(gl); var verts = MyTrefoilKnot.Vertices.SelectMany(x => x.to_array()).ToArray(); var normals = MyTrefoilKnot.Normals.SelectMany(x => x.to_array()).ToArray(); group.BufferData(gl, MyTrefoilKnot.Indices, verts, normals, new Material[] { new Material(new ColorF(255, 150, 50, 50), new ColorF(255, 10, 100, 10), new ColorF(255, 225, 225, 225), null, 100f) }); group.PrepareNMVAO(gl, NmProgram); group.PrepareHTVAO(gl, HtProgram); NmProgram.AddBufferGroup(group); HtProgram.AddBufferGroup(group); NMHTBufferGroup groupCube = new NMHTBufferGroup(gl); var vertsCube = FlatShadedCube.Vertices.SelectMany(x => x.to_array()).ToArray(); var normalsCube = FlatShadedCube.Normals.SelectMany(x => x.to_array()).ToArray(); groupCube.BufferData(gl, FlatShadedCube.Indices, vertsCube, normalsCube, new Material[] { new Material(new ColorF(1f, 0.3f, 1, 0), new ColorF(1f, 1f, 0.5f, 0), new ColorF(1f, 1, 0, 1), null, 100f), }); groupCube.PrepareNMVAO(gl, NmProgram); groupCube.PrepareHTVAO(gl, HtProgram); NmProgram.AddBufferGroup(groupCube); HtProgram.AddBufferGroup(groupCube); }
public void Draw(object sender, OpenGLEventArgs args) { var scene = sender as OpenGLControlJOG; if (NmProgram.ChangedUniforms.Count == 0) // Prepare HitTest scene { // Prevent the image from updating, so that the hittest id's won't be visible to the user. if (HtProgram.ChangedUniforms.Count != 0) { scene.RefreshImgSource = false; GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); HtProgram.BindAll(GL); } else { // Prevent blitting the image when nothing changed. scene.BlitImage = false; } } else // Update the visual scene. { if (!scene.RefreshImgSource) { scene.RefreshImgSource = true; } if (!scene.BlitImage) { scene.BlitImage = true; } GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Add gradient background. SetVerticalGradientBackground(GL, new ColorF(255, 146, 134, 188), new ColorF(1f, 0, 1, 0)); NmProgram.BindAll(GL); } }