Exemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            // Initialize GL State
            GPUCapabilities.Initialize();
            GL.ClearColor(0.25f, 0.25f, 0.25f, 1.0f);

            // Set up PackageManager
            PackageManager.BasePath = "../../Assets/";

            // Initialize camera. Rest is in OnResize()
            orthoCamera = new Camera(this);
            orthoCamera.SetAsCurrent();

            // Load shaders
            ShaderManager.LoadCollection("Shaders/collection.xml");

            // Initialize batch and atlas manager
            spriteBatch = new SpriteBatch();
            sam = new SpriteAtlasManager();

            // Temporary example until editor gets sprite support
            // Uncomment to regenerate sprite file
            //GenerateSpriteFile();

            // Get the sprite atlas
            spaceShips = sam.Get("Sprites/SpaceShips.spr", true);

            // Get sprite by ID (slow operation, cache result on load)
            spaceShip = spaceShips["PlayerBlue1"];
        }
Exemplo n.º 2
0
        public void Draw(Sprite sprite, Vector2 position, Vector2 size, float rotation, Vector4 color)
        {
            /*if(current.PremultipliedAlpha)
            {
                color.X *= color.W;
                color.Y *= color.W;
                color.Z *= color.W;
            }*/

            uint baseIndex = (uint)queue.Count;

            for (int i = 0; i < sprite.Vertices.Length; i++)
            {
                queue.Add(new SpriteRenderData()
                {
                    Vertex = sprite.Vertices[i],
                    UV = sprite.TextureCoordinates[i],
                    Position = new Vector3(position),
                    Size = size * sprite.Size,
                    Rotation = rotation,
                    Color = color
                });
            }

            for (int i = 0; i < sprite.Indices.Length; i++)
            {
                indices.Add(baseIndex + sprite.Indices[i]);
            }
        }