Esempio n. 1
0
        /// <summary>
        /// 把坐标轴画上 绿X 红Y 蓝Z
        /// </summary>
        private void drawCoorAxis()
        {
            if (axisGlProgram != null)
            {
                axisGlProgram.Bind(gl);
                axisGlProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());


                var vertexBufferArray = new VertexBufferArray();
                vertexBufferArray.Create(gl);
                vertexBufferArray.Bind(gl);

                var vertexDataBuffer = new VertexBuffer();
                vertexDataBuffer.Create(gl);
                vertexDataBuffer.Bind(gl);
                vertexDataBuffer.SetData(gl, index_in_vPosition, axisData, false, 3);

                var colorDataBuffer = new VertexBuffer();
                colorDataBuffer.Create(gl);
                colorDataBuffer.Bind(gl);
                colorDataBuffer.SetData(gl, index_in_vColor, axisColor, false, 3);

                //  Draw the square.
                gl.DrawArrays(OpenGL.GL_LINES, 0, 6);

                //  Unbind our vertex array and shader.
                vertexDataBuffer.Unbind(gl);
                colorDataBuffer.Unbind(gl);
                vertexBufferArray.Unbind(gl);
                axisGlProgram.Unbind(gl);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the geometry for the square, also creating the vertex buffer array.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        private void CreateVertices(OpenGL gl)
        {
            //GeneratePoints(out vertices, out  colors);
            GenerateModel(out positions, out colors);

            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, 0, positions, false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();

            colourDataBuffer.Create(gl);
            colourDataBuffer.Bind(gl);
            colourDataBuffer.SetData(gl, 1, colors, false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(gl);
        }
Esempio n. 3
0
 public void GenerateGeometry(GLScene scene)
 {
     my_OpenGL  = scene.GL;
     my_Texture = new Texture()
     {
         Name = ""
     };
     my_VertexBufferArray = new VertexBufferArray();
     my_VertexBufferArray.Create(my_OpenGL);
     my_VertexBufferArray.Bind(my_OpenGL);
     CreateVertexBuffer(GLScene.positionAttribute);
     CreateNormalBuffer(GLScene.normalAttribute);
     CreateColorBuffer(GLScene.colorAttribute);
     CreateTextureCoordBuffer(GLScene.textureAttribute);
     CreateIndexBuffer();
     my_VertexBufferArray.Unbind(my_OpenGL);
     if (my_OpenGL != null & my_UseTexture & my_TextureFile != "")
     {
         try
         {
             my_Texture.Create(my_OpenGL, my_TextureFile);
             my_Texture.Name = my_TextureFile;
         }
         catch (System.Exception)
         {
             MessageBox.Show("Unable to create Texture from File:" + my_TextureFile, "GeometryGL error", MessageBoxButton.OK, MessageBoxImage.Error);
             my_Texture = new Texture();
         }
     }
 }
Esempio n. 4
0
        private void drawPoints()
        {
            if (mainGlProgram != null)
            {
                mainGlProgram.Bind(gl);
                mainGlProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());


                // 同样数组对象不用调用glVertexAttribPointer,可以用它封装好的方式
                var vertexBufferArray = new VertexBufferArray();
                vertexBufferArray.Create(gl);
                vertexBufferArray.Bind(gl);


                var vertexDataBuffer = new VertexBuffer();
                vertexDataBuffer.Create(gl);
                vertexDataBuffer.Bind(gl);
                vertexDataBuffer.SetData(gl, index_in_vPosition, pointData, false, 3);

                //  Draw the square.
                gl.DrawArrays(OpenGL.GL_POINTS, 0, SumPoints.Count);

                //  Unbind our vertex array and shader.
                vertexDataBuffer.Unbind(gl);
                vertexBufferArray.Unbind(gl);
                mainGlProgram.Unbind(gl);
            }
        }
Esempio n. 5
0
        private VertexBufferArray CreateVertexBufferArray(OpenGL gl, PrimordialObject primordialObject)
        {
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            vertexDataBuffer = new VertexBuffer();
            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            //  for(int i = 0; i<100; i++) {
            //  var sendDataTime = _stopwatch.ElapsedMilliseconds;
            gl.BufferData(OpenGL.GL_ARRAY_BUFFER, primordialObject.VertexData, OpenGL.GL_STATIC_DRAW);
            //  File.AppendAllText(fileTitle + "Data.txt", (_stopwatch.ElapsedMilliseconds - sendDataTime).ToString() + "\n");
            // }
            gl.VertexAttribPointer(attributeIndexPosition, 4, OpenGL.GL_FLOAT, false, 3 * 4 * sizeof(float), IntPtr.Zero);
            gl.EnableVertexAttribArray(0);


            gl.VertexAttribPointer(attributeIndexColour, 4, OpenGL.GL_FLOAT, false, 3 * 4 * sizeof(float), IntPtr.Add(IntPtr.Zero, 4 * sizeof(float)));
            gl.EnableVertexAttribArray(1);

            gl.VertexAttribPointer(attributeIndexNormal, 4, OpenGL.GL_FLOAT, false, 3 * 4 * sizeof(float), IntPtr.Add(IntPtr.Zero, 8 * sizeof(float)));
            gl.EnableVertexAttribArray(2);
            vertexDataBuffer.Unbind(gl);
            vertexBufferArray.Unbind(gl);
            return(vertexBufferArray);
        }
Esempio n. 6
0
        /// <summary>
        /// 初始化Vbo
        /// </summary>
        private void InitVbo()
        {
            var gl = openGLControl.OpenGL;

            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, 0, vertices, false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();

            colourDataBuffer.Create(gl);
            colourDataBuffer.Bind(gl);
            colourDataBuffer.SetData(gl, 1, colors, false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(gl);
        }
Esempio n. 7
0
        private void CreateVerticesForSquare2(OpenGL gl, float[] vert, float[] col, float[] nrm)
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");
            string graphicsCard = string.Empty;

            foreach (ManagementObject obj in searcher.Get())
            {
                if (obj["CurrentBitsPerPixel"] != null && obj["CurrentHorizontalResolution"] != null)
                {
                    graphicsCard = obj["Name"].ToString();
                }
            }

            string[]      checkname1 = graphicsCard.Split(' ');
            List <string> checkname2 = new List <string>(checkname1);
            string        match      = checkname2.FirstOrDefault(element => element.Equals("nvidia",
                                                                                           StringComparison.CurrentCultureIgnoreCase));
            var vertices = nrm;
            var colors   = vert; // Colors for our vertices
            var normals  = col;


            if (match != null)
            {
                vertices = vert;
                colors   = col; // Colors for our vertices
                normals  = nrm;
            }


            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, 0, vertices, false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();

            colourDataBuffer.Create(gl);
            colourDataBuffer.Bind(gl);
            colourDataBuffer.SetData(gl, 1, colors, false, 3);

            var normalDataBuffer = new VertexBuffer();

            normalDataBuffer.Create(gl);
            normalDataBuffer.Bind(gl);
            normalDataBuffer.SetData(gl, 2, normals, false, 3);


            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(gl);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates the geometry for the square, also creating the vertex buffer array.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        private void CreateVerticesForSquare(OpenGL gl)
        {
            var vertices = new float[18];

            vertices[0]  = -1.0f; vertices[1] = -1.0f; vertices[2] = 0.0f;   // Bottom left corner
            vertices[3]  = -1.0f; vertices[4] = 1.0f; vertices[5] = 0.0f;    // Top left corner
            vertices[6]  = 1.0f; vertices[7] = 1.0f; vertices[8] = 0.0f;     // Top Right corner
            vertices[9]  = 1.0f; vertices[10] = -1.0f; vertices[11] = 0.0f;  // Bottom right corner
            vertices[12] = -1.0f; vertices[13] = -1.0f; vertices[14] = 0.0f; // Bottom left corner
            vertices[15] = 1.0f; vertices[16] = 1.0f; vertices[17] = 0.0f;   // Top Right corner

            var texcoords = new float[12];

            texcoords[0]  = 0.0f; texcoords[1] = 0.0f;
            texcoords[2]  = 0.0f; texcoords[3] = 1.0f;
            texcoords[4]  = 1.0f; texcoords[5] = 1.0f;
            texcoords[6]  = 1.0f; texcoords[7] = 0.0f;
            texcoords[8]  = 0.0f; texcoords[9] = 0.0f;
            texcoords[10] = 1.0f; texcoords[11] = 1.0f;

            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            texCoordsBufferArray = new VertexBufferArray();
            texCoordsBufferArray.Create(gl);
            texCoordsBufferArray.Bind(gl);


            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, 0, vertices, false, 3);

            var texCoordsBuffer = new VertexBuffer();

            texCoordsBuffer.Create(gl);
            texCoordsBuffer.Bind(gl);
            texCoordsBuffer.SetData(gl, 1, texcoords, false, 2);

            //  Now do the same for the colour data.

            /*var colourDataBuffer = new VertexBuffer();
             * colourDataBuffer.Create(gl);
             * colourDataBuffer.Bind(gl);
             * colourDataBuffer.SetData(gl, 1, colors, false, 3);*/

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(gl);
            texCoordsBufferArray.Unbind(gl);
        }
Esempio n. 9
0
        private void CreateVerticesForSquare(OpenGL gl)
        {
            var vertices = new float[36];
            var colors   = new float[36]; // Colors for our vertices

            colors[0]    = 1.0f; colors[1] = 0.0f; colors[2] = 0.0f;
            vertices[0]  = 0.0f; vertices[1] = 1.0f; vertices[2] = 0.0f;
            colors[3]    = 0.0f; colors[4] = 1.0f; colors[5] = 0.0f;
            vertices[3]  = -1.0f; vertices[4] = -1.0f; vertices[5] = 1.0f;
            colors[6]    = 0.0f; colors[7] = 0.3f; colors[8] = 1.0f;
            vertices[6]  = 1.0f; vertices[7] = -1.0f; vertices[8] = 1.0f;
            colors[9]    = 1.0f; colors[10] = 0.3f; colors[11] = 0.5f;
            vertices[9]  = 0.0f; vertices[10] = 1.0f; vertices[11] = 0.0f;
            colors[12]   = 0.0f; colors[13] = 0.0f; colors[14] = 1.0f;
            vertices[12] = 1.0f; vertices[13] = -1.0f; vertices[14] = 1.0f;
            colors[15]   = 0.3f; colors[16] = 1.0f; colors[17] = 1.0f;
            vertices[15] = 1.0f; vertices[16] = -1.0f; vertices[17] = -1.0f;
            colors[18]   = 1.0f; colors[19] = 0.0f; colors[20] = 0.4f;
            vertices[18] = 0.0f; vertices[19] = 1.0f; vertices[20] = 0.0f;
            colors[21]   = 0.0f; colors[22] = 1.0f; colors[23] = 0.0f;
            vertices[21] = 1.0f; vertices[22] = -1.0f; vertices[23] = -1.0f;
            colors[24]   = 0.0f; colors[25] = 0.5f; colors[26] = 1.0f;
            vertices[24] = -1.0f; vertices[25] = -1.0f; vertices[26] = -1.0f;
            colors[27]   = 1.0f; colors[28] = 0.0f; colors[29] = 0.0f;
            vertices[27] = 0.0f; vertices[28] = 1.0f; vertices[29] = 0.0f;
            colors[30]   = 0.0f; colors[31] = 0.0f; colors[32] = 1.0f;
            vertices[30] = -1.0f; vertices[31] = -1.0f; vertices[32] = -1.0f;
            colors[33]   = 0.0f; colors[34] = 1.0f; colors[35] = 0.0f;
            vertices[33] = -1.0f; vertices[34] = -1.0f; vertices[35] = 1.0f;

            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, 0, colors, false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();

            colourDataBuffer.Create(gl);
            colourDataBuffer.Bind(gl);
            colourDataBuffer.SetData(gl, 1, vertices, false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(gl);
        }
Esempio n. 10
0
        public void CreateVerticesForSquare_FirstInit_wrapped()
        {
            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);

            //  Create a vertex buffer for the vertex data.
            vertexDataBuffer = new VertexBuffer();
            vertexDataBuffer.Create(gl);

            //  Now do the same for the colour data.
            colourDataBuffer = new VertexBuffer();
            colourDataBuffer.Create(gl);
        }
Esempio n. 11
0
        public void Create(OpenGL GL, string texPath, GShaderProgram shader)
        {
            vec3[] points = new vec3[] { /*new vec3(-C_END, -C_END, 0), new vec3(-C_END, C_END, 0), new vec3(C_END, C_END, 0), new vec3(C_END, C_END, 0) */
                new vec3(C_BOX_END, C_BOX_END, 0), new vec3(C_BOX_END, -C_BOX_END, 0), new vec3(-C_BOX_END, C_BOX_END, 0), new vec3(-C_BOX_END, -C_BOX_END, 0)
            };
            vec3[] normals = new vec3[points.Length];
            for (int i = 0; i < normals.Length; i++)
            {
                normals[i] = new vec3(0.0f, 0.0f, -1.0f);
            }
            vec2[] texCord = new vec2[] {
                new vec2(0.0f, 1.0f), new vec2(0.0f, 0.0f), new vec2(1.0f, 1.0f), new vec2(1.0f, 0.0f)
            };

            if (texPath == null)
            {
                _textureName = C_DUMMY_TEXTURE;
                TextureManager.Instance.CreateTexture1x1(C_DUMMY_TEXTURE, GL, false, Color.Blue);
            }
            else
            {
                _textureName = texPath;
                TextureManager.Instance.CreateTexture(texPath, GL, false);
            }

            arrowVAO = new VertexBufferArray();
            arrowVAO.Create(GL);
            arrowVAO.Bind(GL);

            VertexBuffer[] cVBO = new VertexBuffer[3];

            cVBO[0] = new VertexBuffer();
            cVBO[0].Create(GL);
            cVBO[0].Bind(GL);
            cVBO[0].SetData(GL, (uint)shader.GetAttributeID(GL, "vPosition"), points, false, 3);

            //  Texture
            cVBO[1] = new VertexBuffer();
            cVBO[1].Create(GL);
            cVBO[1].Bind(GL);
            cVBO[1].SetData(GL, (uint)shader.GetAttributeID(GL, "vTextureCoord"), texCord, false, 2);

            //  Normals
            cVBO[2] = new VertexBuffer();
            cVBO[2].Create(GL);
            cVBO[2].Bind(GL);
            cVBO[2].SetData(GL, (uint)shader.GetAttributeID(GL, "vSurfaceNormal"), normals, false, 3);

            arrowVAO.Unbind(GL);
        }
Esempio n. 12
0
        public void Create(OpenGL GL, string texPath, GShaderProgram shader)
        {
            CircleData c = DrawCircle(0f, 0f, 1f, _numSegments);

            vec3[] points  = c.points;
            vec3[] normals = new vec3[points.Length];
            vec2[] texCord = c.texture;
            for (int i = 0; i < normals.Length; i++)
            {
                normals[i] = new vec3(0.0f, 0.0f, -1.0f);
            }


            if (texPath == null || texPath == "")
            {
                _textureName = C_DUMMY_TEXTURE;
                TextureManager.Instance.CreateTexture1x1(C_DUMMY_TEXTURE, GL, false, Color.Blue);
            }
            else
            {
                _textureName = texPath;
                TextureManager.Instance.CreateTexture(texPath, GL, false);
            }

            compassVAO = new VertexBufferArray();
            compassVAO.Create(GL);
            compassVAO.Bind(GL);

            VertexBuffer[] cVBO = new VertexBuffer[3];

            cVBO[0] = new VertexBuffer();
            cVBO[0].Create(GL);
            cVBO[0].Bind(GL);
            cVBO[0].SetData(GL, (uint)shader.GetAttributeID(GL, "vPosition"), points, false, 3);

            //  Texture
            cVBO[1] = new VertexBuffer();
            cVBO[1].Create(GL);
            cVBO[1].Bind(GL);
            cVBO[1].SetData(GL, (uint)shader.GetAttributeID(GL, "vTextureCoord"), texCord, false, 2);

            //  Normals
            cVBO[2] = new VertexBuffer();
            cVBO[2].Create(GL);
            cVBO[2].Bind(GL);
            cVBO[2].SetData(GL, (uint)shader.GetAttributeID(GL, "vSurfaceNormal"), normals, false, 3);

            compassVAO.Unbind(GL);
        }
Esempio n. 13
0
        private void ogl_OpenGLInitialized(object sender, OpenGLRoutedEventArgs args)
        {
            var gl = args.OpenGL;

            gl.GenTextures(3, _textures);
            _fbos[0]     = _fbos[1] = _fbos[2] = _fbos[3] = _fbos[4] = 0;
            _textures[3] = _textures[4] = _textures[5] = _textures[6] = _textures[7] = 0;
            try
            {
                _blurShader1 = new ShaderProgram();
                var frag = ReadResource(@"LibDmd.Output.Virtual.Dmd.Blur.frag") + "void main() { FragColor = vec4(blur_level_2(texture, uv, direction).rgb, 1.0); }";
                _blurShader1.Create(gl, ReadResource(@"LibDmd.Output.Virtual.Dmd.Blur.vert"), frag, _attributeLocations);
                _bs1Texture   = _blurShader1.GetUniformLocation(gl, "texture");
                _bs1Direction = _blurShader1.GetUniformLocation(gl, "direction");
            }
            catch (ShaderCompilationException e)
            {
                Logger.Error(e, "Blur Shader 1 compilation failed");
                Logger.Error(e.CompilerOutput);
            }
            try
            {
                _blurShader2 = new ShaderProgram();
                var frag = ReadResource(@"LibDmd.Output.Virtual.Dmd.Blur.frag") + "void main() { FragColor = vec4(blur_level_12(texture, uv, direction).rgb, 1.0); }";
                _blurShader2.Create(gl, ReadResource(@"LibDmd.Output.Virtual.Dmd.Blur.vert"), frag, _attributeLocations);
                _bs2Texture   = _blurShader2.GetUniformLocation(gl, "texture");
                _bs2Direction = _blurShader2.GetUniformLocation(gl, "direction");
            }
            catch (ShaderCompilationException e)
            {
                Logger.Error(e, "Blur Shader 2 compilation failed");
                Logger.Error(e.CompilerOutput);
            }
            _quadVbo = new VertexBufferArray();
            _quadVbo.Create(gl);
            _quadVbo.Bind(gl);
            var posVBO = new VertexBuffer();

            posVBO.Create(gl);
            posVBO.Bind(gl);
            posVBO.SetData(gl, PositionAttribute, new float[] { -1f, -1f, -1f, 1f, 1f, 1f, 1f, -1f }, false, 2);
            var texVBO = new VertexBuffer();

            texVBO.Create(gl);
            texVBO.Bind(gl);
            texVBO.SetData(gl, TexCoordAttribute, new float[] { 0f, 1f, 0f, 0f, 1f, 0f, 1f, 1f }, false, 2);
            _quadVbo.Unbind(gl);
        }
Esempio n. 14
0
        public void GenerateGeometry(OpenGL gl, uint vertexAttributeLocation, uint normalAttributeLocation)
        {
            //  Create the vertex array object. This will hold the state of all of the
            //  vertex buffer operations that follow it's binding, meaning instead of setting the
            //  vertex buffer data and binding it each time, we can just bind the array and call
            //  DrawElements - much easier.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            //  Generate the vertices and normals.
            CreateVertexNormalBuffer(gl, vertexAttributeLocation, normalAttributeLocation);
            CreateIndexBuffer(gl);

            vertexBufferArray.Unbind(gl);
        }
Esempio n. 15
0
        void CreateAndPlotData(OpenGL GL, float[] raw_data, int figureID)
        {
            if (_dataTail[figureID] + raw_data.Length >= C_SAMPLES_PER_FRAME)
            {
                _dataTail[figureID] = 0; // Clear the buffer
            }
            AddVerticesToFigure(figureID, raw_data, _dataTail[figureID]);


            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(GL);
            vertexBufferArray.Bind(GL);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(GL);
            vertexDataBuffer.Bind(GL);
            vertexDataBuffer.SetData(GL, attribute_vpos, _data[figureID], false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();

            colourDataBuffer.Create(GL);
            colourDataBuffer.Bind(GL);
            colourDataBuffer.SetData(GL, attribute_vcol, _dataColor[figureID], false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(GL);

            //  Bind the shader, set the matrices.
            shaderProgram.Bind(GL);
            //shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            //shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(GL, "modelMatrix", mviewdata.to_array());

            //  Bind the out vertex array.
            vertexBufferArray.Bind(GL);

            //  Draw the square.
            GL.DrawArrays(OpenGL.GL_LINE_STRIP, 0, _dataTail[figureID]);

            //  Unbind our vertex array and shader.
            vertexBufferArray.Unbind(GL);
            shaderProgram.Unbind(GL);
        }
Esempio n. 16
0
        public void GenerateGeometry(OpenGL gl)
        {
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            VertexBuffer vb = new VertexBuffer();

            vb.Create(gl);
            vb.Bind(gl);
            vb.SetData(gl, 0, vertices.SelectMany(v => ((vec3)v).ToArray()).ToArray(), false, 3);

            IndexBuffer ib = new IndexBuffer();

            ib.Create(gl);
            ib.Bind(gl);
            ib.SetData(gl, indices);
        }
Esempio n. 17
0
        public void Create(OpenGL GL, GShaderProgram shader, vec3[] vertex, vec4[] color, float size)
        {
            Pos   = vertex;
            Color = color;
            Size  = size;

            pointVAO = new VertexBufferArray();
            pointVAO.Create(GL);
            pointVAO.Bind(GL);

            pVBO    = new VertexBuffer[2];
            pVBO[0] = new VertexBuffer();
            pVBO[0].Create(GL);
            pVBO[1] = new VertexBuffer();
            pVBO[1].Create(GL);
            LoadData(GL, shader, Pos, Color);
            pointVAO.Unbind(GL);
        }
Esempio n. 18
0
        /// <summary>
        /// Creates the geometry for the square, also creating the vertex buffer array.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        private void CreateVerticesForSquare(OpenGL 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

            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, vertices);
            vertexDataBuffer.SetAttributeData(gl, 0, 3, false);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();

            colourDataBuffer.Create(gl);
            colourDataBuffer.Bind(gl);
            colourDataBuffer.SetData(gl, colors);
            colourDataBuffer.SetAttributeData(gl, 1, 3, false);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(gl);
        }
Esempio n. 19
0
        /// <summary>
        /// Draws the scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public void Draw(OpenGL gl, ShaderProgram shaderProgram, VertexBufferArray vertexBufferArray, mat4 modelMatrix, mat4 viewMatrix, mat4 projectionMatrix)
        {
            //  Clear the scene.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            //  Bind the shader, set the matrices.
            shaderProgram.Bind(gl);
            shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());

            //  Bind the out vertex array.
            vertexBufferArray.Bind(gl);

            //  Draw the square.
            gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 6);

            //  Unbind our vertex array and shader.
            vertexBufferArray.Unbind(gl);
            shaderProgram.Unbind(gl);
        }
Esempio n. 20
0
        private void CreateVertexBufferArray(OpenGL gl, Mesh mesh)
        {
            //  Create and bind a vertex buffer array.
            var vertexBufferArray = new VertexBufferArray();

            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertices.
            var verticesVertexBuffer = new VertexBuffer();

            verticesVertexBuffer.Create(gl);
            verticesVertexBuffer.Bind(gl);
            verticesVertexBuffer.SetData(gl, VertexAttributes.Position,
                                         mesh.vertices.SelectMany(v => v.to_array()).ToArray(),
                                         false, 3);
            if (mesh.normals != null)
            {
                var normalsVertexBuffer = new VertexBuffer();
                normalsVertexBuffer.Create(gl);
                normalsVertexBuffer.Bind(gl);
                normalsVertexBuffer.SetData(gl, VertexAttributes.Normal,
                                            mesh.normals.SelectMany(v => v.to_array()).ToArray(),
                                            false, 3);
            }

            if (mesh.uvs != null)
            {
                var texCoordsVertexBuffer = new VertexBuffer();
                texCoordsVertexBuffer.Create(gl);
                texCoordsVertexBuffer.Bind(gl);
                texCoordsVertexBuffer.SetData(gl, VertexAttributes.TexCoord,
                                              mesh.uvs.SelectMany(v => v.to_array()).ToArray(),
                                              false, 2);
            }
            //  We're done creating the vertex buffer array - unbind it and add it to the dictionary.
            verticesVertexBuffer.Unbind(gl);
            meshVertexBufferArrays[mesh] = vertexBufferArray;
        }
Esempio n. 21
0
        public override void GenerateGeometry(OpenGL gl)
        {
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            VertexBuffer vb = new VertexBuffer();

            vb.Create(gl);
            vb.Bind(gl);
            vb.SetData(gl, 0, vertexTriangles.Select(v => vertices[v]).SelectMany(v => ((vec3)v).ToArray()).ToArray(), false, 3);

            VertexBuffer nb = new VertexBuffer();

            nb.Create(gl);
            nb.Bind(gl);
            nb.SetData(gl, 1, vertexNormals.SelectMany(v => ((vec3)v).ToArray()).ToArray(), false, 3);

            IndexBuffer ib = new IndexBuffer();

            ib.Create(gl);
            ib.Bind(gl);
            ib.SetData(gl, Enumerable.Range(0, 36).Select(v => (ushort)v).ToArray());
        }
Esempio n. 22
0
        public override void GenerateGeometry(OpenGL gl)
        {
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            VertexBuffer vb = new VertexBuffer();

            vb.Create(gl);
            vb.Bind(gl);
            vb.SetData(gl, 0, Vertices.SelectMany(v => ((vec3)v).ToArray()).ToArray(), false, 3);

            VertexBuffer nb = new VertexBuffer();

            nb.Create(gl);
            nb.Bind(gl);
            nb.SetData(gl, 1, Vertices.SelectMany(v => ((vec3)v).ToArray()).ToArray(), false, 3);

            IndexBuffer ib = new IndexBuffer();

            ib.Create(gl);
            ib.Bind(gl);
            ib.SetData(gl, Faces.SelectMany(v => v).Select(v => (ushort)v).ToArray());
        }
Esempio n. 23
0
        public GL_GUI_Context(Window window, float width, float height)
        {
            this.window = window;
            this.Width  = width;
            this.Height = height;

            context = SDL.SDL_GL_CreateContext(window.Handle);
            SDL.SDL_GL_MakeCurrent(window.Handle, context);

            gl = new OpenGL();

            gl.Enable(OpenGL.GL_TEXTURE_2D);

            shaderProgram = new ShaderProgram();
            shaderProgram.Create(gl, VERTEX_SHADER, FRAGMENT_SHADER, null);
            shaderProgram.BindAttributeLocation(gl, 0, "in_Position");
            shaderProgram.BindAttributeLocation(gl, 1, "in_Color");
            shaderProgram.AssertValid(gl);

            gl.GenFramebuffersEXT(1, framebuffers);
            gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, framebuffers[0]);

            gl.GenTextures(1, framebufferTargets);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, framebufferTargets[0]);
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGB, window.DisplayWidth, window.DisplayHeight, 0, OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE, IntPtr.Zero);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_NEAREST);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_NEAREST);
            gl.FramebufferTexture(OpenGL.GL_FRAMEBUFFER_EXT, OpenGL.GL_COLOR_ATTACHMENT0_EXT, framebufferTargets[0], 0);
            gl.DrawBuffers(1, new uint[] { OpenGL.GL_COLOR_ATTACHMENT0_EXT });

            if (gl.CheckFramebufferStatusEXT(OpenGL.GL_FRAMEBUFFER_EXT) != OpenGL.GL_FRAMEBUFFER_COMPLETE_EXT)
            {
                throw new Exception("Frame buffer setup not complete");
            }

            gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, 0);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);


            ortho = new float[] {
                2.0f / Width, 0.0f, 0.0f, 0.0f,
                0.0f, -2.0f / Height, 0.0f, 0.0f,
                0.0f, 0.0f, -1.0f, 0.0f,
                -1.0f, 1.0f, 0.0f, 1.0f,
            };

            gl.Viewport(0, 0, window.DisplayWidth, window.DisplayHeight);
            gl.Enable(OpenGL.GL_BLEND);
            gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
            gl.Disable(OpenGL.GL_CULL_FACE);
            gl.Disable(OpenGL.GL_DEPTH_TEST);
            gl.ActiveTexture(OpenGL.GL_TEXTURE0);
            gl.Enable(OpenGL.GL_SCISSOR_TEST);

            shaderProgram.Bind(gl);
            shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", ortho);

            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);
        }
Esempio n. 24
0
        /// <summary>
        /// Creates the geometry for the square, also creating the vertex buffer array.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        private void CreateVerticesForSquare(OpenGL gl)
        {
            var vertices = new float[18];

            vertices[0] = -0.5f;
            vertices[1] = -0.5f;
            vertices[2] = 0.0f; // Bottom left corner

            vertices[3] = -0.5f;
            vertices[4] = .5f;
            vertices[5] = 0.0f; // Top left corner

            vertices[6] = .5f;
            vertices[7] = .5f;
            vertices[8] = 0.0f; // Top Right corner

            vertices[9]  = .5f;
            vertices[10] = -.5f;
            vertices[11] = 0.0f; // Bottom right corner

            vertices[12] = -.5f;
            vertices[13] = -.5f;
            vertices[14] = 0.0f; // Bottom left corner

            vertices[15] = .5f;
            vertices[16] = .5f;
            vertices[17] = 0.0f; // Top Right corner


            var texcoords = new float[12];

            texcoords[0]  = -1.0f;
            texcoords[1]  = -1.0f;
            texcoords[2]  = -1.0f;
            texcoords[3]  = 1.0f;
            texcoords[4]  = 1.0f;
            texcoords[5]  = 1.0f;
            texcoords[6]  = 1.0f;
            texcoords[7]  = -1.0f;
            texcoords[8]  = -1.0f;
            texcoords[9]  = -1.0f;
            texcoords[10] = 1.0f;
            texcoords[11] = 1.0f;

            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            texCoordsBufferArray = new VertexBufferArray();
            texCoordsBufferArray.Create(gl);
            texCoordsBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, 0, vertices, false, 3);

            var texCoordsBuffer = new VertexBuffer();

            texCoordsBuffer.Create(gl);
            texCoordsBuffer.Bind(gl);
            texCoordsBuffer.SetData(gl, 1, texcoords, false, 2);

            //  Unbind the vertex array
            vertexBufferArray.Unbind(gl);
            texCoordsBufferArray.Unbind(gl);
        }
Esempio n. 25
0
        private DmdController(IView window)
        {
            _window = window;

            _window.FramebufferResize += (size) =>
            {
                _fboInvalid = true;
                _hasFrame   = true;
            };

            _gl = GL.GetApi(window);
            _gl.GenTextures(3, _textures);

            _fbos[0] = 0;
            _fbos[1] = 0;
            _fbos[2] = 0;
            _fbos[3] = 0;
            _fbos[4] = 0;

            _textures[3] = 0;
            _textures[4] = 0;
            _textures[5] = 0;
            _textures[6] = 0;
            _textures[7] = 0;

            try
            {
                _blurShader1 = new ShaderProgram();
                var frag = ReadResource(@"PinMameSilk.Shaders.Blur.frag") + "void main() { FragColor = vec4(blur_level_2(tex, uv, direction).rgb, 1.0); }";
                _blurShader1.Create(_gl, ReadResource(@"PinMameSilk.Shaders.Blur.vert"), frag, _attributeLocations);
                _bs1Texture   = _blurShader1.GetUniformLocation(_gl, "tex");
                _bs1Direction = _blurShader1.GetUniformLocation(_gl, "direction");
            }

            catch (ShaderCompilationException e)
            {
                Logger.Fatal($"Blur Shader 1 compilation failed: output={e.CompilerOutput}");
            }

            try
            {
                _blurShader2 = new ShaderProgram();
                var frag = ReadResource(@"PinMameSilk.Shaders.Blur.frag") + "void main() { FragColor = vec4(blur_level_12(tex, uv, direction).rgb, 1.0); }";
                _blurShader2.Create(_gl, ReadResource(@"PinMameSilk.Shaders.Blur.vert"), frag, _attributeLocations);
                _bs2Texture   = _blurShader2.GetUniformLocation(_gl, "tex");
                _bs2Direction = _blurShader2.GetUniformLocation(_gl, "direction");
            }

            catch (ShaderCompilationException e)
            {
                Logger.Fatal($"Blur Shader 2 compilation failed: output={e.CompilerOutput}");
            }

            _quadVbo = new VertexBufferArray();
            _quadVbo.Create(_gl);
            _quadVbo.Bind(_gl);

            var posVBO = new VertexBuffer();

            posVBO.Create(_gl);
            posVBO.Bind(_gl);
            posVBO.SetData(_gl, PositionAttribute, new float[] { -1f, -1f, -1f, 1f, 1f, 1f, 1f, -1f }, false, 2);

            var texVBO = new VertexBuffer();

            texVBO.Create(_gl);
            texVBO.Bind(_gl);
            texVBO.SetData(_gl, TexCoordAttribute, new float[] { 0f, 1f, 0f, 0f, 1f, 0f, 1f, 1f }, false, 2);
            _quadVbo.Unbind(_gl);
        }
        /// <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)
        {
            //  Set a blue clear colour.
            gl.ClearColor(0.4f, 0.6f, 0.9f, 0.5f);

            {
                //  Create the shader program.
                var vertexShaderSource   = ManifestResourceLoader.LoadTextFile(@"Model\Shader.vert");
                var fragmentShaderSource = ManifestResourceLoader.LoadTextFile(@"Model\Shader.frag");
                var shaderProgram        = new ShaderProgram();
                shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
                shaderProgram.BindAttributeLocation(gl, attributeIndexPosition, "in_Position");
                shaderProgram.BindAttributeLocation(gl, attributeIndexColour, "in_Color");
                shaderProgram.AssertValid(gl);
                this.shaderProgram = shaderProgram;
            }
            {
                //  Create the picking shader program.
                var vertexShaderSource   = ColorCodedPickingShaderHelper.GetShaderSource(ColorCodedPickingShaderHelper.ShaderTypes.VertexShader);
                var fragmentShaderSource = ColorCodedPickingShaderHelper.GetShaderSource(ColorCodedPickingShaderHelper.ShaderTypes.FragmentShader);
                var shaderProgram        = new ShaderProgram();
                shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
                shaderProgram.BindAttributeLocation(gl, attributeIndexPosition, "in_Position");
                shaderProgram.BindAttributeLocation(gl, attributeIndexColour, "in_Color");
                shaderProgram.AssertValid(gl);
                this.pickingShaderProgram = shaderProgram;
            }

            unsafe
            {
                //  Create the vertex array object.
                vertexBufferArray = new VertexBufferArray();
                vertexBufferArray.Create(gl);
                vertexBufferArray.Bind(gl);

                //  Create a vertex buffer for the vertex data.
                var vertexDataBuffer = new VertexBuffer();
                vertexDataBuffer.Create(gl);
                vertexDataBuffer.Bind(gl);
                //vertexDataBuffer.SetData(gl, 0,
                //this.Model.VertexCount * sizeof(Vertex), (IntPtr)this.Model.Positions, false, 3, OpenGL.GL_FLOAT);
                vertexDataBuffer.SetData(gl, 0, this.Model.Positions, false, 3);

                //  Now do the same for the colour data.
                var colourDataBuffer = new VertexBuffer();
                colourDataBuffer.Create(gl);
                colourDataBuffer.Bind(gl);
                //colourDataBuffer.SetData(gl, 1,
                //this.Model.VertexCount * sizeof(ByteColor), (IntPtr)this.Model.Colors, false, 3, OpenGL.GL_BYTE);
                colourDataBuffer.SetData(gl, 1, this.Model.Colors, false, 3);

                //  Unbind the vertex array, we've finished specifying data for it.
                vertexBufferArray.Unbind(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));
            ////IPerspectiveCamera camera = this.cameraRotation.Camera;
            ////projectionMatrix = camera.GetProjectionMat4();
            ////viewMatrix = this.cameraRotation.Camera.GetViewMat4();
            ////modelMatrix = mat4.identity();

            ////  Now create the geometry for the square.
            //CreateVertices(gl);

            this.initialised = true;
        }
Esempio n. 27
0
        private void OpenGL_Initialize(object sender, OpenGLEventArgs args)
        {
            openGLControl.OpenGLVersion = SharpGL.Version.OpenGLVersion.OpenGL3_3;
            OpenGL gl = openGLControl.OpenGL;

            vao = new VertexBufferArray();
            vao.Create(gl);
            vao.Bind(gl);

            vbo = new VertexBuffer();
            vbo.Create(gl);
            vbo.Bind(gl);

            gl.EnableVertexAttribArray(0);
            gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, 8 * 4, new System.IntPtr(0));
            gl.EnableVertexAttribArray(1);
            gl.VertexAttribPointer(1, 2, OpenGL.GL_FLOAT, false, 8 * 4, new System.IntPtr(12));
            gl.EnableVertexAttribArray(2);
            gl.VertexAttribPointer(2, 3, OpenGL.GL_FLOAT, false, 8 * 4, new System.IntPtr(20));

            gl.BindVertexArray(0);

            string vertexShaderSource =
                @"
                    #version 410

                    layout (location = 0) in vec3 in_position;
                    layout (location = 1) in vec2 in_uv;
                    layout (location = 2) in vec3 in_normal;

                    uniform mat4 mvp;
                    uniform mat4 m;

                    out vec3 normal;
                    out vec2 uv;

                    void main()
                    {
                        gl_Position = mvp * vec4(in_position, 1.0);
                        normal = (m * vec4(in_normal, 0.0)).xyz;
                        uv = in_uv;
                    }
                ";
            string fragmentShaderSource =
                @"
                    #version 410

                    layout (location = 0) out vec4 out_color;

                    in vec3 normal;
                    in vec2 uv;

                    void main()
                    {
                        out_color = vec4(1, 0, 0, 1);
                        if (length(normal) > 0.0)
                        {
                            out_color = vec4(abs(normal), 1);
                        }
                    }
                ";

            shader = new ShaderProgram();
            try
            {
                shader.Create(gl, vertexShaderSource, fragmentShaderSource, null);
            }
            catch (ShaderCompilationException e)
            {
                string error   = e.CompilerOutput;
                string message = e.Message;
            }

            const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;

            projectionMatrix = glm.perspective(rads, (float)(openGLControl.ActualWidth / openGLControl.ActualHeight), 0.1f, 100.0f);

            modelMatrix = mat4.identity();

            cameraPos  = new vec3(0.0f, 0.0f, 5.0f);
            viewMatrix = glm.lookAt(cameraPos, new vec3(0f), new vec3(0f, 1f, 0f));

            lastMousePos = new Point(-1, -1);

            gl.PointSize(5f);
            gl.ClearColor(0.2f, 0.3f, 0.8f, 1);
        }
Esempio n. 28
0
        void CreateAndDrawGrid(OpenGL GL)
        {
            // Debug.WriteLine("Painting Begins..");

            // Create vertices for 4 lines that will split the figure into 3 equal sections
            xgrid = new vec3[(C_NUM_Y_DIV + 1) * 2];
            for (int i = 0; i < (C_NUM_Y_DIV + 1) * 2; i = i + 2)
            {
                xgrid[i].x = -1f; xgrid[i + 1].x = 1f;
                xgrid[i].y = C_X_MARGIN_MIN + C_Y_STEP * i / 2; xgrid[i + 1].y = C_X_MARGIN_MIN + C_Y_STEP * i / 2;
                xgrid[i].z = 0f; xgrid[i + 1].z = 0f;
            }

            coldata = new vec3[] {
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White)
            };

            mviewdata = new mat4(1.0f);


            // --------------- Implementation WITH VERTEX ARRAY OBJECTS --------------------
            ////  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(GL);
            vertexBufferArray.Bind(GL);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(GL);
            vertexDataBuffer.Bind(GL);
            vertexDataBuffer.SetData(GL, attribute_vpos, xgrid, false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();

            colourDataBuffer.Create(GL);
            colourDataBuffer.Bind(GL);
            colourDataBuffer.SetData(GL, attribute_vcol, coldata, false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(GL);

            //  Bind the shader, set the matrices.
            shaderProgram.Bind(GL);
            //shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            //shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(GL, "modelview", mviewdata.to_array());

            //  Bind the out vertex array.
            vertexBufferArray.Bind(GL);

            GL.DrawArrays(OpenGL.GL_LINES, 0, 8);

            //  Unbind our vertex array and shader.
            vertexBufferArray.Unbind(GL);
            shaderProgram.Unbind(GL);

            // --------------- Implementation WITH VERTEX ARRAY OBJECTS END --------------------
        }
Esempio n. 29
0
        /// <summary>
        /// Creates the geometry for the square, also creating the vertex buffer array.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        private void CreateVerticesForSquare(OpenGL 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

            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(gl);
            vertexBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();
            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, 0, vertices, false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();
            colourDataBuffer.Create(gl);
            colourDataBuffer.Bind(gl);
            colourDataBuffer.SetData(gl, 1, colors, false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(gl);
        }