コード例 #1
0
ファイル: GameWindow.cs プロジェクト: spl33t/VoxWorld
        protected override void OnLoad(EventArgs e)
        {
            // Create and fill a vertex buffer
            this.vertexBuffer = new VertexBuffer<ColoredVertex>(ColoredVertex.Size);

            this.vertexBuffer.AddVertex(new ColoredVertex(new Vector3(-1, -1, -1.5f), Color4.Lime));
            this.vertexBuffer.AddVertex(new ColoredVertex(new Vector3(1, 1, -1.5f), Color4.Red));
            this.vertexBuffer.AddVertex(new ColoredVertex(new Vector3(1, -1, -1.5f), Color4.Blue));

            // Load shaders
            string fscode, vscode;
            var assembly = Assembly.GetExecutingAssembly();
            var fsresourceName = "VoxWorld.Shaders.fragment-shader.fs";
            var vsresourceName = "VoxWorld.Shaders.vertex-shader.vs";

            using (Stream stream = assembly.GetManifestResourceStream(fsresourceName))
            using (StreamReader reader = new StreamReader(stream))
                fscode = reader.ReadToEnd();

            using (Stream stream = assembly.GetManifestResourceStream(vsresourceName))
            using (StreamReader reader = new StreamReader(stream))
                vscode = reader.ReadToEnd();

            var vertexShader = new Shader(ShaderType.VertexShader, vscode);
            var fragmentShader = new Shader(ShaderType.FragmentShader, fscode);

            // Link shaders into shader program
            this.shaderProgram = new ShaderProgram(vertexShader, fragmentShader);

            // Create vertex array to specify vertex layout
            this.vertexArray = new VertexArray<ColoredVertex>(
                this.vertexBuffer, this.shaderProgram,
                new VertexAttribute("vPosition", 3, VertexAttribPointerType.Float, ColoredVertex.Size, 0),
                new VertexAttribute("vColor", 4, VertexAttribPointerType.Float, ColoredVertex.Size, 12)
                );

            // Create projection matrix uniform
            this.projectionMatrix = new Matrix4Uniform("projectionMatrix");
            this.projectionMatrix.Matrix = Matrix4.CreatePerspectiveFieldOfView(
                MathHelper.PiOver2, 16f / 9, 0.1f, 100f);
        }
コード例 #2
0
ファイル: Shader.cs プロジェクト: spl33t/VoxWorld
        public void Set(ShaderProgram Program)
        {
            // Get uniform location
            var i = Program.GetUniformLocation(this.name);

            // Set uniform value
            GL.UniformMatrix4(i, false, ref this.matrix);
        }