Exemplo n.º 1
0
        public override void AddVertexBuffer(VertexBuffer vertexBuffer)
        {
            if (vertexBuffer.BufferLayout == null)
            {
                Console.WriteLine("BufferLayout Not set");
            }

            BindVertexArray(_vertexArrayObject);
            vertexBuffer.Bind();

            uint index  = 0;
            var  layout = vertexBuffer.BufferLayout;

            foreach (var element in layout.Elements)
            {
                EnableVertexAttribArray(index);
                VertexAttribPointer(index,
                                    element.GetComponentCount(),
                                    element.Type.ToOpenGL(),
                                    element.Normalized,
                                    layout.GetStride(),
                                    new IntPtr(element.Offset));
                index++;
            }

            _vertexBuffers.Add(vertexBuffer);
        }
Exemplo n.º 2
0
        public void Load(int width, int height)
        {
            // Create Bitmap and OpenGL texture
            text_bmp = new Bitmap(Width, Height); // window size

            //TextTexture = Texture.Load(text_bmp);

            Text = "";

            using (Graphics gfx = Graphics.FromImage(text_bmp))
            {
                gfx.Clear(BackgroundColor);
                gfx.DrawString(Text, new Font(Font,
                                              FontStyle),
                               TextBrush, 0, 0);
            }

            TextTexture = Texture.Load(text_bmp);

            GL.UseProgram(Shader.Program);

            Matrix4 SM = Matrix4.CreateScale((float)Width / width, (float)Height / height, 0f);

            float pixelW = (float)(1 / (float)(width / 2));
            float pixelH = (float)(1 / (float)(height / 2));

            Matrix4 TM = Matrix4.CreateTranslation(
                (float)(Position.X - (float)(width / 2) + (float)Width / 2) * pixelW,
                (float)(-Position.Y + (float)(height / 2) - (float)Height / 2) * pixelH,
                0f);

            Matrix4 ModelViewMatrix = SM * TM;

            Matrix4 ProjectionMatrix = Matrix4.Identity;

            int ModelviewMatrix_location = GL.GetUniformLocation(Shader.Program, "modelview_matrix");

            GL.UniformMatrix4(ModelviewMatrix_location, false, ref ModelViewMatrix);

            int ProjectionMatrix_location = GL.GetUniformLocation(Shader.Program, "projection_matrix");

            GL.UniformMatrix4(ProjectionMatrix_location, false, ref ProjectionMatrix);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, TextTexture);
            GL.Uniform1(GL.GetUniformLocation(Shader.Program, "TextureUnit0"), TextureUnit.Texture0 - TextureUnit.Texture0);

            DrawBufer(VertexBuffer, VertexFormat);

            VertexBuffer.IndexFromLength();
            VertexBuffer.Load();
            //VertexBuffer.Reload();



            VertexBuffer.Bind(Shader);
            GL.UseProgram(0);

            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public void Update(double time, bool AI = false)
        {
            if (!AI)
            {
                _currentFramesInput = GetUserInput();
            }
            if (_currentFramesInput.HasFlag(Input.Slow))
            {
                time *= SLOW_MULTIPLIER;
            }
            // _position.Azimuth += time*0.5*Direction;
            if (_currentFramesInput.HasFlag(Input.Left))
            {
                _position.Azimuth -= _velocity.Azimuth * time;
            }
            else if (_currentFramesInput.HasFlag(Input.Right))
            {
                _position.Azimuth += _velocity.Azimuth * time;
            }
            _position = _position.Normalised();

            _vertexBuffer.Bind();
            _vertexBuffer.Initialise();
            _vertexBuffer.SetData(BuildVertexList(), _dataSpecification);
            _vertexBuffer.UnBind();
        }
Exemplo 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);
        }
Exemplo n.º 6
0
        public void Draw()
        {
            if (state == DrawStates.None)
            {
                return;
            }

            if ((state & DrawStates.Vertex) == DrawStates.Vertex)
            {
                VertexBuffer.Bind(BufferTarget.ArrayBuffer);
                VertexBuffer.UseVertexPointer(vertexSize, VertexStride, VertexOffset);
            }

            if ((state & DrawStates.TexCoord) == DrawStates.TexCoord)
            {
                TexCoordBuffer.Bind(BufferTarget.ArrayBuffer);
                TexCoordBuffer.UseTexCoordPointer(texCoordSize, TexCoordStride, TexCoordOffset);
            }

            if ((state & DrawStates.Normal) == DrawStates.Normal)
            {
                NormalBuffer.Bind(BufferTarget.ArrayBuffer);
                NormalBuffer.UseNormalPointer(NormalStride, NormalOffset);
            }

            //TODO this needs to become static/part of some graphics context class.
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            IndexBuffer.Bind(BufferTarget.ElementArrayBuffer);
            GL.DrawElements(DrawMode, IndexBuffer.Length, (DrawElementsType)IndexBuffer.DataType, 0);
            IndexBuffer.Unbind(BufferTarget.ElementArrayBuffer);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        protected override void OnLoad(EventArgs e)
        {
            prog = new ShaderProgram(Shader.FromFile(vertPath), Shader.FromFile(fragPath));

            textureWall      = new Texture(System.Drawing.Image.FromFile("Data/wall.jpg"), 0, "wall");
            textureContainer = new Texture(System.Drawing.Image.FromFile("Data/container2.png"), 1, "container");



            vbo = new VertexBuffer <float>();
            vbo.Bind();
            vbo.BufferData(vertices);


            vao = new VertexArray();
            vao.Bind();

            ibo = new IndexBuffer();
            ibo.Bind();
            ibo.BufferData(indices);

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 5 * 4, 0);
            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 5 * 4, 3 * 4);
            GL.EnableVertexAttribArray(1);

            vao.Unbind();
            ibo.Unbind();
            vbo.Unbind();
            prog.Use();

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
        }
Exemplo n.º 9
0
        internal void Draw(PrimitiveType primitiveType, Matrix world)
        {
            Threading.EnsureUIThread();
            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Back);

            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            Material.Shader.Bind();
            Material.Apply();

            VertexBuffer.BindVertexArray();
            VertexBuffer.Bind();
            IndexBuffer.Bind();
            VertexBuffer.VertexDeclaration.Apply(Material.Shader, IntPtr.Zero);

            REngine.CheckGLError();

            Material.Shader.BindSemantics(Matrix.Identity * world, REngine.camera.View, REngine.camera.Projection);
            REngine.CheckGLError();


            GL.DrawElements(primitiveType, IndexBuffer.IndexCount, DrawElementsType.UnsignedInt, IntPtr.Zero);

            Material.Shader.Unbind();
            IndexBuffer.Unbind();
            VertexBuffer.Unbind();
            VertexBuffer.UnbindVertexArray();
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
        private void CreateBuffers()
        {
            _dataSpecification = new BufferDataSpecification
            {
                Count              = 2,
                Name               = "in_position",
                Offset             = 0,
                ShouldBeNormalised = false,
                Stride             = 0,
                Type               = VertexAttribPointerType.Float
            };

            _vertexArray = new VertexArray {
                DrawPrimitiveType = PrimitiveType.Triangles
            };
            _vertexArray.Bind();

            var size = 3 * 2 * sizeof(float);

            _vertexBuffer = new VertexBuffer
            {
                BufferUsage     = BufferUsageHint.StreamDraw,
                DrawableIndices = 3,
                MaxSize         = size
            };
            _vertexBuffer.Bind();
            _vertexBuffer.Initialise();
            _vertexBuffer.DataSpecifications.Add(_dataSpecification);

            _vertexArray.Load(_shaderProgram, _vertexBuffer);
            _vertexArray.UnBind();
        }
Exemplo n.º 12
0
        public void Render()
        {
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);
            GL.EnableVertexAttribArray(3);

            VertexBuffer.Bind();
            IndexBuffer.Bind();

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, /*0*/ 10 * sizeof(float),
                                   new IntPtr(0 * sizeof(float)));
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, /*3*/ 10 * sizeof(float),
                                   new IntPtr(3 * sizeof(float)));
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, /*7*/ 10 * sizeof(float),
                                   new IntPtr(7 * sizeof(float)));
            GL.VertexAttribPointer(3, 1, VertexAttribPointerType.Float, false, /*9*/ 10 * sizeof(float),
                                   new IntPtr(9 * sizeof(float)));

            GL.DrawElements(PrimitiveType.Triangles, Elements.Length, DrawElementsType.UnsignedInt, IntPtr.Zero);

            GL.DisableVertexAttribArray(0);
            GL.DisableVertexAttribArray(1);
            GL.DisableVertexAttribArray(2);
            GL.DisableVertexAttribArray(3);
        }
Exemplo n.º 13
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);
            }
        }
Exemplo n.º 14
0
        public void Update(double time, bool updateRadius)
        {
            if (updateRadius)
            {
                Position.Radius -= (time * Velocity.Radius);
            }
            if (Position.Radius <= ImpactDistance)
            {
                Destroy = true;
            }
            if (Pulsing)
            {
                Pulse(time);
            }

            if (_vertexArray == null)
            {
                InitialiseRendering();
            }

            _vertexBuffer.Bind();
            _vertexBuffer.Initialise();
            _vertexBuffer.SetData(BuildVertexList(), _dataSpecification);
            _vertexBuffer.UnBind();
        }
Exemplo n.º 15
0
        private void InitialiseRendering()
        {
            _dataSpecification = new BufferDataSpecification
            {
                Count              = 2,
                Name               = "in_position",
                Offset             = 0,
                ShouldBeNormalised = false,
                Stride             = 0,
                Type               = VertexAttribPointerType.Float,
                SizeInBytes        = sizeof(float)
            };

            _vertexArray = new VertexArray {
                DrawPrimitiveType = PrimitiveType.Triangles
            };
            _vertexArray.Bind();

            _vertexBuffer = new VertexBuffer
            {
                BufferUsage        = BufferUsageHint.StreamDraw,
                DrawableIndices    = _sides.Count(b => b) * 6 * 3,
                MaxDrawableIndices = _sides.Count(b => b) * 6 * 3
            };
            _vertexBuffer.AddSpec(_dataSpecification);
            _vertexBuffer.CalculateMaxSize();
            _vertexBuffer.Bind();
            _vertexBuffer.Initialise();

            _vertexArray.Load(_shaderProgram, _vertexBuffer);
            _vertexArray.UnBind();
        }
Exemplo n.º 16
0
        public void Update(double time, bool updateRadius, double azimuth)
        {
            //Set azimuth for all beats
            for (int i = DrawingIndex; i < DrawingCount; i++)
            {
                _positions[i].Azimuth = azimuth;
            }
            //Update radius for all beats
            if (updateRadius)
            {
                for (int i = DrawingIndex; i < DrawingCount; i++)
                {
                    _positions[i].Radius -= (time * _velocities[i].Radius);
                    if (_positions[i].Radius + _widths[i] <= _impactDistances[i] - _impactBuffer)
                    {
                        DrawingIndex++;
                    }
                }
            }

            if (_vertexArray == null)
            {
                InitialiseRendering();
            }

            _vertexBuffer.Bind();
            _outlineOffset = BuildVertexList();
            _vertexBuffer.DrawableIndices = _outlineOffset * 2;
            _vertexBuffer.Initialise();
            _vertexBuffer.SetData(vertexList, _dataSpecification);
            _vertexBuffer.UnBind();
        }
Exemplo n.º 17
0
        public void CreateVerticesForSquare_angled()
        {
            //  Create the vertex array object.
            vertexBufferArray.Bind(gl);

            //  Create a vertex buffer for the vertex data.
            vertexDataBuffer.Bind(gl);
            vertexDataBuffer.SetData(gl, 0, Data.vertices_arrayed, false, 3);

            //  Now do the same for the colour data.
            colourDataBuffer.Bind(gl);
            colourDataBuffer.SetData(gl, 1, Data.colours_arrayed, false, 3);

            shiftedcenterDataBuffer.Bind(gl);
            shiftedcenterDataBuffer.SetData(gl, 2, Data.center_arrayed, false, 3);

            sizeDataBuffer.Bind(gl);
            sizeDataBuffer.SetData(gl, 3, Data.size_arrayed, false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(gl);
            vertexDataBuffer.Unbind(gl);
            colourDataBuffer.Unbind(gl);
            shiftedcenterDataBuffer.Unbind(gl);
            sizeDataBuffer.Unbind(gl);
        }
Exemplo n.º 18
0
        private void UpdateItem(int index)
        {
            numVertices = 0;

            if (index >= 0 && index < Variables.Count)
            {
                ObservedVariable variable = Variables[index];

                if (DebugHandler.Debugger.CurrentMode == dbgDebugMode.dbgBreakMode)
                {
                    PointCloud pointCloud = null;

                    if (variable.MemberData == null)
                    {
                        pointCloud = DebugHandler.Load(variable.Name);
                    }
                    else
                    {
                        pointCloud = DebugHandler.Load(variable.Name, variable.MemberData);
                    }

                    if (pointCloud != null)
                    {
                        OpenGL gl = openGLControl.OpenGL;

                        vao.Bind(gl);

                        vbo.Bind(gl);
                        gl.BufferData(OpenGL.GL_ARRAY_BUFFER, pointCloud.vertices, OpenGL.GL_STATIC_DRAW);
                        numVertices = pointCloud.numVertices;
                    }
                }
            }
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
 public static VertexIndices FromBuffer(VertexBuffer indexBuffer, int count, DrawElementsType indexType)
 {
     return new VertexIndices((t) =>
     {
         indexBuffer.Bind(BufferTarget.ElementArrayBuffer, (b) =>
             GL.DrawElements(t, count, indexType, IntPtr.Zero));
     });
 }
Exemplo n.º 21
0
        public override void Render(NkHandle Userdata, GL_Texture Texture, NkRect ClipRect, uint Offset, uint Count)
        {
            float[] vert   = new float[Count * 2];
            float[] uvs    = new float[Count * 2];
            float[] colors = new float[Count * 4];

            for (int i = 0; i < Count; i++)
            {
                NkVertex V = Verts[Inds[Offset + i]];
                vert[i * 2]     = V.Position.X;
                vert[i * 2 + 1] = V.Position.Y;

                uvs[i * 2]     = V.UV.X;
                uvs[i * 2 + 1] = V.UV.Y;

                NkColor color = V.Color;
                colors[i * 4]     = color.R;
                colors[i * 4 + 1] = color.G;
                colors[i * 4 + 2] = color.B;
                colors[i * 4 + 3] = color.A;
            }



            var vertexDataBuffer = new VertexBuffer();

            vertexDataBuffer.Create(gl);
            vertexDataBuffer.Bind(gl);


            vertexDataBuffer.SetDataV2F(gl, 0, rawData, NkVertex.SIZE * (int)Count, false, 3);

            //    vertexDataBuffer.SetData(gl, 0, vert, false, 2);

            var colourDataBuffer = new VertexBuffer();

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

            var uvDataBuffer = new VertexBuffer();

            uvDataBuffer.Create(gl);
            uvDataBuffer.Bind(gl);
            uvDataBuffer.SetData(gl, 2, uvs, false, 2);

            gl.ActiveTexture(OpenGL.GL_TEXTURE0);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, Texture.TextureName);
            glScissor2(window.DisplayHeight, (int)ClipRect.X, (int)ClipRect.Y, (int)ClipRect.W, (int)ClipRect.H);
            gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, (int)Count);

            vertexDataBuffer.Unbind(gl);
            //  colourDataBuffer.Unbind(gl);
            //  uvDataBuffer.Unbind(gl);
        }
Exemplo n.º 22
0
        public void Update(float[] vertices)
        {
            Bind();

            VertexBuffer.Bind();
            VertexBuffer.SetData(sizeof(float) * vertices.Length, vertices);

            VertexCount = vertices.Length / Dimensions;

            Unbind();
        }
Exemplo n.º 23
0
        public Veldrid.CommandList BuildStandardCommandList()
        {
            if (CommandList == null)
            {
                CommandList = Renderer.VeldridFactory.CreateCommandList();
            }

            CommandList.Begin();
            CommandList.SetFramebuffer(Renderer.GraphicsDevice.SwapchainFramebuffer);

            if (ClearColor.HasValue)
            {
                float[] Floats = ClearColor.Value.GetFloats();
                CommandList.ClearColorTarget(0, new RgbaFloat(Floats[0], Floats[1], Floats[2], Floats[3]));
            }

            if (VertexBuffer != null)
            {
                if (!VertexBuffer.Bound)
                {
                    VertexBuffer.Bind();
                }
                VeldridCamera vCam = Camera as VeldridCamera;
                vCam.Update();

                UpdateModelBuffer();

                VeldridTexture texture = Texture as VeldridTexture;

                CommandList.SetVertexBuffer(0, (VertexBuffer as VeldridVertexBuffer).VertexBuffer);
                CommandList.SetIndexBuffer((VertexBuffer as VeldridVertexBuffer).IndexBuffer, IndexFormat.UInt16);
                if (texture != null)
                {
                    CommandList.SetPipeline((Material as VeldridMaterial).TexturedPipeline);
                }
                else
                {
                    CommandList.SetPipeline((Material as VeldridMaterial).UntexturedPipeline);
                }
                CommandList.SetGraphicsResourceSet(0, vCam.ProjectionViewResourceSet);
                CommandList.SetGraphicsResourceSet(1, ModelResourceSet);

                if (texture != null)
                {
                    CommandList.SetGraphicsResourceSet(2, texture.GetTextureResourceSet());
                }

                CommandList.DrawIndexed((uint)NumIndicies, 1, (uint)StartIndex, 0, 0);
            }

            CommandList.End();

            return(CommandList);
        }
Exemplo 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]  = -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);
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
0
        protected override void OnLoad(EventArgs e)
        {
            cam = new Kamera(this, new Vector3(0.0f, 0.0f, 3.0f), new Vector3(0, 0, 0), 0.1f, 0.05f);

            VertexBuffer <float> vbo = new VertexBuffer <float>();

            vbo.Bind();
            vbo.BufferData(vertices);

            boxVao = new VertexArray();
            boxVao.Bind();
            boxVao.SetVertexAttrib <float>(0, 3, VertexAttribPointerType.Float, false, 8, 0); //pos
            boxVao.SetVertexAttrib <float>(1, 3, VertexAttribPointerType.Float, false, 8, 3); //norm
            boxVao.SetVertexAttrib <float>(2, 2, VertexAttribPointerType.Float, false, 8, 6); //texCoord
            boxVao.Unbind();

            lampVao = new VertexArray();
            lampVao.Bind();
            vbo.Bind();                                                                        //müssen wir nochmal
            lampVao.SetVertexAttrib <float>(0, 3, VertexAttribPointerType.Float, false, 8, 0); //pos
            lampVao.SetVertexAttrib <float>(1, 3, VertexAttribPointerType.Float, false, 8, 3); //norm
            lampVao.SetVertexAttrib <float>(2, 2, VertexAttribPointerType.Float, false, 8, 6); //texCoord
            lampVao.Unbind();
            vbo.Unbind();


            lightingShader = new ShaderProgram(Shader.FromFile("Shader/vertexBase.c"), Shader.FromFile("Shader/fragmentBase.c"));
            lampShader     = new ShaderProgram(Shader.FromFile("Shader/vertexBase.c"), Shader.FromFile("Shader/fragmentLamp.c"));

            diffuseMapTexture  = new Texture("Data/container2.png", 0, "material.diffuse");
            specularMapTexture = new Texture("Data/container2_specular.png", 1, "material.specular");

            containerMat = new Material();
            containerMat.AddTexture("diffuse", diffuseMapTexture);
            containerMat.AddTexture("specular", specularMapTexture);
            containerMat.AddFloat("shininess", 32.0f);

            GL.Enable(EnableCap.DepthTest);
        }
Exemplo n.º 27
0
        protected override void OnRenderFrame(FrameEventArgs evt)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            _shader.Use();
            _vertexBuffer.Bind();

            GL.BindVertexArray(_vertexArrayObject);
            GL.DrawArrays(PrimitiveType.Triangles, 0, _vertices.Length);

            Context.SwapBuffers();
            base.OnRenderFrame(evt);
        }
Exemplo n.º 28
0
        public void Draw(OpenGL gl, int width, int height)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);  // Clear The Screen And The Depth Buffer

            int windowID       = gl.GetUniformLocation(_prog.ShaderProgramObject, "window");
            int nID            = gl.GetUniformLocation(_prog.ShaderProgramObject, "n");
            int baseHueID      = gl.GetUniformLocation(_prog.ShaderProgramObject, "base_hue");
            int colorizeID     = gl.GetUniformLocation(_prog.ShaderProgramObject, "colorize");
            int thicknessID    = gl.GetUniformLocation(_prog.ShaderProgramObject, "thickness");
            int minThicknessID = gl.GetUniformLocation(_prog.ShaderProgramObject, "min_thickness");
            int thinningID     = gl.GetUniformLocation(_prog.ShaderProgramObject, "thinning");
            int decayID        = gl.GetUniformLocation(_prog.ShaderProgramObject, "decay");
            int desaturationID = gl.GetUniformLocation(_prog.ShaderProgramObject, "desaturation");

            gl.Uniform2(windowID, (float)width, (float)height);
            gl.Uniform1(nID, 5);
            gl.Uniform1(thicknessID, 5.0f);
            gl.Uniform1(minThicknessID, 1.5f);
            gl.Uniform1(thinningID, 0.05f);
            gl.Uniform1(baseHueID, 0.0f);
            gl.Uniform1(colorizeID, 1);
            gl.Uniform1(decayID, 0.3f);
            gl.Uniform1(desaturationID, 0.1f);

            // Run the clear program.
            gl.UseProgram(_clearProg.ShaderProgramObject);

            VertexBuffer clearVertexBuffer = new VertexBuffer();

            clearVertexBuffer.Create(gl);
            clearVertexBuffer.Bind(gl);
            clearVertexBuffer.SetData(gl, 0, _clearRectangle, false, CLEAR_DATA_STRIDE);

            //gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, _clearRectangle.Length);

            // Attempt to get an available audio sample.
            var data = _audioScope.GetSample();

            if (data != null)
            {
                // Run the main program.
                gl.UseProgram(_prog.ShaderProgramObject);

                VertexBuffer vertexBuffer = new VertexBuffer();
                vertexBuffer.Create(gl);
                vertexBuffer.Bind(gl);
                vertexBuffer.SetData(gl, 0, data, false, MAIN_DATA_STRIDE);

                gl.DrawArrays(OpenGL.GL_LINE_STRIP_ADJACENCY, 0, data.Length);
            }
        }
Exemplo n.º 29
0
        public override void Render()
        {
            GL.UseProgram(Shader.Program);

            GL.ActiveTexture(TextureUnit.Texture3);
            GL.BindTexture(TextureTarget.TextureCubeMap, TextureID);
            GL.Uniform1(GL.GetUniformLocation(Shader.Program, "cubeMapTex"),
                        TextureUnit.Texture3 - TextureUnit.Texture0);

            VertexBuffer.Bind(Shader);
            GL.UseProgram(0);

            GL.BindTexture(TextureTarget.TextureCubeMap, 0);
        }
        public void UpdateBuffers(int numSprites, float[] vertices, float[] uvs, byte[] colors)
        {
            VertexBuffer.Bind();
            //VertexBuffer.Invalidate();
            VertexBuffer.SetSubData(numSprites * 8 * sizeof(float), 0, vertices);

            UVBuffer.Bind();
            //UVBuffer.Invalidate();
            UVBuffer.SetSubData(numSprites * 8 * sizeof(float), 0, uvs);

            ColorBuffer.Bind();
            //ColorBuffer.Invalidate();
            ColorBuffer.SetSubData(numSprites * 16 * sizeof(byte), 0, colors);
        }
Exemplo n.º 31
0
        public void BuildVertexArray()
        {
            foreach (var block in Blocks)
            {
                if (block is IBlockModel)
                {
                    var blockModel = block as IBlockModel;

                    ElementCount  += blockModel.Model.ElementCount;
                    VertecesCount += blockModel.Model.VertexCount;
                }
            }

            Vertices = new Vertex[VertecesCount];
            Elements = new uint[ElementCount];

            uint vertexPos  = 0;
            uint elementPos = 0;

            foreach (var block in Blocks)
            {
                var tempVertexPos = vertexPos;

                if (block is IBlockModel)
                {
                    var blockModel = block as IBlockModel;

                    blockModel.Model.Vertices.CopyTo(Vertices, vertexPos);
                    vertexPos += blockModel.Model.VertexCount;

                    foreach (var element in blockModel.Model.Elements)
                    {
                        Elements[elementPos] = tempVertexPos + element;
                        elementPos++;
                    }
                }
            }

            VertexBuffer = new VertexBuffer();
            IndexBuffer  = new IndexBuffer();

            VertexBuffer.Create();
            VertexBuffer.Bind();
            VertexBuffer.SetData(RawDataCreation.GenRawVertexData(Vertices));

            IndexBuffer.Create();
            IndexBuffer.Bind();
            IndexBuffer.SetData(Elements);
        }
Exemplo n.º 32
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);
        }
Exemplo n.º 33
0
        public static Terrain Build(IOpenGL33 gl, int columns, int rows, float width, float depth)
        {
            var noise = new PerlinNoise();
            var noise2 = new PerlinNoise();
            
            var vertexBuffer = new VertexBuffer<PositionNormalTexCoord>((columns + 1) * (rows + 1), gl);
            var indexBuffer = new ElementBuffer<uint>(columns * rows * 6 , gl);

            float fx = - width / 2;
            float fy = -depth / 2;

            float dx = width / columns;
            float dy = depth / rows;

            int i = 0;

            for (int y = 0; y < (rows + 1); y++)
            {
                for (int x = 0; x < (columns + 1); x++, i++)
                {
                    float ix = fx + x * dx;
                    float iy = fy + y * dy;

                    const float detail = 0.25f;
                    const float detailScale = 0.2f;
                    const float macro = 0.008f;
                    const float macroScale = 4f;
                    var fUp = (float)((noise.Noise(x * detail, 0, (y + 1) * detail) - noise2.Noise(x * detail, 0, (y + 1) * detail) * 0.25f) * detailScale + noise.Noise(x * macro, 0, (y + 1) * macro) * macroScale) ;
                    var fDown = (float)((noise.Noise(x * detail, 0,  (y - 1) * detail) - noise2.Noise(x * detail, 0,  (y - 1) * detail) * 0.25f) * detailScale + noise.Noise(x * macro, 0,  (y - 1) * macro) * macroScale) ;
                    var fLeft = (float)((noise.Noise((x - 1) * detail, 0, y * detail) - noise2.Noise((x - 1) * detail, 0, y * detail) * 0.25f) * detailScale + noise.Noise((x - 1) * macro, 0, y * macro) * macroScale);
                    var fRight = (float)((noise.Noise((x + 1) * detail, 0, y * detail) - noise2.Noise((x + 1) * detail, 0, y * detail) * 0.25f) * detailScale + noise.Noise((x + 1) * macro, 0, y * macro) * macroScale);
                    var fThis = (float)((noise.Noise(x * detail, 0, y * detail) - noise2.Noise(x * detail, 0, y * detail) * 0.25f) * detailScale + noise.Noise(x * macro, 0, y * macro) * macroScale);

                    var vUp = new Vector3f(ix, fUp, iy - dy);
                    var vDown = new Vector3f(ix, fDown, iy + dy);
                    var vLeft = new Vector3f(ix - 1, fLeft, iy);
                    var vRight = new Vector3f(ix + 1, fRight, iy);
                    var vThis = new Vector3f(ix, fThis, iy);

                    var upperLeft = CalculateNormal(vLeft, vUp, vThis);
                    var upperRight = CalculateNormal(vUp, vRight, vThis);
                    var lowerRight = CalculateNormal(vRight, vDown, vThis);
                    var lowerLeft = CalculateNormal(vDown, vLeft, vThis);

                    var normal = upperLeft + upperRight + lowerLeft + lowerRight;
                    normal = new Vector3f(normal.X * 0.25f, normal.Y * 0.25f, normal.Z * 0.25f);

                    vertexBuffer[i] = new PositionNormalTexCoord { Normal = normal.Normalize(), Position = vThis, TexCoord = new Vector2f(vThis.X, vThis.Z)};
                }
            }
            int offset = 0;
            foreach(var index in Enumerable.Range(0, columns * rows + columns).Where(index => (index % (columns + 1)) != columns))
            {
                indexBuffer[offset] = (uint)index;
                indexBuffer[offset + 1] = (uint)(index + (columns + 1) + 1); 
                indexBuffer[offset + 2] = (uint)index + 1;

                indexBuffer[offset + 3] = (uint)index;                
                indexBuffer[offset + 4] = (uint)(index + (columns + 1));
                indexBuffer[offset + 5] = (uint)(index + (columns + 1) + 1);
                offset += 6;
            }

            using(vertexBuffer.Bind())
                vertexBuffer.BufferData(BufferUsage.StaticDraw);

            using(indexBuffer.Bind())
                indexBuffer.BufferData(BufferUsage.StaticDraw);

            var vertexArray = new VertexArray(gl, new[] {vertexBuffer}, new[] {PositionNormalTexCoord.Descriptor});

            var shader = new TerrainShader(gl);

            return new Terrain(gl, vertexArray, vertexBuffer, indexBuffer, shader);
        }
Exemplo n.º 34
0
        private IVertexBuffer CreateBuffer()
        {
            var result = new VertexBuffer<Vertex>(36, gl);
            
            // Set up every face omn the cube
            // Top
            result[0]  = new Vertex { Position = new Vector3f(-1, 1,  1), Normal = new Vector3f(0, 1, 0)};
            result[1]  = new Vertex { Position = new Vector3f( 1, 1,  1), Normal = new Vector3f(0, 1, 0) };
            result[2]  = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(0, 1, 0) };
            
            result[3]  = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(0, 1, 0) };
            result[4]  = new Vertex { Position = new Vector3f( 1, 1,  1), Normal = new Vector3f(0, 1, 0) };
            result[5]  = new Vertex { Position = new Vector3f( 1, 1, -1), Normal = new Vector3f(0, 1, 0) };

            // Bottom
            result[6]  = new Vertex { Position = new Vector3f(-1, -1,  1), Normal = new Vector3f(0,  -1, 0) };
            result[7] = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(0, -1, 0) };
            result[8]  = new Vertex { Position = new Vector3f( 1, -1,  1), Normal = new Vector3f(0,  -1, 0) };
            

            result[9]  = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(0, -1, 0) };
            result[10] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(0, -1, 0) };
            result[11] = new Vertex { Position = new Vector3f( 1, -1,  1), Normal = new Vector3f(0, -1, 0) };
            
            // Left
            result[12] = new Vertex { Position = new Vector3f(-1, 1, 1), Normal = new Vector3f(-1, 0, 0)};
            result[13] = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(-1, 0, 0) };
            result[14] = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(-1, 0, 0) };

            result[15] = new Vertex { Position = new Vector3f(-1, 1, 1), Normal = new Vector3f(-1, 0, 0) };
            result[16] = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(-1, 0, 0) };
            result[17] = new Vertex { Position = new Vector3f(-1, -1, 1), Normal = new Vector3f(-1, 0, 0) };

            // Right
            result[18] = new Vertex { Position = new Vector3f(1, 1, 1), Normal = new Vector3f(1, 0, 0) };
            result[19] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(1, 0, 0) };
            result[20] = new Vertex { Position = new Vector3f(1, 1, -1), Normal = new Vector3f(1, 0, 0) };

            result[21] = new Vertex { Position = new Vector3f(1, 1, 1), Normal = new Vector3f(1, 0, 0) };
            result[22] = new Vertex { Position = new Vector3f(1, -1, 1), Normal = new Vector3f(1, 0, 0) };
            result[23] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(1, 0, 0) };

            // Front
            result[24] = new Vertex {Position = new Vector3f(-1, 1, 1), Normal = new Vector3f(0, 0, 1)};
            result[25] = new Vertex { Position = new Vector3f(1, -1, 1), Normal = new Vector3f(0, 0, 1) };
            result[26] = new Vertex { Position = new Vector3f(1, 1, 1), Normal = new Vector3f(0, 0, 1) };

            result[27] = new Vertex { Position = new Vector3f(-1, 1, 1), Normal = new Vector3f(0, 0, 1) };
            result[29] = new Vertex { Position = new Vector3f(1, -1, 1), Normal = new Vector3f(0, 0, 1) };
            result[28] = new Vertex { Position = new Vector3f(-1, -1, 1), Normal = new Vector3f(0, 0, 1) };

            // Back
            result[30] = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(0, 0, -1) };
            result[32] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(0, 0, -1) };
            result[31] = new Vertex { Position = new Vector3f(1, 1, -1), Normal = new Vector3f(0, 0, -1) };

            result[33] = new Vertex { Position = new Vector3f(-1, 1, -1), Normal = new Vector3f(0, 0, -1) };
            result[34] = new Vertex { Position = new Vector3f(1, -1, -1), Normal = new Vector3f(0, 0, -1) };
            result[35] = new Vertex { Position = new Vector3f(-1, -1, -1), Normal = new Vector3f(0, 0, -1) };
            

            using (result.Bind())
            {
                result.BufferData(BufferUsage.StaticDraw);
            }

            return result;
        }