示例#1
0
        public ApplicationSprite()
        {
            this.WithStage3D(
                stage3D =>
            {
                //AtMessage("WithStage3D");

                var context3D = stage3D.context3D;

                context3D.configureBackBuffer(300, 300, 2);

                // Create program 3D instance for shader
                var program = context3D.createProgram();
                // Assemble vertex shader from its code
                var vertexAssembler = new AGALMiniAssembler();
                vertexAssembler.assemble(Context3DProgramType.VERTEX, vertexShader);
                // Assemble fragment shader from its code
                var fragmentAssembler = new AGALMiniAssembler();
                fragmentAssembler.assemble(Context3DProgramType.FRAGMENT, fragmentShader);
                // Upload vertex/framgment shader to our program
                program.upload(vertexAssembler.agalcode, fragmentAssembler.agalcode);
                // Set the program instance as currently active program
                context3D.setProgram(program);

                // Create index buffer
                var __i3dBuffer = context3D.createIndexBuffer(3);
                // Upload index buffer from predefined values
                __i3dBuffer.uploadFromVector(new uint[] { 0, 1, 2 }, 0, 3);

                // Create vertex buffer
                var __v3dBuffer = context3D.createVertexBuffer(3, 3);
                // Upload vertex buffer from predefined values
                __v3dBuffer.uploadFromVector(new double[] {
                    -1, -1, 5,
                    1, -1, 5,
                    0, 1, 5
                }, 0, 3);
                // Set vertex buffer, this is what we access in vertex shader register va0
                context3D.setVertexBufferAt(0, __v3dBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);

                // Create our projection matrix
                var projection = new PerspectiveMatrix3D();
                // Use a helper function to set up the projection
                projection.perspectiveFieldOfViewLH(45 * Math.PI / 180, 1.2, 0.1, 512);
                // Set the projection matrix as a vertex program constant, this is what we access in vertex shader register vc0
                context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, projection, true);
                // Set the out color for our polygon as fragment program constant, this is what we access in fragment shader register fc0
                context3D.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, new double[] { 1, 1, 1, 0 });

                // Hook up enter frame event where we will do our rendering
                this.enterFrame +=
                    delegate
                {
                    context3D.clear(0, 0, 0, 0);

                    context3D.drawTriangles(__i3dBuffer, 0, 1);

                    context3D.present();
                };
            }
                );
        }
        public ApplicationSprite()
        {


            this.WithStage3D(
                stage3D =>
                {
                    //AtMessage("WithStage3D");

                    var context3D = stage3D.context3D;

                    context3D.configureBackBuffer(300, 300, 2);

                    // Create program 3D instance for shader  
                    var program = context3D.createProgram();
                    // Assemble vertex shader from its code
                    var vertexAssembler = new AGALMiniAssembler();
                    // partial?
                    vertexAssembler.assemble(Context3DProgramType.VERTEX, vertexShader);
                    // Assemble fragment shader from its code
                    var fragmentAssembler = new AGALMiniAssembler();
                    fragmentAssembler.assemble(Context3DProgramType.FRAGMENT, fragmentShader);
                    // Upload vertex/framgment shader to our program  
                    program.upload(vertexAssembler.agalcode, fragmentAssembler.agalcode);
                    // Set the program instance as currently active program  
                    context3D.setProgram(program);

                    // Create index buffer
                    var __i3dBuffer = context3D.createIndexBuffer(3);
                    // Upload index buffer from predefined values
                    __i3dBuffer.uploadFromVector(new uint[] { 0, 1, 2 }, 0, 3);

                    // Create vertex buffer
                    var __v3dBuffer = context3D.createVertexBuffer(3, 3);
                    // Upload vertex buffer from predefined values
                    __v3dBuffer.uploadFromVector(new double[]{
                    -1, -1, 5,
                    1, -1, 5,
                    0,  1, 5}, 0, 3);
                    // Set vertex buffer, this is what we access in vertex shader register va0
                    context3D.setVertexBufferAt(0, __v3dBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);

                    // Create our projection matrix
                    var projection = new PerspectiveMatrix3D();
                    // Use a helper function to set up the projection
                    projection.perspectiveFieldOfViewLH(45 * Math.PI / 180, 1.2, 0.1, 512);
                    // Set the projection matrix as a vertex program constant, this is what we access in vertex shader register vc0
                    context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, projection, true);
                    // Set the out color for our polygon as fragment program constant, this is what we access in fragment shader register fc0
                    context3D.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, new double[] { 1, 1, 1, 0 });

                    // Hook up enter frame event where we will do our rendering
                    this.enterFrame +=
                        delegate
                        {
                            context3D.clear(0, 0, 0, 0);

                            context3D.drawTriangles(__i3dBuffer, 0, 1);

                            context3D.present();
                        };
                }
            );
        }