当前位置: 首页>>代码示例>>C#>>正文


C# OpenGL.EnableVertexAttribArray方法代码示例

本文整理汇总了C#中SharpGL.OpenGL.EnableVertexAttribArray方法的典型用法代码示例。如果您正苦于以下问题:C# OpenGL.EnableVertexAttribArray方法的具体用法?C# OpenGL.EnableVertexAttribArray怎么用?C# OpenGL.EnableVertexAttribArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SharpGL.OpenGL的用法示例。


在下文中一共展示了OpenGL.EnableVertexAttribArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VAO

        public VAO(OpenGL gl, IShaderProgram program, VBO vbo)
        {
            _gl = gl;
            _program = program;
            VBO = vbo;

            var buffers = new uint[1];
            gl.GenVertexArrays(1, buffers);
            Handle = buffers[0];

            using (new Bind(program))
            using (new Bind(this))
            using (new Bind(vbo))
            {
                var stride = Vect3f.SizeInBytes * 2 + Vect4f.SizeInBytes;

                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, true, stride, IntPtr.Zero);
                gl.BindAttribLocation(program.Handle, 0, "vert_position");

                gl.EnableVertexAttribArray(1);
                gl.VertexAttribPointer(1, 3, OpenGL.GL_FLOAT, true, stride, new IntPtr(Vect3f.SizeInBytes));
                gl.BindAttribLocation(program.Handle, 1, "vert_normal");

                gl.EnableVertexAttribArray(2);
                gl.VertexAttribPointer(2, 4, OpenGL.GL_FLOAT, false, stride, new IntPtr(Vect3f.SizeInBytes * 2));
                gl.BindAttribLocation(program.Handle, 2, "vert_colour");
            }
        }
开发者ID:rho24,项目名称:OpenCAD,代码行数:29,代码来源:VAO.cs

示例2: BindVBOs

        public void BindVBOs(OpenGL gl, LinesProgram program)
        {
            var attribPos = program.Attribs["Position"];
            gl.BindBuffer(_vboTarget, Position);
            gl.VertexAttribPointer(attribPos, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.EnableVertexAttribArray(attribPos);

            attribPos = program.Attribs["ColorValue"];
            gl.BindBuffer(_vboTarget, ColorValue);
            gl.VertexAttribPointer(attribPos, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.VertexAttribDivisor(attribPos, 1);
            gl.EnableVertexAttribArray(attribPos);

            if (IndicesCount > 0)
                gl.BindBuffer(_iboTarget, Ibo);
        }
开发者ID:jochemgeussens,项目名称:sharpgl,代码行数:16,代码来源:LinesBufferGroup.cs

示例3: DrawTrefoilBuffers

        private void DrawTrefoilBuffers(OpenGL gl)
        {
            //  Bind the vertex and index buffer.
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBuffer);
            gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);

            gl.EnableVertexAttribArray(attrPosition);
            gl.EnableVertexAttribArray(attrNormal);

            //  Draw the geometry, straight from the vertex buffer.
            gl.VertexAttribPointer(attrPosition, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Zero);
            int normalOffset = Marshal.SizeOf(typeof(Vertex));
            gl.VertexAttribPointer(attrNormal, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Add(new IntPtr(0), normalOffset));

            gl.DrawElements(OpenGL.GL_LINES, (int)trefoilKnot.IndexCount, OpenGL.GL_UNSIGNED_SHORT, IntPtr.Zero);

        }
开发者ID:RFExplorer,项目名称:rfexplorer-1,代码行数:17,代码来源:MainWindow.xaml.cs

示例4: BackgroundRenderer

        public BackgroundRenderer(OpenGL gl)
        {
            _gl = gl;

            _program = new BackgroundShader(gl);
            _flat = new VAO(gl);
            _flatBuffer = new VBO(gl);

            using (new Bind(_flat))
            using (new Bind(_flatBuffer))
            {
                var flatData = new float[] { -1, -1, 1, -1, -1, 1, 1, 1, };
                _flatBuffer.Update(flatData, flatData.Length * sizeof(float));
                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
                gl.BindVertexArray(0);
            }
        }
开发者ID:veggielane,项目名称:OpenCAD,代码行数:18,代码来源:OctreeRenderer.cs

示例5: PostProcesser

        public PostProcesser(OpenGL gl,int width,int height)
        {
            _gl = gl;
            _fbo = new FBO(gl, width, height);

            _flatProgram = new FlatShader(gl);

            _flat = new VAO(gl);
            _flatBuffer = new VBO(gl);

            using (new Bind(_flat))
            using (new Bind(_flatBuffer))
            {
                var flatData = new float[] { -1, -1, 1, -1, -1, 1, 1, 1, };
                _flatBuffer.Update(flatData, flatData.Length * sizeof(float));
                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
                gl.BindVertexArray(0);
            }
        }
开发者ID:veggielane,项目名称:OpenCAD,代码行数:20,代码来源:PostProcesser.cs

示例6: OctreeRenderer

        public OctreeRenderer(OctreeModel model, OpenGL gl)
        {
            _gl = gl;
            _octreeProgram = new OctreeShader(gl);
            _cubes = new VAO(gl);
            _cubeBuffer = new VBO(gl);

            var filled = model.Node.Flatten().Where(o => o.State == NodeState.Filled).ToArray();
            _count = filled.Length;
            var list = new List<float>();
            foreach (var octreeNode in filled)
            {
                list.AddRange(octreeNode.Center.ToArray().Select(d => (float)d));

                list.AddRange(new[]
                        {
                            (float)MathsHelper.Map(octreeNode.Color.R, 0, 255, 0, 1),
                            (float)MathsHelper.Map(octreeNode.Color.G, 0, 255, 0, 1),
                            (float)MathsHelper.Map(octreeNode.Color.B, 0, 255, 0, 1),
                            (float)MathsHelper.Map(octreeNode.Color.A, 0, 255, 0, 1),
                            (float)octreeNode.Size
                        });
            }

            var vertices = list.ToArray();

            using (new Bind(_cubes))
            using (new Bind(_cubeBuffer))
            {
                _cubeBuffer.Update(vertices, vertices.Length * sizeof(float));
                const int stride = sizeof(float) * 8;
                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, stride, new IntPtr(0));

                gl.EnableVertexAttribArray(1);
                gl.VertexAttribPointer(1, 4, OpenGL.GL_FLOAT, false, stride, new IntPtr(sizeof(float) * 3));

                gl.EnableVertexAttribArray(2);

                gl.VertexAttribPointer(2, 1, OpenGL.GL_FLOAT, false, stride, new IntPtr(sizeof(float) * 7));
                gl.BindVertexArray(0);
            }
        }
开发者ID:veggielane,项目名称:OpenCAD,代码行数:43,代码来源:OctreeRenderer.cs

示例7: CreateVertexArrayObject

        private void CreateVertexArrayObject(OpenGL gl, RenderMode renderMode)
        {
            if (this.positionBuffer == null || this.colorBuffer == null) { return; }

            this.vertexArrayObject = new uint[1];
            gl.GenVertexArrays(1, this.vertexArrayObject);
            gl.BindVertexArray(this.vertexArrayObject[0]);

            // prepare positions
            {
                int location = shaderProgram.GetAttributeLocation(gl, in_Position);
                ATTRIB_INDEX_POSITION = (uint)location;
                gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, positionBuffer[0]);
                gl.VertexAttribPointer(ATTRIB_INDEX_POSITION, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
                gl.EnableVertexAttribArray(ATTRIB_INDEX_POSITION);
            }
            // prepare colors
            {
                int location = shaderProgram.GetAttributeLocation(gl, in_uv);
                ATTRIB_INDEX_UV = (uint)location;
                gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, colorBuffer[0]);
                gl.VertexAttribPointer(ATTRIB_INDEX_UV, 1, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
                gl.EnableVertexAttribArray(ATTRIB_INDEX_UV);
            }

            gl.BindVertexArray(0);
        }
开发者ID:bitzhuwei,项目名称:CSharpGL,代码行数:27,代码来源:HexahedronGrid.cs

示例8: PrepareNMVAO

        public void PrepareNMVAO(OpenGL gl, NormalMaterialProgram program)
        {
            var vertArrIds = new uint[1];
            gl.GenVertexArrays(1, vertArrIds);

            VaoNM = vertArrIds[0];
            gl.BindVertexArray(VaoNM);

            BindNMVBOs(gl, program);

            gl.EnableVertexAttribArray(0);
            gl.BindVertexArray(0);
        }
开发者ID:jochemgeussens,项目名称:sharpgl,代码行数:13,代码来源:NMHTBufferGroup.cs

示例9: PrepareHTVAO

        public void PrepareHTVAO(OpenGL gl, HitTestProgram program)
        {
            var vertArrIds = new uint[1];
            gl.GenVertexArrays(1, vertArrIds);

            VaoHT = vertArrIds[0];
            gl.BindVertexArray(VaoHT);

            BindHTVBOs(gl, program);

            gl.EnableVertexAttribArray(0);
            gl.BindVertexArray(0);
        }
开发者ID:jochemgeussens,项目名称:sharpgl,代码行数:13,代码来源:NMHTBufferGroup.cs

示例10: BindNMVBOs

        public void BindNMVBOs(OpenGL gl, NormalMaterialProgram program)
        {
            var attribPos = program.Attribs["Position"];
            gl.BindBuffer(_vboTarget, Position);
            gl.VertexAttribPointer(attribPos, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.EnableVertexAttribArray(attribPos);

            attribPos = program.Attribs["Normal"];
            gl.BindBuffer(_vboTarget, Normal);
            gl.VertexAttribPointer(attribPos, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.EnableVertexAttribArray(attribPos);

            attribPos = program.Attribs["AmbientMaterial"];
            gl.BindBuffer(_vboTarget, AmbientMaterial);
            gl.VertexAttribPointer(attribPos, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.VertexAttribDivisor(attribPos, 1);
            gl.EnableVertexAttribArray(attribPos);

            attribPos = program.Attribs["DiffuseMaterial"];
            gl.BindBuffer(_vboTarget, DiffuseMaterial);
            gl.VertexAttribPointer(attribPos, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.VertexAttribDivisor(attribPos, 1);
            gl.EnableVertexAttribArray(attribPos);

            attribPos = program.Attribs["SpecularMaterial"];
            gl.BindBuffer(_vboTarget, SpecularMaterial);
            gl.VertexAttribPointer(attribPos, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.VertexAttribDivisor(attribPos, 1);
            gl.EnableVertexAttribArray(attribPos);

            attribPos = program.Attribs["ShininessValue"];
            gl.BindBuffer(_vboTarget, ShininessValue);
            gl.VertexAttribPointer(attribPos, 1, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.VertexAttribDivisor(attribPos, 1);
            gl.EnableVertexAttribArray(attribPos);

            gl.BindBuffer(_iboTarget, Ibo);
        }
开发者ID:jochemgeussens,项目名称:sharpgl,代码行数:38,代码来源:NMHTBufferGroup.cs

示例11: BindHTVBOs

        public void BindHTVBOs(OpenGL gl, HitTestProgram program)
        {
            var attribPos = program.Attribs["Position"];
            gl.BindBuffer(_vboTarget, Position);
            gl.VertexAttribPointer(attribPos, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.EnableVertexAttribArray(attribPos);

            attribPos = program.Attribs["HTColorId"];
            gl.BindBuffer(_vboTarget, HTColorId);
            gl.VertexAttribPointer(attribPos, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
            gl.VertexAttribDivisor(attribPos, 1);
            gl.EnableVertexAttribArray(attribPos);

            gl.BindBuffer(_iboTarget, Ibo);
        }
开发者ID:jochemgeussens,项目名称:sharpgl,代码行数:15,代码来源:NMHTBufferGroup.cs

示例12: PrepareVAO

        public void PrepareVAO(OpenGL gl, LinesProgram program)
        {
            var vertArrIds = new uint[1];
            gl.GenVertexArrays(1, vertArrIds);

            Vao = vertArrIds[0];
            gl.BindVertexArray(Vao);

            BindVBOs(gl, program);

            gl.EnableVertexAttribArray(0);
            gl.BindVertexArray(0);
        }
开发者ID:jochemgeussens,项目名称:sharpgl,代码行数:13,代码来源:LinesBufferGroup.cs

示例13: DrawTrefoilCelShaded

        private void DrawTrefoilCelShaded(OpenGL gl)
        {
            //  Use the shader program.
            gl.UseProgram(shaderProgram.ProgramObject);

            //  Set the variables for the shader program.
            gl.Uniform3(toonUniforms.DiffuseMaterial, 0f, 0.75f, 0.75f);
            gl.Uniform3(toonUniforms.AmbientMaterial, 0.04f, 0.04f, 0.04f);
            gl.Uniform3(toonUniforms.SpecularMaterial, 0.5f, 0.5f, 0.5f);
            gl.Uniform1(toonUniforms.Shininess, 50f);

            //  Set the light position.
            gl.Uniform3(toonUniforms.LightPosition, 1, new float[4] { 0.25f, 0.25f, 1f, 0f });

            //  Set the matrices.
            gl.UniformMatrix4(toonUniforms.Projection, 1, false, projection.AsColumnMajorArrayFloat);
            gl.UniformMatrix4(toonUniforms.Modelview, 1, false, modelView.AsColumnMajorArrayFloat);
            gl.UniformMatrix3(toonUniforms.NormalMatrix, 1, false, normalMatrix.AsColumnMajorArrayFloat);

            //  Bind the vertex and index buffer.
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBuffer);
            gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);

            gl.EnableVertexAttribArray(attrPosition);
            gl.EnableVertexAttribArray(attrNormal);

            //  Draw the geometry, straight from the vertex buffer.
            gl.VertexAttribPointer(attrPosition, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Zero);
            int normalOffset = Marshal.SizeOf(typeof(Vertex));
            gl.VertexAttribPointer(attrNormal, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Add(new IntPtr(0), normalOffset));

            gl.DrawElements(OpenGL.GL_TRIANGLES, (int)trefoilKnot.IndexCount, OpenGL.GL_UNSIGNED_SHORT, IntPtr.Zero);
        }
开发者ID:RFExplorer,项目名称:rfexplorer-1,代码行数:33,代码来源:MainWindow.xaml.cs

示例14: Bind

        public void Bind(OpenGL gl)
        {
            // Bind the vertex, normal and index buffers.
            if (_transformationsBufferId != null)
            {
                var transStride = 16;

                //Bind
                gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, _transformationsBufferId.Value);
                gl.VertexAttribPointer(VertexAttributes.Position, transStride, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
                gl.EnableVertexAttribArray(VertexAttributes.Position);
            }

            if (_colorsBufferId != null)
            {
                var colStride = 3;
                //Bind
                gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, _colorsBufferId.Value);
                gl.VertexAttribPointer(VertexAttributes.Normal, colStride, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
                gl.EnableVertexAttribArray(VertexAttributes.Normal);
            }

            if (_indicesBufferId != null)
            {
                gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, _indicesBufferId.Value);
            }
        }
开发者ID:jochemgeussens,项目名称:OpenGLHelper-Using-SharpGL,代码行数:27,代码来源:ShaderBoundingBox.cs

示例15: Bind

        /// <summary>
        /// Calls VertexBuffer.Bind(gl), IndexBuffer.Bind(gl) and Material.Bind(gl). 
        /// </summary>
        /// <param name="gl">The OpenGL</param>
        public void Bind(OpenGL gl)
        {
            //if (gl == null)
            //{
            //    throw new ArgumentNullException("OpenGL parameter cannot be null. Call 'GenerateGeometry(...)' before attempting to bind.");
            //}

            // Bind the vertex, normal and index buffers.
            if (VertexBuffer != null)
            {
                //Bind
                //VertexBuffer.BindBuffer(gl); //
                gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, VertexBuffer.BufferId.Value);
                gl.VertexAttribPointer(VertexAttributes.Position, BufferStride, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
                gl.EnableVertexAttribArray(VertexAttributes.Position);
            }

            if (NormalBuffer != null)
            {
                //Bind
                //NormalBuffer.BindBuffer(gl); //
                gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, NormalBuffer.BufferId.Value);
                gl.VertexAttribPointer(VertexAttributes.Normal, BufferStride, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
                gl.EnableVertexAttribArray(VertexAttributes.Normal);
            }

            if (IndexBuffer != null)
            {
                //IndexBuffer.BindBuffer(gl); //
                gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, IndexBuffer.BufferId.Value);
            }
        }
开发者ID:jochemgeussens,项目名称:OpenGLHelper-Using-SharpGL,代码行数:36,代码来源:OGLVisualSceneElementBase.cs


注:本文中的SharpGL.OpenGL.EnableVertexAttribArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。