示例#1
0
        private uint InitVertexAttrBuffer(float[] vertexes)
        {
            uint vertexBufferObject    = Gl.GenBuffer();
            uint vertexAttributeObject = Gl.GenVertexArray();
            uint ebo = Gl.GenBuffer();
            uint figureSizeInBytes = (uint)(sizeof(float) * vertexes.Length);

            _texture1 = _textureLoader.GetTexture("My.png");
            _texture2 = _textureLoader.GetTexture("smile.png");
            InitVertexAttrBufferInternal(vertexAttributeObject, vertexBufferObject, ebo, figureSizeInBytes, vertexes);
            return(vertexAttributeObject);
        }
示例#2
0
        /// <summary>
        /// Load sprite data from a sprite sheet
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="textureLoader"></param>
        /// <returns></returns>
        public SpriteDataCollection LoadSpriteSheet(FilePath filePath, ITextureLoader textureLoader)
        {
            var result = new SpriteDataCollection();

            using (var br = new StreamReader(filePath))
            {
                //Read line-by-line:
                SpriteData               currentSprite    = null;
                SpriteAnimation          currentAnimation = null;
                SpriteAnimationDirection currentDirection = null;
                ITexture image = null;

                String line = br.ReadLine();
                if (line != null)
                {
                    //First line gives image filename
                    image = textureLoader.GetTexture(filePath.Directory + line);
                }
                while (line != null)
                {
                    line = br.ReadLine();
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        //Store and clear current sprite data:
                        if (currentSprite != null)
                        {
                            result.Add(currentSprite);
                        }
                        currentSprite    = null;
                        currentAnimation = null;
                    }
                    else
                    {
                        String[] splitLine = line.Split('\t'); // Split on tabs
                        if (currentSprite == null)
                        {
                            //Initialise sprite:
                            currentSprite      = new SpriteData();
                            currentSprite.Name = line;
                            //currentSprite.Texture(image);
                        }
                        else if (currentAnimation == null || !splitLine.IsNumeric())
                        {
                            currentAnimation = new SpriteAnimation();
                            currentSprite.Animations.Add(line, currentAnimation);
                            currentDirection = null;
                        }
                        else if (currentDirection == null || splitLine.Length <= 1)
                        {
                            currentDirection = new SpriteAnimationDirection();
                            currentAnimation.Directions.Add(double.Parse(line), currentDirection);
                        }
                        else
                        {
                            TextureBrush frame = new TextureBrush(image, splitLine);
                            currentDirection.Frames.Add(frame);
                        }
                    }
                }
            }
            return(result);
        }