public SpriteRenderer(SpriteSheet spriteSheet)
        {
            SpriteSheet = spriteSheet;

            m_program = SpriteProgram.Instance;
            m_instances = new List<SpriteInstance>();
            m_bufferSprite = new Buffer<SpriteData>();
            m_bufferQuad = new Buffer<Vector3>();
            m_vao = new VertexArray();

            m_bufferQuad.SetData(new Vector3[] {
                new Vector3(0f, 0f, 0f),
                new Vector3(0f, 1f, 0f),
                new Vector3(1f, 1f, 0f),
                new Vector3(1f, 0f, 0f)
            });

            GL.BindVertexArray(m_vao);
            GL.UseProgram(m_program);

            m_program.Position.SetValue(m_bufferQuad.GetView());

            m_program.Transform.SetValue(m_bufferSprite.GetView<Matrix4>("Transform"));
            m_program.Transform.SetDivisor(1);
            m_program.TextureOrigin.SetValue(m_bufferSprite.GetView<Vector2>("TextureOrigin"));
            m_program.TextureOrigin.SetDivisor(1);
            m_program.TextureTarget.SetValue(m_bufferSprite.GetView<Vector2>("TextureTarget"));
            m_program.TextureTarget.SetDivisor(1);

            GL.BindVertexArray(null);

            m_isDirty = true;
        }
Example #2
0
 public Sprite(SpriteSheet spriteSheet, string name, Vector2i size, Box2 coordinates)
 {
     SpriteSheet = spriteSheet;
     Name = name;
     Size = size;
     Coordinates = coordinates;
 }
Example #3
0
        public Background(Camera camera)
        {
            m_camera = camera;

            m_backgroundTexture_01 = Texture2D.Load(typeof(Background).Assembly.GetManifestResourceStream("Test.Game_01.Textures.Background_01.png"));
            m_backgroundSheet_01 = new SpriteSheet(m_backgroundTexture_01);
            m_backgroundSprite_01 = m_backgroundSheet_01.AddSprite("", new Box2i(Vector2i.Zero, m_backgroundTexture_01.Size));
            m_backgroundRenderer_01 = new SpriteRenderer(m_backgroundSheet_01);
            m_backgroundInstance_01 = m_backgroundRenderer_01.AddSprite(m_backgroundSprite_01);

            m_backgroundTexture_02 = Texture2D.Load(typeof(Background).Assembly.GetManifestResourceStream("Test.Game_01.Textures.Background_02.png"));
            m_backgroundSheet_02 = new SpriteSheet(m_backgroundTexture_02);
            m_backgroundSprite_02 = m_backgroundSheet_02.AddSprite("", new Box2i(Vector2i.Zero, m_backgroundTexture_02.Size));
            m_backgroundRenderer_02 = new SpriteRenderer(m_backgroundSheet_02);
            m_backgroundInstance_02_First = m_backgroundRenderer_02.AddSprite(m_backgroundSprite_02);
            m_backgroundInstance_02_Second = m_backgroundRenderer_02.AddSprite(m_backgroundSprite_02);
        }