예제 #1
0
파일: App.cs 프로젝트: JJJohan/DX12Engine
        public void Start()
        {
            // Create an example triangle object.
            _triangleVertices = new List<Vertex>(6)
            {
                new Vertex(new Vector3(-0.25f, 0.25f, 0.0f), Colour.White, new Vector2(0.0f, 0.0f)),
                new Vertex(new Vector3(0.25f, -0.25f, 0.0f), Colour.White, new Vector2(1.0f, 64.0f)),
                new Vertex(new Vector3(-0.25f, -0.25f, 0.0f), Colour.White, new Vector2(0.0f, 64.0f)),

                new Vertex(new Vector3(-0.25f, 0.25f, 0.0f), Colour.White, new Vector2(0.0f, 0.0f)),
                new Vertex(new Vector3(0.25f, 0.25f, 0.0f), Colour.White, new Vector2(1.0f, 0.0f)),
                new Vertex(new Vector3(0.25f, -0.25f, 0.0f), Colour.White, new Vector2(1.0f, 64.0f))
            };

            _vertexBuffer = ResourceFactory.CreateVertexBufferInstance();
            _vertexBuffer.SetVertices(_triangleVertices);

            _pTexture = ResourceFactory.CreateTexture();
            _pTexture.Load(Helpers.GetRelativePath("Textures\\font.dds"));

            _pMaterial = ResourceFactory.CreateMaterial();
            _pMaterial.SetTexture(_pTexture);
            _pMaterial.LoadVertexShader(Helpers.GetRelativePath("Shaders\\DiffuseTexture.hlsl"), "VSMain", "vs_5_1");
            _pMaterial.LoadPixelShader(Helpers.GetRelativePath("Shaders\\DiffuseTexture.hlsl"), "PSMain", "ps_5_1");
            _pMaterial.Finalise(false);

            _pTriangle = new RenderObject("triangle");
            _pTriangle.SetVertexBuffer(_vertexBuffer);
            _pTriangle.SetMaterial(_pMaterial);

            // Create an example triangle object.
            _vertices2 = new List<Vertex>(4)
            {
                new Vertex(new Vector3(-0.25f, 0.25f, 0.0f), Colour.White, new Vector2(0.0f, 0.0f)),
                new Vertex(new Vector3(0.25f, -0.25f, 0.0f), Colour.White, new Vector2(1.0f, 1.0f)),
                new Vertex(new Vector3(0.25f, 0.25f, 0.0f), Colour.White, new Vector2(1.0f, 0.0f)),
                new Vertex(new Vector3(-0.25f, -0.25f, 0.0f), Colour.White, new Vector2(0.0f, 1.0f))
            };

            _indices = new List<int>(6)
            {
                1, 0, 2,
                0, 1, 3
            };

            _vertexBuffer2 = ResourceFactory.CreateVertexBufferInstance();
            _vertexBuffer2.SetVertices(_vertices2);

            _indexBuffer = ResourceFactory.CreateIndexBufferInstance();
            _indexBuffer.SetIndices(_indices);

            _pTexture2 = ResourceFactory.CreateTexture();
            _pTexture2.Load(Helpers.GetRelativePath("Textures\\test2.png"));

            _pMaterial2 = ResourceFactory.CreateMaterial();
            _pMaterial2.SetTexture(_pTexture2);
            _pMaterial2.LoadVertexShader(Helpers.GetRelativePath("Shaders\\DiffuseTexture.hlsl"), "VSMain", "vs_5_1");
            _pMaterial2.LoadPixelShader(Helpers.GetRelativePath("Shaders\\DiffuseTexture.hlsl"), "PSMain", "ps_5_1");
            _pMaterial2.Finalise(false);

            _pTriangle2 = new RenderObject("triangle2");
            _pTriangle2.SetIndexBuffer(_indexBuffer);
            _pTriangle2.SetVertexBuffer(_vertexBuffer2);
            _pTriangle2.SetMaterial(_pMaterial2);

            _pFont = FontManager.LoadFont("Myriad", Helpers.GetRelativePath("Textures\\myriad.dds"), Helpers.GetRelativePath("Textures\\myriad.txt"));
            _pText = new Text("text", _pFont);
            _pText.SetText("test");
            _pText.SetColour(Colour.Yellow);
            _pText.Transform.Position = new Vector3(0.0f, 0.0f, 0.0f);
            _pText2 = new Text("text2", _pFont);
            _pText2.SetText("Hello world!");
            _pText2.Transform.Position = new Vector3(0.0f, 20.0f, 0.0f);
            _pText2.EnableWorldSpace(true);
        }