Exemple #1
0
        public void RenderObject()
        {
            // set up
            float[] vertices = new float[] { -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f };
            int     vao;
            VertexBufferObject <float> vbo;

            GL.GenVertexArrays(1, out vao);
            vbo = new VertexBufferObject <float>(sizeof(float), vertices);
            GL.BindVertexArray(vao);
            vbo.BindBuffer();
            vbo.CreateBuffer(BufferUsageHint.StaticDraw);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
            GL.EnableVertexAttribArray(0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindVertexArray(0);
            //actual renderering
            GL.ClearColor(OpenTK.Graphics.Color4.CornflowerBlue);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            shaderMgr.InitialiseAShader("test1");
            shaderMgr.GetShader("test1").Use();
            GL.BindVertexArray(vao);
            vbo.Draw(PrimitiveType.Triangles);
            GL.BindVertexArray(0);
        }
Exemple #2
0
        /// <summary>
        /// Creates a VAO and VBO object from an array of vertices, the shader, an array of attributes
        /// </summary>
        /// <param name="vertices"> the vertex array</param>
        /// <param name="shaderIndex">index of the shader being used for that object</param>
        /// <param name="vbo">vbo object for output</param>
        /// <param name="vao">vao object for output</param>
        /// <param name="attributes">attribute or attributes(in an array if more than one)</param>
        public void CreateBufferObjects(Vertex[] vertices, string shaderName, out VertexBufferObject <Vertex> vbo, out VertexArrayObject <Vertex> vao,
                                        params BufferObjects.VertexAttribute[] attributes)
        {
            VertexArrayObject <Vertex>  thevao = new VertexArrayObject <Vertex>();
            VertexBufferObject <Vertex> thevbo = new VertexBufferObject <Vertex>(Vertex.Size, vertices);

            thevbo.CreateBuffer();
            thevao.SetAttributes(thevbo, shaderMgr.GetShader(shaderName), attributes);
            vbo = thevbo;
            vao = thevao;
        }
Exemple #3
0
 private void CreateBackgroundConeBuffers(Vertex[] vertices)
 {
     //first set up the attributes
     BufferObjects.VertexAttribute[] attribute = new BufferObjects.VertexAttribute[3];
     attribute[0] = new BufferObjects.VertexAttribute("position", 3, OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float,
                                                      Vertex.Size, 0);
     attribute[1] = new BufferObjects.VertexAttribute("normal", 3, OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float,
                                                      Vertex.Size, Vector3.SizeInBytes);
     attribute[2] = new BufferObjects.VertexAttribute("texcoord", 2, OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float,
                                                      Vertex.Size, 2 * Vector3.SizeInBytes);
     BGvao = new VertexArrayObject <Vertex>();
     BGvbo = new VertexBufferObject <Vertex>(Vertex.Size, vertices);
     BGvbo.CreateBuffer(BufferUsageHint.StaticDraw);
     BGvao.SetAttributes(BGvbo, shaderMgr.GetShader("BackgroundNoFog"), attribute);
     BGvao.Bind();
     // create the EBO
     int[] EBOindices = new int[]
                        #region
     { 0, 1, 3, 2,
       2, 3, 5, 4,
       4, 5, 7, 6,
       6, 7, 9, 8,
       8, 9, 11, 10,
       10, 11, 13, 12,
       12, 13, 15, 14,
       14, 15, 17, 16,
       16, 17, 19, 18,
       18, 19, 21, 20,
       20, 21, 23, 22,
       22, 23, 25, 24,
       24, 25, 27, 26,
       26, 27, 29, 28,
       28, 29, 31, 30,
       30, 31, 33, 32,
       32, 33, 35, 34,
       34, 35, 37, 36,
       36, 37, 39, 38,
       38, 39, 41, 40,
       40, 41, 43, 42,
       42, 43, 45, 44,
       44, 45, 47, 46,
       46, 47, 49, 48,
       48, 49, 51, 50,
       50, 51, 53, 52,
       52, 53, 55, 54,
       54, 55, 57, 56,
       56, 57, 59, 58,
       58, 59, 61, 60,
       60, 61, 63, 62,
       62, 63, 1, 0 };
     #endregion
     //side walls
     BGSideWallebo = new ElementBufferObject(EBOindices);
     BGSideWallebo.CreateBuffer(BufferUsageHint.StaticDraw);
     EBOindices = null;
     //caps
     EBOindices = new int[]
                  #region
     {
         0, 2, 64,
         2, 4, 64,
         4, 6, 64,
         6, 8, 64,
         8, 10, 64,
         10, 12, 64,
         12, 14, 64,
         14, 16, 64,
         16, 18, 64,
         18, 20, 64,
         20, 22, 64,
         22, 24, 64,
         24, 26, 64,
         26, 28, 64,
         28, 30, 64,
         30, 32, 64,
         32, 34, 64,
         34, 36, 64,
         36, 38, 64,
         38, 40, 64,
         40, 42, 64,
         42, 44, 64,
         44, 46, 64,
         46, 48, 64,
         48, 50, 64,
         50, 52, 64,
         52, 54, 64,
         54, 56, 64,
         56, 58, 64,
         58, 60, 64,
         60, 62, 64,
         62, 0, 64,
         65, 3, 1,
         65, 5, 3,
         65, 7, 5,
         65, 9, 7,
         65, 11, 9,
         65, 13, 11,
         65, 15, 13,
         65, 17, 15,
         65, 19, 17,
         65, 21, 19,
         65, 23, 21,
         65, 25, 23,
         65, 27, 25,
         65, 29, 27,
         65, 31, 29,
         65, 33, 31,
         65, 35, 33,
         65, 37, 35,
         65, 39, 37,
         65, 41, 39,
         65, 43, 41,
         65, 45, 43,
         65, 47, 45,
         65, 49, 47,
         65, 51, 49,
         65, 53, 51,
         65, 55, 53,
         65, 57, 55,
         65, 59, 57,
         65, 61, 59,
         65, 63, 61,
         65, 1, 63,
     };
     #endregion
     BGCapsebo = new ElementBufferObject(EBOindices);
     BGCapsebo.CreateBuffer(BufferUsageHint.StaticDraw);
     BGvao.UnBind();
     BGvbo.UnBind();
     BGSideWallebo.Unbind();
     BGCapsebo.Unbind();
 }