Exemple #1
0
        private void LineBuffer_Loading(object sender, EventArgs e)
        {
            for (int i = 0; i < this.maxlines * 2; i++)
            {
                vertex[i] = Vector3.Zero;
                colour[i] = Vector4.Zero;
                index[i]  = (uint)i;
            }

            vertexVBO.Init();
            vertexVBO.SetData(vertex);

            colourVBO.Init();
            colourVBO.SetData(colour);

            indexVBO.Init();
            indexVBO.SetData(index);

            // setup shader
            this.shader.Init(
                @"LineBuffer.glsl|VS",
                @"LineBuffer.glsl|FS",
                new List <Variable>
            {
                new Variable(0, "vertex"),
                new Variable(1, "colour")
            });
        }
Exemple #2
0
        private void BuildFrameData()
        {
            meshVbo = new VBO();
            meshVbo.SetData(new[] {
                new Vertex(0.0f, 0.5f, Color4.Red),
                new Vertex(-0.5f, -0.5f, Color4.Green),
                new Vertex(0.5f, -0.5f, Color4.Blue)
            });
            meshVao = new VAO(3);             // 3 вершины
            // Нулевой атрибут вершины – позиция, у неё 2 компонента типа float
            meshVao.AttachVBO(0, meshVbo, 2, VertexAttribPointerType.Float, 5 * sizeof(float), 0);
            // Первый атрибут вершины – цвет, у него 3 компонента типа float
            meshVao.AttachVBO(1, meshVbo, 3, VertexAttribPointerType.Float, 5 * sizeof(float), 2 * sizeof(float));

            shaderProgram = new ShaderProgram();

            using (var vertexShader = new Shader(ShaderType.VertexShader))
                using (var fragmentShader = new Shader(ShaderType.FragmentShader))
                {
                    System.Console.WriteLine("vertexShader.Compile");
                    vertexShader.Compile(@"
					#version 400

					layout(location = 0) in vec2 Position;
					layout(location = 1) in vec3 Color;

					out vec3 fragColor;

					void main()
					{
                        gl_Position = vec4(Position, 0.0, 1.0);
                        fragColor = Color;
					}
					"                    );
                    fragmentShader.Compile(@"
					#version 400

					in vec3 fragColor;

					layout(location = 0) out vec4 outColor;

					void main()
					{
                        outColor = vec4(fragColor, 1.0);
					}
					"                    );
                    System.Console.WriteLine("shaderProgram.AttachShader(vertexShader);");
                    shaderProgram.AttachShader(vertexShader);
                    shaderProgram.AttachShader(fragmentShader);
                    shaderProgram.Link();
                }
        }
Exemple #3
0
        public Entity(Vector2 position, Vector2 size, Texture tex, Vector2 texScale, bool solid)
        {
            float x = size.X / 2.0f;
            float y = size.Y / 2.0f;

            float[] vertices =
            {
                -x, y,
                -x, -y,
                x,  y,
                x, -y
            };

            float[] texcoords =
            {
                0, 1,
                0, 0,
                1, 1,
                1, 0
            };

            byte[] indices =
            {
                0, 1, 2, 3
            };

            if (texScale != Vector2.One)
            {
                for (int i = 0; i < texcoords.Length; i += 2)
                {
                    texcoords[i]     *= texScale.X;
                    texcoords[i + 1] *= texScale.Y;
                }
            }

            VBO verts = new VBO(), texC = new VBO(), ind = new VBO();

            verts.SetData(ref vertices, BufferUsageHint.StaticDraw);
            texC.SetData(ref texcoords, BufferUsageHint.StaticDraw);
            ind.SetData(ref indices, BufferUsageHint.StaticDraw);

            buffers = new BufferSet();
            buffers.VertexBuffer   = verts;
            buffers.VertexSize     = 2;
            buffers.TexCoordBuffer = texC;
            buffers.TexCoordSize   = 2;
            buffers.IndexBuffer    = ind;
            buffers.DrawMode       = BeginMode.TriangleStrip;
            buffers.SetDrawState(DrawStates.Vertex | DrawStates.TexCoord);

            this.size     = size;
            this.position = position;
            this.tex      = tex;

            this.solid = solid;

            Name    = string.Empty;
            Visible = true;

            RebuildModelMatrix();
        }