/// Color Scale private void DrawColorScale(object sender, SharpGL.WPF.OpenGLRoutedEventArgs args) { OpenGL gl = ColorScaleControl.OpenGL; gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); float w = (float)ColorScaleControl.ActualWidth; float h = (float)ColorScaleControl.ActualHeight; gl.Viewport(0, 0, (int)w, (int)h); gl.MatrixMode(MatrixMode.Projection); gl.LoadIdentity(); gl.MatrixMode(MatrixMode.Modelview); gl.LoadIdentity(); gl.Begin(BeginMode.QuadStrip); gl.Color(0.0f, 0.0f, 1.0f); // Blue gl.Vertex(-0.05f, 0.0f, 0.0f); gl.Vertex(-0.05f, 1.0f, 0.0f); gl.Color(0.0f, 1.0f, 1.0f); // Cyan gl.Vertex(0.15f, 0.0f, 0.0f); gl.Vertex(0.15f, 1.0f, 0.0f); gl.Color(0.0f, 1.0f, 0.0f); // Green gl.Vertex(0.35f, 0.0f, 0.0f); gl.Vertex(0.35f, 1.0f, 0.0f); gl.Color(1.0f, 1.0f, 0.0f); // Yellow gl.Vertex(0.55f, 0.0f, 0.0f); gl.Vertex(0.55f, 1.0f, 0.0f); gl.Color(1.0f, 0.5f, 0.0f); // Orange gl.Vertex(0.75f, 0.0f, 0.0f); gl.Vertex(0.75f, 1.0f, 0.0f); gl.Color(1.0f, 0.0f, 0.0f); // Red gl.Vertex(0.95f, 0.0f, 0.0f); gl.Vertex(0.95f, 1.0f, 0.0f); gl.End(); gl.Begin(BeginMode.Lines); gl.Color(1.0f, 1.0f, 1.0f); // White gl.Vertex(-0.05f, -0.2f, 0.0f); gl.Vertex(-0.05f, -0.7f, 0.0f); gl.Vertex(0.95f, -0.2f, 0.0f); gl.Vertex(0.95f, -0.7f, 0.0f); gl.Vertex(-0.05f, -0.4f, 0.0f); gl.Vertex(0.95f, -0.4f, 0.0f); //gl.DrawText(-1, 0, 128.0f, 128.0f, 128.0f, "Arial", 1.0f, "Drawing maze"); gl.End(); gl.Flush(); }
/// Main OpenGL program private void OpenGLDraw(object sender, SharpGL.WPF.OpenGLRoutedEventArgs args) { // Enable finish button if (openFileOk && dispCBOk) { finish_btn.IsEnabled = true; } else { finish_btn.IsEnabled = false; } // Get the OpenGL object OpenGL gl = GLControl.OpenGL; // Set The Material Color float[] glfMaterialColor = new float[] { 0.4f, 0.2f, 0.8f, 1.0f }; float w = (float)GLControl.ActualWidth; float h = (float)GLControl.ActualHeight; // Perspective projection gl.Viewport(0, 0, (int)w, (int)h); gl.Ortho(0, w, 0, h, -100, 100); // Clear The Screen And The Depth Buffer gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_AMBIENT_AND_DIFFUSE, glfMaterialColor); gl.MatrixMode(MatrixMode.Modelview); gl.LoadIdentity(); gl.Scale(scale, scale, 1); // Camera Position gl.LookAt(_position[0], _position[1], _position[2], _viewPoint[0], _viewPoint[1], _viewPoint[2], _upVector[0], _upVector[1], _upVector[2]); // Draw the helix float[][] points = vertexes.ToArray(); Helix(points.Length, points); }