Пример #1
0
        public ExampleLayer()
        {
            //Create camera
            cameraController = new OrthographicCameraController(1280.0f / 720.0f);

            //Shader library
            shaderLibrary = new ShaderLibrary();

            // ----------
            //Square
            // ----------
            squareVertexArray = IVertexArray.Create();

            float[] squareVertices =
            {
                -0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
                0.5f,  -0.5f, 0.0f, 1.0f, 0.0f,
                0.5f,   0.5f, 0.0f, 1.0f, 1.0f,
                -0.5f,  0.5f, 0.0f, 0.0f, 1.0f
            };

            IVertexBuffer squareVertexBuffer = IVertexBuffer.Create(squareVertices, squareVertices.GetBytes());

            BufferLayout squareBufferLayout = new BufferLayout(new[]
            {
                new BufferElement("a_Position", ShaderDataType.Float3),
                new BufferElement("a_TexCoord", ShaderDataType.Float2)
            });

            squareVertexBuffer.SetLayout(squareBufferLayout);
            squareVertexArray.AddVertexBuffer(squareVertexBuffer);

            uint[]       squareIndices     = { 0, 1, 2, 2, 3, 0 };
            IIndexBuffer squareIndexBuffer =
                IIndexBuffer.Create(squareIndices, squareIndices.GetBytes() / sizeof(uint));

            squareVertexArray.SetIndexBuffer(squareIndexBuffer);

            //Square shader
            shaderLibrary.LoadAndAddShader("Shaders/Square.glsl");

            //Texture shader
            IShader textureShader = IShader.Create("Shaders/Texture.glsl");

            shaderLibrary.AddShader(textureShader);

            birdiTexture = I2DTexture.Create("Textures/Birdi.png");
            faceTexture  = I2DTexture.Create("Textures/Face.png");

            textureShader.Bind();
            textureShader.SetInt("u_Texture", 0);
        }
Пример #2
0
        /// <summary>
        /// Initializes the 2D rendering system
        /// </summary>
        internal static void Init()
        {
            ProfilerTimer.Profile(() =>
            {
                rendererData = new Renderer2DStorage
                {
                    QuadVertexArray = IVertexArray.Create()
                };

                float[] squareVertices =
                {
                    -0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
                    0.5f,  -0.5f, 0.0f, 1.0f, 0.0f,
                    0.5f,   0.5f, 0.0f, 1.0f, 1.0f,
                    -0.5f,  0.5f, 0.0f, 0.0f, 1.0f
                };

                IVertexBuffer squareVertexBuffer = IVertexBuffer.Create(squareVertices, squareVertices.GetBytes());

                BufferLayout squareBufferLayout = new BufferLayout(new[]
                {
                    new BufferElement("a_Position", ShaderDataType.Float3),
                    new BufferElement("a_TexCoord", ShaderDataType.Float2)
                });
                squareVertexBuffer.SetLayout(squareBufferLayout);
                rendererData.QuadVertexArray.AddVertexBuffer(squareVertexBuffer);

                uint[] squareIndices           = { 0, 1, 2, 2, 3, 0 };
                IIndexBuffer squareIndexBuffer =
                    IIndexBuffer.Create(squareIndices, squareIndices.GetBytes() / sizeof(uint));
                rendererData.QuadVertexArray.SetIndexBuffer(squareIndexBuffer);

                rendererData.WhiteTexture = I2DTexture.Create(1, 1);
                uint whiteTextureData     = 0xffffffff;
                rendererData.WhiteTexture.SetData(whiteTextureData, sizeof(uint));

                rendererData.TextureShader = IShader.Create("Shaders/Texture.glsl");
                rendererData.TextureShader.Bind();
                rendererData.TextureShader.SetInt("u_Texture", 0);
            });
        }