Exemple #1
0
        public Axes(float size, float width = 3.0f)
        {
            m_Size  = size;
            m_Width = width;

            // X Axis only
            vertices = new float[]
            {
                // Position             // Color
                0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                m_Size, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,

                0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
                0.0f, m_Size, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,

                0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f,
                0.0f, 0.0f, m_Size, 0.0f, 0.0f, 1.0f, 1.0f
            };

            m_Vao = new VertexArray();
            m_Vbo = new VertexBuffer(vertices, (uint)(vertices.Length * sizeof(float)));

            VertexBufferLayout layout = new VertexBufferLayout();

            layout.PushFloat(3, false);
            layout.PushFloat(4, false);
            m_Vao.AddBuffer(m_Vbo, layout);

            m_Shader = Shader.GetShader(ShaderFiles.Axes);

            m_Vao.Unbind();
            m_Shader.Unbind();
            m_Vbo.Unbind();
        }
Exemple #2
0
        /// <summary>
        /// Initiates the buffers needed to render with OpenGl
        /// </summary>
        public void InitOpenGlBuffers()
        {
            var openGlVertices     = VertexToOpenGlVertex(m_Vertices);
            var openGlVerticesFlat = VertexToOpenGlVertex(m_VerticesFlat);

            m_Vao = new VertexArray();
            m_Vbo = new VertexBuffer(openGlVertices.ToArray(), (uint)(openGlVertices.Count * Marshal.SizeOf(openGlVertices[0])));

            VertexBufferLayout layout = new VertexBufferLayout();

            layout.PushFloat(3, false);
            layout.PushFloat(3, false);
            layout.PushFloat(4, false);
            m_Vao.AddBuffer(m_Vbo, layout);

            m_Ibo = new IndexBuffer(m_OpenGlIndices.ToArray(), (uint)m_OpenGlIndices.Count);

            MeshMaterial.MatShader.Bind();
            MeshMaterial.MatShader.SetUniformMat4("u_Model", TransformationMatrix);
            MeshMaterial.MatShader.SetUniformMat3("u_ModelNormalMatrix", NormalTransformMatrix);

            m_Vao.Unbind();
            m_Vbo.Unbind();
            m_Ibo.Unbind();


            m_VaoFlat = new VertexArray();
            m_VboFlat = new VertexBuffer(openGlVerticesFlat.ToArray(),
                                         (uint)(openGlVerticesFlat.Count * Marshal.SizeOf(openGlVerticesFlat[0])));
            m_VaoFlat.AddBuffer(m_VboFlat, layout);

            m_VaoFlat.Unbind();
            m_VboFlat.Unbind();
        }
Exemple #3
0
        public FrameBuffer()
        {
            RendererID = Gl.GenFramebuffer();

            m_Vertices = new float[]
            {
                // positions   // texCoords
                0.5f, 1.0f, 0.0f, 1.0f,
                0.5f, 0.5f, 0.0f, 0.0f,
                1.0f, 0.5f, 1.0f, 0.0f,

                0.5f, 1.0f, 0.0f, 1.0f,
                1.0f, 0.5f, 1.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 1.0f
            };

            m_VAO = new VertexArray();
            m_VBO = new VertexBuffer(m_Vertices, (uint)m_Vertices.Length * sizeof(float));
            VertexBufferLayout layout = new VertexBufferLayout();

            layout.PushFloat(2, false);
            layout.PushFloat(2, false);
            m_VAO.AddBuffer(m_VBO, layout);

            m_VAO.Unbind();
        }
Exemple #4
0
        private void InitOpenGlBuffers()
        {
            m_Vao = new VertexArray();
            m_Vbo = new VertexBuffer(m_Vertices, (uint)m_Vertices.Length * sizeof(float));

            VertexBufferLayout layout = new VertexBufferLayout();

            layout.PushFloat(3, false);
            m_Vao.AddBuffer(m_Vbo, layout);

            m_Ibo = new IndexBuffer(m_Indices, (uint)m_Indices.Length);

            m_Vao.Unbind();
            m_Ibo.Unbind();
        }
Exemple #5
0
        private void InitOpenGlBuffers()
        {
            m_Vao = new VertexArray();
            m_Vbo = new VertexBuffer(m_Vertices.ToArray(),
                                     (uint)(m_Vertices.Count * sizeof(float)));

            VertexBufferLayout layout = new VertexBufferLayout();

            layout.PushFloat(3, false);
            m_Vao.AddBuffer(m_Vbo, layout);

            m_Shader = Shader.GetShader(ShaderFiles.LinesConstant);

            m_Vao.Unbind();
            m_Vbo.Unbind();
        }
Exemple #6
0
        public void AddBuffer(VertexBuffer vb, VertexBufferLayout layout)
        {
            Bind();
            vb.Bind();
            uint offset = 0;

            for (int i = 0; i < layout.Elements.Count; i++)
            {
                VertexBufferElement element = layout.Elements[i];
                Gl.VertexAttribPointer((uint)i, (int)element.Count, element.Type, element.IsNormalized,
                                       (int)layout.Stride, new IntPtr(offset));
                Gl.EnableVertexAttribArray((uint)i);

                offset += element.Count * VertexBufferElement.GetSizeOfType(element.Type);
            }
        }
Exemple #7
0
        private void DrawSilhouette(Renderer renderer, Camera camera)
        {
            if (Settings.CurrentShading == ShadingOption.BoundingBox)
            {
                return;
            }

            List <float> vertices = new List <float>();

            foreach (var hE in m_HalfEdges.Values)
            {
                Vertex startV = hE.Origin;
                Vertex endV   = hE.Next.Origin;

                if (hE.Twin == null)
                {
                    vertices.AddRange(startV.Position.to_array());
                    vertices.AddRange(endV.Position.to_array());
                    continue;
                }

                bool isF1BackFace = IsBackFace(camera, hE.LeftFace);
                bool isF2BackFace = IsBackFace(camera, hE.Twin.LeftFace);

                if (isF1BackFace && !isF2BackFace || !isF1BackFace && isF2BackFace)
                {
                    vertices.AddRange(startV.Position.to_array());
                    vertices.AddRange(endV.Position.to_array());
                }
            }

            if (m_VboSil != null)
            {
                m_VboSil.Destroy();
            }
            if (m_VaoSil != null)
            {
                m_VaoSil.Destroy();
            }

            m_VaoSil = new VertexArray();
            m_VboSil = new VertexBuffer(vertices.ToArray(), (uint)(vertices.Count * sizeof(float)));

            VertexBufferLayout layout = new VertexBufferLayout();

            layout.PushFloat(3, false);
            m_VaoSil.AddBuffer(m_VboSil, layout);

            Shader shader = Shader.GetShader(ShaderFiles.LinesConstant);

            shader.Bind();
            shader.SetUniform4f("u_Color", Settings.ColorSelected.x, Settings.ColorSelected.y,
                                Settings.ColorSelected.z, Settings.ColorSelected.w);
            shader.SetUniformMat4("u_Model", TransformationMatrix);
            shader.SetUniformMat4("u_View", camera.ViewMatrix);
            shader.SetUniformMat4("u_Projection", camera.ProjectionMatrix);

            Scene.Instance.SetHiddenSurfaceRemoval(false);
            renderer.DrawLines(m_VaoSil, vertices.Count, 3.0f, shader);
            Scene.Instance.SetHiddenSurfaceRemoval(true);
        }
Exemple #8
0
        public void InitOpenGlBuffers()
        {
            // Init Main Buffers
            if (m_VaoMain != null)
            {
                m_VaoMain.Destroy();
            }
            m_VaoMain = new VertexArray();

            if (m_VboMain != null)
            {
                m_VboMain.Destroy();
            }
            m_VboMain = new VertexBuffer(m_Vertices.ToArray(),
                                         (uint)(m_Vertices.Count * sizeof(float)));

            VertexBufferLayout layout = new VertexBufferLayout();

            layout.PushFloat(3, false);
            m_VaoMain.AddBuffer(m_VboMain, layout);

            m_VaoMain.Unbind();
            m_VboMain.Unbind();

            // Init Arrow Buffers
            if (m_VaoArrow != null)
            {
                m_VaoArrow.Destroy();
            }
            m_VaoArrow = new VertexArray();

            if (m_VboArrow != null)
            {
                m_VboArrow.Destroy();
            }
            m_VboArrow = new VertexBuffer(m_ArrowVertices.ToArray(),
                                          (uint)(m_ArrowVertices.Count * sizeof(float)));

            layout = new VertexBufferLayout();
            layout.PushFloat(3, false);
            m_VaoArrow.AddBuffer(m_VboArrow, layout);

            m_VaoArrow.Unbind();
            m_VboArrow.Unbind();

            // Init Selection Buffers
            if (m_VaoSelection != null)
            {
                m_VaoSelection.Destroy();
            }
            m_VaoSelection = new VertexArray();

            if (m_VboSelection != null)
            {
                m_VboSelection.Destroy();
            }
            m_VboSelection = new VertexBuffer(m_SelectionVertices.ToArray(),
                                              (uint)(m_SelectionVertices.Count * sizeof(float)));

            layout = new VertexBufferLayout();
            layout.PushFloat(3, false);
            m_VaoSelection.AddBuffer(m_VboSelection, layout);

            m_IboSelection = new IndexBuffer(m_SelectionIndices.ToArray(), (uint)m_SelectionIndices.Count);

            m_VaoArrow.Unbind();
            m_VboArrow.Unbind();
            m_IboSelection.Unbind();
        }