protected override Texture2D loadTexture(ushort id, string name, string file)
        {
            using (var fs = new FileStream(file, FileMode.Open))
                using (var image = (Bitmap)Bitmap.FromStream(fs))
                {
                    // Fix up the Image to match the expected format
                    image.RGBToBGR();

                    var data = new byte[image.Width * image.Height * 4];

                    BitmapData bitmapData = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
                                                           ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    if (bitmapData.Stride != image.Width * 4)
                    {
                        throw new NotImplementedException();
                    }
                    Marshal.Copy(bitmapData.Scan0, data, 0, data.Length);
                    image.UnlockBits(bitmapData);

                    var texture = new XnaTexture2D(_graphics, image.Width, image.Height);
                    texture.SetData(data);

                    return(new Texture2D(id, name, texture));
                }
            //return new Texture2D(id, name, new XnaTexture2D(_graphics, 1, 1));
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="graphicsManager">The <see cref="Komodo.Core.Engine.Graphics.GraphicsManager"/> is needed to generate a Texture, as the <see cref="Microsoft.Xna.Framework.Graphics.GraphicsDevice"/> is needed to generate a <see cref="Microsoft.Xna.Framework.Graphics.Texture2D"/>.</param>
        private void CreateMonoGameTexture(GraphicsManager graphicsManager)
        {
            var graphicsDevice = graphicsManager.GraphicsDeviceManager.GraphicsDevice;

            MonoGameTexture = new Texture2D(graphicsDevice, _width, _height);
            MonoGameTexture.SetData(GetData());
        }
示例#3
0
 public static Microsoft.Xna.Framework.Graphics.Texture2D cropTexture2D(Microsoft.Xna.Framework.Graphics.GraphicsDevice GraphicsDevice, Microsoft.Xna.Framework.Graphics.Texture2D originalTexture, Microsoft.Xna.Framework.Rectangle sourceRectangle)
 {
     Microsoft.Xna.Framework.Graphics.Texture2D cropTexture = new Microsoft.Xna.Framework.Graphics.Texture2D(GraphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
     Microsoft.Xna.Framework.Color[] data = new Microsoft.Xna.Framework.Color[sourceRectangle.Width * sourceRectangle.Height];
     originalTexture.GetData(0, sourceRectangle, data, 0, data.Length);
     cropTexture.SetData(data);
     return cropTexture;
 }
示例#4
0
        public Microsoft.Xna.Framework.Graphics.Texture2D ToTexture2DTest()
        {
            var _t    = new Microsoft.Xna.Framework.Graphics.Texture2D(ScriptManager.graphicsDevice, Width, Height);
            var _data = new Microsoft.Xna.Framework.Color[Width * Height];

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    _data[y * Width + x] = this.GetPixel(x, y);
                }
            }
            _t.SetData(_data);
            return(_t);
        }
示例#5
0
        /// <summary>
        /// Gets the texture.
        /// </summary>
        /// <param name="imageIndex">Index of the image.</param>
        public Microsoft.Xna.Framework.Graphics.Texture2D LoadTexture2d(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, ushort imageIndex)
        {
            var image  = this.Images[imageIndex];
            var bitmap = image.Plain;

            uint[] imgData = new uint[bitmap.Width * bitmap.Height];
            Microsoft.Xna.Framework.Graphics.Texture2D texture = new Microsoft.Xna.Framework.Graphics.Texture2D(device, bitmap.Width, bitmap.Height);

            unsafe
            {
                BitmapData origdata = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
                uint *     byteData = (uint *)origdata.Scan0;
                for (int i = 0; i < imgData.Length; i++)
                {
                    imgData[i] = (byteData[i] & 0x000000ff) << 16 | (byteData[i] & 0x0000FF00) | (byteData[i] & 0x00FF0000) >> 16 | (byteData[i] & 0xFF000000);
                }
                bitmap.UnlockBits(origdata);
            }
            texture.SetData(imgData);

            return(texture);
        }
示例#6
0
        /// <summary>
        /// Gets the texture.
        /// </summary>
        /// <param name="imageIndex">Index of the image.</param>
        public Microsoft.Xna.Framework.Graphics.Texture2D LoadTexture2d(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, ushort imageIndex)
        {
            var image = this.Images[imageIndex];
            var bitmap = image.Plain;

            uint[] imgData = new uint[bitmap.Width * bitmap.Height];
            Microsoft.Xna.Framework.Graphics.Texture2D texture = new Microsoft.Xna.Framework.Graphics.Texture2D(device, bitmap.Width, bitmap.Height);

            unsafe
            {
                BitmapData origdata = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
                uint* byteData = (uint*)origdata.Scan0;
                for (int i = 0; i < imgData.Length; i++)
                {
                    imgData[i] = (byteData[i] & 0x000000ff) << 16 | (byteData[i] & 0x0000FF00) | (byteData[i] & 0x00FF0000) >> 16 | (byteData[i] & 0xFF000000);
                }
                bitmap.UnlockBits(origdata);
            }
            texture.SetData(imgData);

            return texture;
        }
示例#7
0
        public bool Register(ref List <Unit>[] allUnits, tempMap gameData, int x, int y, Microsoft.Xna.Framework.Graphics.GraphicsDevice g, int owner, int mode)
        { //adds building to list (at mouse position (x,y))
            //mode 0 for building, mode 1 for unit creation (so they don't conflict)
            bool success = false;
            int  goldRequired, lumberRequired, foodRequired;

            //int owner = this.building.owner; //default
            //Set resource for each building here (I don't know yet)


            if (this.buildStr != null || this.newUnitStr != null) //we actually have stuff to build
            {
                int typeIndex;
                if (mode == 0)
                {
                    typeIndex = nameTranslation(this.buildStr);            //get index
                }
                else
                {
                    typeIndex = nameTranslation(this.newUnitStr);
                }
                goldRequired   = SplashScreen.unitData.goldCost[typeIndex];
                lumberRequired = SplashScreen.unitData.lumberCost[typeIndex];
                foodRequired   = SplashScreen.unitData.foodConsumption[typeIndex];
                int checkMode = 0;

                string curBuildStr;
                int    unitW, unitH;
                if (this.buildStr != null && mode == 0)
                {
                    curBuildStr = this.buildStr;
                    unitW       = this.building.unitTileWidth;
                    unitH       = this.building.unitTileHeight;
                    //unitW = this.building.defaultUnitTileW;
                    //unitH = this.building.defaultUnitTileH;
                    checkMode = 0;
                }
                else
                {
                    curBuildStr = this.newUnitStr;
                    unitW       = this.newUnit.unitTileWidth;
                    unitH       = this.newUnit.unitTileHeight;
                    //unitW = this.newUnit.defaultUnitTileW;
                    //unitH = this.newUnit.defaultUnitTileH;
                    checkMode = 1;
                }

                if (gameData.canBuildOn(x, y, curBuildStr) && openSpace(x, y, unitW, unitH, allUnits, gameData, checkMode))
                {
                    if (mode == 0 && gameData.gold[owner] >= goldRequired && gameData.lumber[owner] >= lumberRequired && this.building.unitType >= SplashScreen.numUnits)
                    {                                                                                                       //checks that we have enough resource
                        Unit temp = new Unit(curBuildStr, x, y, owner, this.findLastID(allUnits[owner]) + 1, ref gameData); //+1 for new id
                        if (temp.unitType >= SplashScreen.numUnits)
                        {
                            temp.setBuildFrame(1);                                         //set to construction frame for building
                        }
                        //Init minimap data for unit
                        Microsoft.Xna.Framework.Color[] uCol = new Microsoft.Xna.Framework.Color[1]; // Unit Color
                        uCol[0] = Microsoft.Xna.Framework.Color.Yellow;
                        //Microsoft.Xna.Framework.Graphics.Texture2D tempImg = getTextureFromBitmap(temp.objectImage, g);
                        //temp.objImg2D = tempImg; //store the img
                        Microsoft.Xna.Framework.Graphics.Texture2D uRec = new Microsoft.Xna.Framework.Graphics.Texture2D(g, 1, 1);
                        uRec.SetData(uCol);
                        temp.uRec = uRec;

                        allUnits[temp.owner].Add(temp); //add unit

                        gameData.gold[owner]   -= goldRequired;
                        gameData.lumber[owner] -= lumberRequired;

                        //don't need to subtract/add food as that will be auto updated when unit added to screen

                        this.building = null;
                        this.buildStr = null;
                        success       = true;
                        buildCancel(); //finished building so cancel build mode
                    }
                    //else if (mode == 1 && gameData.gold[owner] >= goldRequired && gameData.lumber[owner] >= lumberRequired && (gameData.foodMax[owner] >= foodRequired + gameData.food[owner])) //a unit
                    else if (mode == 1 && (gameData.foodMax[owner] >= foodRequired + gameData.food[owner]))                 //a unit so only check if enough open population in order to register unit (if not the buffer will make it so we wait for enough population)
                    {                                                                                                       //unit creation probably
                        Unit temp = new Unit(curBuildStr, x, y, owner, this.findLastID(allUnits[owner]) + 1, ref gameData); //+1 for new id

                        //Init minimap data for unit
                        Microsoft.Xna.Framework.Color[] uCol = new Microsoft.Xna.Framework.Color[1]; // Unit Color
                        uCol[0] = Microsoft.Xna.Framework.Color.Yellow;
                        //Microsoft.Xna.Framework.Graphics.Texture2D tempImg = getTextureFromBitmap(temp.objectImage, g);
                        //temp.objImg2D = tempImg; //store the img
                        Microsoft.Xna.Framework.Graphics.Texture2D uRec = new Microsoft.Xna.Framework.Graphics.Texture2D(g, 1, 1);
                        uRec.SetData(uCol);
                        temp.uRec = uRec;

                        allUnits[temp.owner].Add(temp); //add unit

                        //Don't subtract resource here, subtracted when queueing
                        //gameData.gold[owner] -= goldRequired;
                        //gameData.lumber[owner] -= lumberRequired;

                        //don't need to subtract/add food as that will be auto updated when unit added to screen

                        this.newUnit    = null;
                        this.newUnitStr = null;
                        success         = true;
                    }
                    else
                    {
                        if (mode == 0)
                        {
                            this.buildMode = 0;
                            this.buildStr  = null;
                            this.building  = null;
                        }
                    }
                }
                else
                {
                    if (mode == 0)
                    {
                        this.buildMode = 0;
                        this.buildStr  = null;
                        this.building  = null;
                    }
                }
            }

            return(success); //if build fails, we have to change menus back (like calling cancel)
        }
示例#8
0
 public override void SetData <T>(T[] data)
 {
     texture.SetData(data);
 }