Exemplo n.º 1
0
        /// <summary>
        /// Initialises the Scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public void Initialise(OpenGL gl)
        {
            //  We're going to specify the attribute locations for the position and normal, 
            //  so that we can force both shaders to explicitly have the same locations.
            const uint positionAttribute = 0;
            const uint normalAttribute = 1;
            var attributeLocations = new Dictionary<uint, string>
            {
                {positionAttribute, "Position"},
                {normalAttribute, "Normal"},
            };

            //  Create the per pixel shader.
            shaderPerPixel = new ShaderProgram();
            shaderPerPixel.Create(gl, 
                ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.vert"),
                ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.frag"), attributeLocations);
            
            //  Create the toon shader.
            shaderToon = new ShaderProgram();
            shaderToon.Create(gl,
                ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.vert"),
                ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.frag"), attributeLocations);
            
            //  Generate the geometry and it's buffers.
            trefoilKnot.GenerateGeometry(gl, positionAttribute, normalAttribute);
        }
Exemplo n.º 2
0
        void IRenderable.Render(OpenGL gl, RenderMode renderMode)
        {
            if (positionBuffer != null && colorBuffer != null && radiusBuffer != null)
            {
                if (this.shaderProgram == null)
                {
                    this.shaderProgram = InitShader(gl, renderMode);
                }
                if (this.vertexArrayObject == null)
                {
                    CreateVertexArrayObject(gl, renderMode);
                }

                BeforeRendering(gl, renderMode);

                if (this.RenderGrid && this.vertexArrayObject != null)
                {
                    gl.Enable(OpenGL.GL_BLEND);
                    gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);

                    gl.BindVertexArray(this.vertexArrayObject[0]);
                    gl.DrawArrays(OpenGL.GL_POINTS, 0, count);
                    gl.BindVertexArray(0);

                    gl.Disable(OpenGL.GL_BLEND);
                }

                AfterRendering(gl, renderMode);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialises the scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="width">The width of the screen.</param>
        /// <param name="height">The height of the screen.</param>
        public void Initialise(OpenGL gl, float width, float height)
        {
            //  Set a blue clear colour.
            gl.ClearColor(0.4f, 0.6f, 0.9f, 0.0f);

            //  Create the shader program.
            var vertexShaderSource = ManifestResourceLoader.LoadTextFile("Shader.vert");
            var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("Shader.frag");
            shaderProgram = new ShaderProgram();
            shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
            shaderProgram.BindAttributeLocation(gl, attributeIndexPosition, "in_Position");
            shaderProgram.BindAttributeLocation(gl, attributeIndexColour, "in_Color");
            shaderProgram.AssertValid(gl);

            //  Create a perspective projection matrix.
            const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;
            projectionMatrix = glm.perspective(rads, width / height, 0.1f, 100.0f);

            //  Create a view matrix to move us back a bit.
            viewMatrix = glm.translate(new mat4(1.0f), new vec3(0.0f, 0.0f, -5.0f));

            //  Create a model matrix to make the model a little bigger.
            modelMatrix = glm.scale(new mat4(1.0f), new vec3(2.5f));

            //  Now create the geometry for the square.
            CreateVerticesForSquare(gl);
        }
        /// <summary>
        /// Create and add a new ShaderProgram from the given sources. 
        /// Call this function if you decide to add your own shaders.
        /// </summary>
        /// <param name="gl">The OpenGL</param>
        /// <param name="vertexShaderSource">The path to the vertex shader code.</param>
        /// <param name="fragmentShaderSource">The path to the fragment shader code.</param>
        /// <param name="shaderName">The name for the shader.</param>
        public static ExtShaderProgram CreateShader(OpenGL gl, IShaderParameterIds parameters, string vertexShaderSource, string fragmentShaderSource)
        {
            //  Create the per pixel shader.
            ShaderProgram shader = new ShaderProgram();
            shader.Create(gl,
                ManifestResourceLoader.LoadTextFile(vertexShaderSource),
                ManifestResourceLoader.LoadTextFile(fragmentShaderSource), _attributeLocations);

            return new ExtShaderProgram(shader, parameters);
        }
Exemplo n.º 5
0
        public void Initialise(OpenGL gl)
        {
            //  Create the per pixel shader.
            shaderPerPixel = new ShaderProgram();
            shaderPerPixel.Create(gl, 
                ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.vert"),
                ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.frag"), null);
            shaderPerPixel.BindAttributeLocation(gl, VertexAttributes.Position, "Position");
            shaderPerPixel.BindAttributeLocation(gl, VertexAttributes.Normal, "Normal");
            gl.ClearColor(0f,0f, 0f, 1f);

            //  Immediate mode only features!
            gl.Enable(OpenGL.GL_TEXTURE_2D);
        }
        public void run(MainWindow window, ShaderProgram sp, OpenGL gl)
        {
            try
            {
                mThread = new Thread(new ThreadStart(listen));

                mWindow = window;
                mGL = gl;
                mShaderProgram = sp;

                mThread.Start();
            }
            catch (Exception)
            {

            }
        }
Exemplo n.º 7
0
        private void OpenGLControl_OpenGLInitialized(object sender, EventArgs e)
        {
            OpenGL gl = this.openGLControl1.OpenGL;

            string fragmentShaderCode = null;

            using (StreamReader sr = new StreamReader(FRAGMENT_SHADER_PATH))
            {
                fragmentShaderCode = sr.ReadToEnd();
            }

            string vertexShaderCode = null;

            using (StreamReader sr = new StreamReader(VERTEX_SHADER_PATH))
            {
                vertexShaderCode = sr.ReadToEnd();
            }

            _prog = new SharpGL.Shaders.ShaderProgram();
            _prog.Create(gl, vertexShaderCode, fragmentShaderCode, null);

            string geometryShaderCode = null;

            if (File.Exists(GEOMETRY_SHADER_PATH))
            {
                using (StreamReader sr = new StreamReader(GEOMETRY_SHADER_PATH))
                {
                    geometryShaderCode = sr.ReadToEnd();
                }

                Shader geometryShader = new Shader();
                geometryShader.Create(gl, OpenGL.GL_GEOMETRY_SHADER, geometryShaderCode);
                gl.AttachShader(_prog.ShaderProgramObject, geometryShader.ShaderObject);
            }

            gl.LinkProgram(_prog.ShaderProgramObject);

            // Now that we've compiled and linked the shader, check it's link status.If it's not linked properly, we're
            //  going to throw an exception.
            if (_prog.GetLinkStatus(gl) == false)
            {
                throw new SharpGL.Shaders.ShaderCompilationException(string.Format("Failed to link shader program with ID {0}.", _prog.ShaderProgramObject), _prog.GetInfoLog(gl));
            }
        }
        protected void InitShaderProgram(SharpGL.OpenGL gl, out SharpGL.Shaders.ShaderProgram shaderProgram)
        {
            var vertexShaderSource   = ManifestResourceLoader.LoadTextFile(@"Well.PointSpriteStringElement.vert");
            var fragmentShaderSource = ManifestResourceLoader.LoadTextFile(@"Well.PointSpriteStringElement.frag");

            shaderProgram = new ShaderProgram();
            shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
            int position = shaderProgram.GetAttributeLocation(gl, "in_Position");

            if (position >= 0)
            {
                attributeIndexPosition = (uint)position;
            }
            //int color = shaderProgram.GetAttributeLocation(gl, "in_Color");
            //if (color >= 0) { attributeIndexColour = (uint)color; }
            //int radius = shaderProgram.GetAttributeLocation(gl, "in_radius");
            //if (radius >= 0) { attributeIndexRadius = (uint)radius; }
            //int visible = shaderProgram.GetAttributeLocation(gl, "in_visible");
            //if (visible >= 0) { attributeIndexVisible = (uint)visible; }
            shaderProgram.AssertValid(gl);
        }
        public void Initialise(OpenGL gl)
        {
            #region Load the main program.

            string fragmentShaderCode = null;
            using (StreamReader sr = new StreamReader(FRAGMENT_SHADER_PATH))
            {
                fragmentShaderCode = sr.ReadToEnd();
            }

            string vertexShaderCode = null;
            using (StreamReader sr = new StreamReader(VERTEX_SHADER_PATH))
            {
                vertexShaderCode = sr.ReadToEnd();
            }

            _prog = new SharpGL.Shaders.ShaderProgram();
            _prog.Create(gl, vertexShaderCode, fragmentShaderCode, null);

            string geometryShaderCode = null;
            if (File.Exists(GEOMETRY_SHADER_PATH))
            {
                using (StreamReader sr = new StreamReader(GEOMETRY_SHADER_PATH))
                {
                    geometryShaderCode = sr.ReadToEnd();
                }

                Shader geometryShader = new Shader();
                geometryShader.Create(gl, OpenGL.GL_GEOMETRY_SHADER, geometryShaderCode);
                gl.AttachShader(_prog.ShaderProgramObject, geometryShader.ShaderObject);
            }

            gl.LinkProgram(_prog.ShaderProgramObject);

            // Now that we've compiled and linked the shader, check it's link status.If it's not linked properly, we're
            //  going to throw an exception.
            if (_prog.GetLinkStatus(gl) == false)
            {
                throw new SharpGL.Shaders.ShaderCompilationException(string.Format("Failed to link shader program with ID {0}.", _prog.ShaderProgramObject), _prog.GetInfoLog(gl));
            }

            #endregion

            #region Load clear program.

            //string clearFragShaderCode = null;
            //using (StreamReader sr = new StreamReader(CLEAR_FRAGMENT_SHADER_PATH))
            //{
            //    clearFragShaderCode = sr.ReadToEnd();
            //}

            //string clearVertexShaderCode = null;
            //using (StreamReader sr = new StreamReader(CLEAR_VERTEX_SHADER_PATH))
            //{
            //    clearVertexShaderCode = sr.ReadToEnd();
            //}

            //_clearProg = new SharpGL.Shaders.ShaderProgram();
            //_clearProg.Create(gl, clearVertexShaderCode, clearFragShaderCode, null);

            //gl.LinkProgram(_clearProg.ShaderProgramObject);

            //// Now that we've compiled and linked the shader, check it's link status. If it's not linked properly, we're
            //// going to throw an exception.
            //if (_clearProg.GetLinkStatus(gl) == false)
            //{
            //    throw new SharpGL.Shaders.ShaderCompilationException(string.Format("Failed to link the clear shader program with ID {0}.", _clearProg.ShaderProgramObject), _clearProg.GetInfoLog(gl));
            //}

            //_clearRectangle = new float[] { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f };

            #endregion
        }
Exemplo n.º 10
0
    private async void MapLoad(object sender, EventArgs e)
    {
      var shapelayerText = FileLoader.LoadTextFile("config/shapelayers.json");
      var shapelayers = JsonConvert.DeserializeObject<List<Shapelayer>>(shapelayerText);
      var stationText = FileLoader.LoadTextFile("config/stations.json");
      var stations = JsonConvert.DeserializeObject<NexradStationFile>(stationText);

      var us_stations = stations.stationtable.station.Where(x => x.co == "US");
      var states = us_stations.GroupBy(x => x.st).OrderBy(x => x.Key);
      var list = new ListView();
      list.Columns.Add(new ColumnHeader() { Width = list.Width - 10 });
      list.HeaderStyle = ColumnHeaderStyle.None; 
      list.Alignment = ListViewAlignment.Left;
      list.AutoArrange = false;
      list.CheckBoxes = true;
      list.Margin = new Padding(30);
      list.Height = 500;
      list.Width = 250;
      list.ShowGroups = true;
      list.View = View.Details;
   
      foreach (var shapelayer in shapelayers)
      {
        if (list.Groups[shapelayer.category] == null)
        {
          list.Groups.Add(shapelayer.category, shapelayer.category);
        }
        var cur_renderable = new ShapeData(shapelayer.file, shapelayer.r, shapelayer.g, shapelayer.b, shapelayer.category, shapelayer.description);
        all_renderables.Add(cur_renderable);
        var item = list.Items.Add(shapelayer.description);
        item.Group = list.Groups[shapelayer.category];
        item.Checked = shapelayer.enabled;
        if (item.Checked)
        {
          load_renderables.Add(cur_renderable);
        }
      }

      for (int i = 0; i < states.Count(); i++)
      {
        var grp = list.Groups.Add(states.ElementAt(i).Key, states.ElementAt(i).Key);   
      }
      foreach(var station in us_stations){
        var cur_renderable = new RadarScan("K" + station.id, station.st);
        all_renderables.Add(cur_renderable);
        var item = list.Items.Add("K" + station.id + " " + station.name);
        item.Group = list.Groups[station.st];
        item.Checked = station.enabled;
        if (item.Checked)
        {
          load_renderables.Add(cur_renderable);
        }
      }

      list.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
      panel1.Controls.Add(list);
      list.ItemChecked += list_ItemChecked;


      loadThread = new Thread(new ThreadStart(loaderThreadFunc));
      loadThread.Start();
      loadThread2 = new Thread(new ThreadStart(loaderThreadFunc));
      loadThread2.Start();
      loadThread3 = new Thread(new ThreadStart(loaderThreadFunc));
      loadThread3.Start();

      overlayControl.OpenGLDraw += overlayControl_Draw;
      overlayControl.Resized += overlayControl_Resized;

      var gl = overlayControl.OpenGL;
      gl.Enable(OpenGL.GL_BLEND);
      gl.BlendFunc(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha);
      var vertexShaderSource = FileLoader.LoadTextFile("Shader.vert");
      var fragmentShaderSource = FileLoader.LoadTextFile("Shader.frag");
      shaderProgram = new ShaderProgram();
      shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
      shaderProgram.BindAttributeLocation(gl, 0, "in_Position");
      shaderProgram.BindAttributeLocation(gl, 1, "in_Color");
      shaderProgram.AssertValid(gl);

      overlayControl_Resized(null, null);

      overlayControl.Click += overlayControl_Click;
      overlayControl.MouseMove += OnMouseMove;
      overlayControl.MouseDown += OnMouseDown;
      overlayControl.MouseUp += OnMouseUp;
      overlayControl.MouseWheel += overlayControl_MouseWheel;
    }
Exemplo n.º 11
0
 public ShaderWrapper(ShaderProgram shaderProgram, SharpGL.OpenGL gl)
 {
     m_gl = gl;
     m_shaderProgram = shaderProgram;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Handles the OpenGLInitialized event of the openGLControl1 control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
 private void openGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
 {
     //  TODO: Initialise OpenGL here.
     //  Get the OpenGL object.
     OpenGL gl = openGLControl.OpenGL;
     gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);
     //  Set a blue clear colour.
     gl.ClearColor(0.4f, 0.6f, 0.9f, 0.0f);
     gl.ClearColor(0f, 0f, 0f, 0.0f);
     //  Create the shader program.
     var vertexShaderSource = ManifestResourceLoader.LoadTextFile("vertex_shader.glsl");
     var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("fragment_shader.glsl");
     shaderProgram = new ShaderProgram();
     shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
     attribute_vpos = (uint)gl.GetAttribLocation(shaderProgram.ShaderProgramObject, "vPosition");
     attribute_vcol = (uint)gl.GetAttribLocation(shaderProgram.ShaderProgramObject, "vColor");
     shaderProgram.AssertValid(gl);
     InitializeFixedBufferContents();
 }
Exemplo n.º 13
0
 private ShaderProgram InitShader(OpenGL gl, RenderMode renderMode)
 {
     String vertexShaderSource = ManifestResourceLoader.LoadTextFile(@"Grids.HexahedronGrid.vert");
     String fragmentShaderSource = ManifestResourceLoader.LoadTextFile(@"Grids.HexahedronGrid.frag");
     ShaderProgram shaderProgram = new ShaderProgram();
     shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
     //shaderProgram.BindAttributeLocation(gl, ATTRIB_INDEX_POSITION, in_position);
     //shaderProgram.BindAttributeLocation(gl, ATTRIB_INDEX_COLOUR, in_uv);
     {
         int location = shaderProgram.GetAttributeLocation(gl, in_Position);
         if (location < 0) { throw new ArgumentException(); }
         this.ATTRIB_INDEX_POSITION = (uint)location;
     }
     {
         int location = shaderProgram.GetAttributeLocation(gl, in_uv);
         if (location < 0) { throw new ArgumentException(); }
         this.ATTRIB_INDEX_UV = (uint)location;
     }
     shaderProgram.AssertValid(gl);
     return shaderProgram;
 }
 /// <summary>
 /// Deletes the shaderprogram van the GL and clears the parameters of this object.
 /// </summary>
 public void Dispose()
 {
     Program.Delete(_gl);
     Program = null;
     Parameters = null;
 }
Exemplo n.º 15
0
        private void CreateShader(SharpGL.OpenGL gl)
        {
            //  Create the shader program.
            var vertexShaderSource = ManifestResourceLoader.LoadTextFile("Shader.vert");
            var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("Shader.frag");
            m_shaderProgram = new ShaderProgram();
            m_shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
            m_shaderProgram.BindAttributeLocation(gl, AttributeIndexPosition, "in_Position");
            m_shaderProgram.BindAttributeLocation(gl, AttributeIndexColour, "in_Color");
            m_shaderProgram.AssertValid(gl);

            m_shader = new ShaderWrapper(m_shaderProgram, gl);
        }
Exemplo n.º 16
0
        void IRenderable.Render(OpenGL gl, RenderMode renderMode)
        {
            if (this.shaderProgram == null)
            {
                this.shaderProgram = InitShader(gl, renderMode);
            }
            if (this.matrixVertexArrayObject == null)
            {
                CreateVertexArrayObject(gl, renderMode);
            }
            if (this.fractionVertexArrayObject == null)
            {
                CreateFractionVertexArrayObject(gl, renderMode);
            }

            BeforeRendering(gl, renderMode);

            DoRenderMatrix(gl, renderMode);

            DoRenderFraction(gl, renderMode);

            AfterRendering(gl, renderMode);
        }
        private void openGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
        {
            //  TODO: Initialise OpenGL here.

            //  Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL;

            gl.PointSize(10);

            string vertex = File.ReadAllText("Shaders//Vertex//default.vert");
            string frag = File.ReadAllText("Shaders//Fragment//default.frag");
            mShaderProgram = new ShaderProgram();
            mShaderProgram.Create(gl, vertex, frag, null);
            mShaderProgram.BindAttributeLocation(gl, mPositionHandle, "in_Position");
            mShaderProgram.AssertValid(gl);

            var vertices = new float[18];
            var colors = new float[18]; // Colors for our vertices
            vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = 0.0f; // Bottom left corner
            colors[0] = 1.0f; colors[1] = 1.0f; colors[2] = 1.0f; // Bottom left corner
            vertices[3] = -0.5f; vertices[4] = 0.5f; vertices[5] = 0.0f; // Top left corner
            colors[3] = 1.0f; colors[4] = 0.0f; colors[5] = 0.0f; // Top left corner
            vertices[6] = 0.5f; vertices[7] = 0.5f; vertices[8] = 0.0f; // Top Right corner
            colors[6] = 0.0f; colors[7] = 1.0f; colors[8] = 0.0f; // Top Right corner
            vertices[9] = 0.5f; vertices[10] = -0.5f; vertices[11] = 0.0f; // Bottom right corner
            colors[9] = 0.0f; colors[10] = 0.0f; colors[11] = 1.0f; // Bottom right corner
            vertices[12] = -0.5f; vertices[13] = -0.5f; vertices[14] = 0.0f; // Bottom left corner
            colors[12] = 1.0f; colors[13] = 1.0f; colors[14] = 1.0f; // Bottom left corner
            vertices[15] = 0.5f; vertices[16] = 0.5f; vertices[17] = 0.0f; // Top Right corner
            colors[15] = 0.0f; colors[16] = 1.0f; colors[17] = 0.0f; // Top Right corner

            //mDrawable = new Drawable(new Verticies(vertices, 3, 6, 3),mShaderProgram,gl);

            mClient.run(this, mShaderProgram, gl);

            //  Set the clear color.
            gl.ClearColor(0, 0.3f, 1, 1);
        }
 public ExtShaderProgram(ShaderProgram program, IShaderParameterIds parameters)
 {
     Program = program;
     Parameters = parameters;
 }
Exemplo n.º 19
0
        void IRenderable.Render(OpenGL gl, RenderMode renderMode)
        {
            if (positionBuffer == null || colorBuffer == null) { return; }

            if (this.shaderProgram == null)
            {
                this.shaderProgram = InitShader(gl, renderMode);
            }
            if (this.vertexArrayObject == null)
            {
                CreateVertexArrayObject(gl, renderMode);
            }

            BeforeRendering(gl, renderMode);

            if (this.RenderGridWireframe && this.vertexArrayObject != null)
            {
                //if (wireframeIndexBuffer != null)
                if (positionBuffer != null && colorBuffer != null && indexBuffer != null)
                {
                    shaderProgram.SetUniform1(gl, "renderingWireframe", 1.0f);// shader一律上白色。

                    gl.Disable(OpenGL.GL_LINE_STIPPLE);
                    gl.Disable(OpenGL.GL_POLYGON_STIPPLE);
                    gl.Enable(OpenGL.GL_LINE_SMOOTH);
                    gl.Enable(OpenGL.GL_POLYGON_SMOOTH);
                    gl.ShadeModel(SharpGL.Enumerations.ShadeModel.Smooth);
                    gl.Hint(SharpGL.Enumerations.HintTarget.LineSmooth, SharpGL.Enumerations.HintMode.Nicest);
                    gl.Hint(SharpGL.Enumerations.HintTarget.PolygonSmooth, SharpGL.Enumerations.HintMode.Nicest);
                    gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);

                    gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
                    gl.PrimitiveRestartIndex(uint.MaxValue);

                    gl.Enable(OpenGL.GL_BLEND);
                    gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);

                    gl.BindVertexArray(this.vertexArrayObject[0]);
                    gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer[0]);
                    gl.DrawElements(OpenGL.GL_QUAD_STRIP, this.indexBufferLength, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
                    gl.BindVertexArray(0);

                    gl.Disable(OpenGL.GL_BLEND);

                    gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);

                    gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Filled);
                    gl.Disable(OpenGL.GL_POLYGON_SMOOTH);
                }
            }

            if (this.RenderGrid && this.vertexArrayObject != null)
            {
                if (positionBuffer != null && colorBuffer != null && indexBuffer != null)
                {
                    shaderProgram.SetUniform1(gl, "renderingWireframe", 0.0f);// shader根据uv buffer来上色。

                    gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
                    gl.PrimitiveRestartIndex(uint.MaxValue);

                    gl.Enable(OpenGL.GL_BLEND);
                    gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);

                    gl.BindVertexArray(this.vertexArrayObject[0]);
                    gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer[0]);
                    gl.DrawElements(OpenGL.GL_QUAD_STRIP, this.indexBufferLength, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
                    gl.BindVertexArray(0);

                    gl.Disable(OpenGL.GL_BLEND);

                    gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
                }
            }

            AfterRendering(gl, renderMode);
        }
        /// <summary>
        /// Compile the code for the shaderprogram.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="vertexShaderCode">The code for the vertex shader.</param>
        /// <param name="fragmentShaderCode">The code for the fragment shader.</param>
        public ShaderManagerBase(string vertexShaderCode, string fragmentShaderCode, OpenGL gl)
        {
            // Remember the GL, so it's available for dispose.
            _gl = gl;

            _vertexShaderCode = vertexShaderCode;
            _fragmentShaderCode = fragmentShaderCode;

            //  Create the shader program.
            ShaderProgram = new ShaderProgram();
            ShaderProgram.Create(gl, vertexShaderCode, fragmentShaderCode, AttributeLocations);
        }