Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        public void PreLoadTexture(HSD_TOBJ tobj)
        {
            if (!imageBufferTextureIndex.ContainsKey(tobj.ImageData.ImageData))
            {
                var rawImageData = tobj.ImageData.ImageData;
                var width        = tobj.ImageData.Width;
                var height       = tobj.ImageData.Height;

                List <byte[]> mips = new List <byte[]>();

                if (tobj.LOD != null && tobj.ImageData.MaxLOD != 0)
                {
                    for (int i = 0; i < tobj.ImageData.MaxLOD - 1; i++)
                    {
                        mips.Add(tobj.GetDecodedImageData(i));
                    }
                }
                else
                {
                    mips.Add(tobj.GetDecodedImageData());
                }

                var index = TextureManager.Add(mips, width, height);

                imageBufferTextureIndex.Add(rawImageData, index);
            }
        }
Beispiel #2
0
    public static void Main(string[] args)
    {
        string grassSrc = "Grass.png";
        string pathSrc  = "Path.png";

        // Add into the flyweight:
        TextureManager.Add(TextureName.Grass, grassSrc);
        TextureManager.Add(TextureName.Path, pathSrc);

        // Create two sprites using the Texture Name:
        Sprite grassSprite = new Sprite(TextureName.Grass);
        Sprite pathSprite  = new Sprite(TextureName.Path);

        // Create a sprite using a Texture reference:
        Texture grass         = TextureManager.GetTexture(TextureName.Grass);
        Sprite  anotherSprite = new Sprite(grass);

        // Draw the sprites:

        grassSprite.Draw(0, 1);   // Drawing sprite at 0, 1
        pathSprite.Draw(0, 2);    // Drawing sprite at 0, 2

        anotherSprite.Draw(0, 3); // Drawing sprite at 0, 3

        // Swap the sprite out:
        anotherSprite.SetTexture(TextureName.Path);

        anotherSprite.Draw(0, 4); // Drawing sprite at 0, 4
    }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        private static void GenerateFontImage()
        {
            int bitmapWidth  = TextSettings.GlyphsPerLine * TextSettings.GlyphWidth;
            int bitmapHeight = TextSettings.GlyphLineCount * TextSettings.GlyphHeight;

            using (Bitmap bitmap = new Bitmap(bitmapWidth, bitmapHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                using (var g = Graphics.FromImage(bitmap))
                {
                    if (TextSettings.BitmapFont)
                    {
                        g.SmoothingMode     = SmoothingMode.None;
                        g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
                    }
                    else
                    {
                        g.SmoothingMode     = SmoothingMode.HighQuality;
                        g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                    }

                    for (int p = 0; p < TextSettings.GlyphLineCount; p++)
                    {
                        for (int n = 0; n < TextSettings.GlyphsPerLine; n++)
                        {
                            char c = (char)(n + p * TextSettings.GlyphsPerLine);
                            CharSpacing.Add(c, TextRenderer.MeasureText(g, c.ToString(), RenderFont, new Size(1, 1), TextFormatFlags.NoPadding).Width + 1);
                            g.DrawString(c.ToString(), RenderFont, Brushes.White,
                                         n * TextSettings.GlyphWidth + TextSettings.AtlasOffsetX, p * TextSettings.GlyphHeight + TextSettings.AtlassOffsetY);
                        }
                    }
                }
                TextureManager.Add(bitmap);
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        private void LoadTexture(byte[] data, int width, int height)
        {
            var id = TextureManager.TextureCount;

            TextureManager.Add(data, width, height);
            var image = Tools.BitmapTools.BGRAToBitmap(data, width, height);

            BitmapList.Images.Add(image);
            textureList.Items.Add(new ListViewItem()
            {
                ImageIndex = id, Text = "Image_" + id
            });
        }
Beispiel #5
0
        protected override void LoadContent()
        {
            TextureManager.Add(Content.Load <Texture2D>("Tiles/grass_small"), 0);
            TextureManager.Add(Content.Load <Texture2D>("Tiles/rock"), 1);
            TextureManager.Add(Content.Load <Texture2D>("Tiles/wood_small"), 2);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/lumberjack_sheet_small"), 3);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/woodpile"), 4);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/trees.png"), 5);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/rock"), 6);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/house"), 7);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/lumbermill"), 8);
            TextureManager.Add(Content.Load <Texture2D>("texture1px"), 10);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/carrier_sheet_small"), 11);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/buildsite"), 12);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/dot"), 13);
            TextureManager.Add(Content.Load <Texture2D>("Sprites/builder_sheet_small"), 14);

            DrawingUtils.Font = Content.Load <SpriteFont>("Fonts/font1");
        }
    /// <summary>
    /// Loads all textures present in the given directory path that match the provided extensions array.
    /// The loaded textures are added to the TextureManager.
    /// </summary>
    public static IEnumerator LoadTexturesFromDir(string path, string[] extensions)
    {
        DirectoryInfo          dirInfo = new DirectoryInfo(path);
        IEnumerable <FileInfo> files   = dirInfo.GetFilesByExtensions(extensions);

        foreach (FileInfo file in files)
        {
            yield return(null);

            string filePath = Path.Combine(file.DirectoryName, file.Name);
            try
            {
                Texture2D texture = TextureLoader.LoadTexture(filePath);
                TextureManager.Add(Path.GetFileNameWithoutExtension(filePath), texture);
            }
            catch (System.BadImageFormatException)
            {
                Debug.Log("Error: Image " + file.Name + " has an invalid format.");
            }
        }
    }