コード例 #1
0
        private void createVertexBuffer(Model model)
        {
            MeshData meshTeapot = model.Mesh;

            // teapot
            vbTeapot = new VertexBuffer(meshTeapot.VertexCount,
                                        meshTeapot.IndexCount,
                                        VertexFormat.Float3,
                                        VertexFormat.Float3,
                                        VertexFormat.Float3,
                                        VertexFormat.Float2);
            vbTeapot.SetVertices(0, meshTeapot.Positions);
            vbTeapot.SetVertices(1, meshTeapot.Normals);
            vbTeapot.SetVertices(2, meshTeapot.Tangents);
            vbTeapot.SetVertices(3, meshTeapot.TexCoords);
            vbTeapot.SetIndices(meshTeapot.Indices);


            // grid
            meshGrid = BasicMeshFactory.CreatePlane(40.0f, 40.0f,
                                                    10, 10, 0.25f, 0.25f);


            vbGrid = new VertexBuffer(meshGrid.VertexCount,
                                      meshGrid.IndexCount,
                                      VertexFormat.Float3,
                                      VertexFormat.Float3,
                                      VertexFormat.Float3,
                                      VertexFormat.Float2);
            vbGrid.SetVertices(0, meshGrid.Positions);
            vbGrid.SetVertices(1, meshGrid.Normals);
            vbGrid.SetVertices(2, meshGrid.Tangents);
            vbGrid.SetVertices(3, meshGrid.TexCoords);
            vbGrid.SetIndices(meshGrid.Indices);
        }
コード例 #2
0
        public BgModel(float width, float depth, int divW, int divH)
        {
            // grid
#if false
            meshGrid = BasicMeshFactory.CreateGrid(width, depth,
                                                   divW, divH,
                                                   new Rgba(128, 128, 128, 255),
                                                   new Rgba(255, 0, 0, 255),
                                                   new Rgba(0, 255, 0, 255));
#else
            meshGrid = BasicMeshFactory.CreatePlane(width, depth,
                                                    divW, divH, 0.25f, 0.25f);
#endif

            vbGrid = new VertexBuffer(meshGrid.VertexCount,
                                      meshGrid.IndexCount,
                                      VertexFormat.Float3,
                                      VertexFormat.Float2);
            vbGrid.SetVertices(0, meshGrid.Positions);
            vbGrid.SetVertices(1, meshGrid.TexCoords);

            vbGrid.SetIndices(meshGrid.Indices);


            // vertex color shader
            shaderVtxColor = new ShaderProgram("/Application/Sample/Graphics/ShaderCatalogSample/shaders/Texture.cgx");
            shaderVtxColor.SetAttributeBinding(0, "a_Position");
            shaderVtxColor.SetAttributeBinding(1, "a_TexCoord");
            texture = new Texture2D("/Application/Sample/Graphics/ShaderCatalogSample/data/renga.png", false);
            texture.SetWrap(TextureWrapMode.Repeat);

            posture = Matrix4.Translation(new Vector3(0.0f, 0.0f, 0.0f));
        }
コード例 #3
0
        static void Init()
        {
            stopwatch = new Stopwatch();
            graphics  = new GraphicsContext();
            SampleDraw.Init(graphics);

            DspWidth  = graphics.Screen.Width;
            DspHeight = graphics.Screen.Height;

            sceneList = new List <IScene>();
            sceneList.Add(new SceneSimpleShader());
            sceneList.Add(new SceneVertexLightingShader());
            sceneList.Add(new SceneGouraudShader());
            sceneList.Add(new ScenePhongShader());
            sceneList.Add(new SceneGlossMapShader());
            sceneList.Add(new SceneTextureShader());
            sceneList.Add(new SceneMultiTextureShader());
            sceneList.Add(new SceneToonShader());
            sceneList.Add(new SceneFogShader());
            sceneList.Add(new SceneBumpMapShader());
            sceneList.Add(new SceneProjectionShadow());

            // graphics context
            graphics.SetViewport(0, 0, DspWidth, DspHeight);
            graphics.SetClearColor(0.0f, 0.5f, 1.0f, 1.0f);
            graphics.Enable(EnableMode.DepthTest);
            graphics.Enable(EnableMode.CullFace);
            graphics.SetCullFace(CullFaceMode.Back, CullFaceDirection.Ccw);

            // camera
            float aspect = DspWidth / (float)DspHeight;
            float fov    = FMath.Radians(45.0f);

            camera = new Camera(fov, aspect, 10.0f, 100.0f);

            // light
            light         = new LightModel();
            light.Color   = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            light.Ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f);

            // model
//        model = new Model( BasicMeshFactory.CreateSphere( 4.0f, 20 ) );
            model               = new Model(BasicMeshFactory.CreateTorus(3.0f, 1.0f, 40, 12));
            model.Position      = new Vector3(0.0f, 4.0f, 0.0f);
            model.DiffuseColor  = new Vector4(0.5f, 0.5f, 1.0f, 1.0f);
            model.AmbientColor  = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            model.SpecularColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);

            // Bg
            modelBg = new BgModel(40.0f, 40.0f, 10, 10);

            id = 0;
            sceneList[id].Setup(graphics, model);

            stopwatch.Start();
        }
コード例 #4
0
ファイル: LightModel.cs プロジェクト: weimingtom/Sakura
    public LightModel()
    {
        // Light
        meshLight = BasicMeshFactory.CreateSphere( 1.0f, 20 );
        vbLight = new VertexBuffer( meshLight.VertexCount,
                                    meshLight.IndexCount,
                                    VertexFormat.Float3 );
        vbLight.SetVertices( 0, meshLight.Positions );
        vbLight.SetIndices( meshLight.Indices );

        // simple shader
        shaderSimple = new ShaderProgram( "/Application/Sample/Graphics/ShaderCatalogSample/shaders/Simple.cgx" );
		shaderSimple.SetAttributeBinding( 0, "a_Position" );

        // default color
        ambient = new Vector4( 0.2f, 0.2f, 0.2f, 1.0f );
        color = new Vector4( 1.0f, 1.0f, 0.0f, 1.0f );

        posture = Matrix4.Translation( new Vector3( 0.0f, 15.0f, 13.0f ) );
    }
コード例 #5
0
    private void createVertexBuffer( MeshData meshTeapot )
    {
        // teapot
		vbTeapot = new VertexBuffer( meshTeapot.VertexCount,
                                     meshTeapot.IndexCount,
                                     VertexFormat.Float3,
                                     VertexFormat.Float2 );
		vbTeapot.SetVertices( 0, meshTeapot.Positions );
        vbTeapot.SetVertices( 1, meshTeapot.TexCoords );
		vbTeapot.SetIndices( meshTeapot.Indices );


        // shadow map(simple)
        shaderShadowMap = new ShaderProgram( "/Application/Sample/Graphics/ShaderCatalogSample/shaders/Simple.cgx" );
		shaderShadowMap.SetAttributeBinding( 0, "a_Position" );

        // texture
        shaderTexture = new ShaderProgram( "/Application/Sample/Graphics/ShaderCatalogSample/shaders/Texture.cgx" );
        shaderTexture.SetAttributeBinding( 0, "a_Position" );
        shaderTexture.SetAttributeBinding( 1, "a_TexCoord" );
        texColorMap = new Texture2D( "/Application/Sample/Graphics/ShaderCatalogSample/data/renga.png", false );
        texColorMap.SetWrap( TextureWrapMode.Repeat );

        // grid
        meshGrid = BasicMeshFactory.CreatePlane( 40.0f, 40.0f,
                                                 10, 10, 0.25f, 0.25f );

        vbGrid = new VertexBuffer( meshGrid.VertexCount,
                                   meshGrid.IndexCount,
                                   VertexFormat.Float3,
                                   VertexFormat.Float2 );

		vbGrid.SetVertices( 0, meshGrid.Positions );
		vbGrid.SetVertices( 1, meshGrid.TexCoords );
		vbGrid.SetIndices( meshGrid.Indices ) ;

        // projection shadow
        shaderProjectionShadow = new ShaderProgram( "/Application/Sample/Graphics/ShaderCatalogSample/shaders/ProjectionShadow.cgx" );
        shaderProjectionShadow.SetAttributeBinding( 0, "a_Position" );
        shaderProjectionShadow.SetAttributeBinding( 1, "a_TexCoord0" );
    }