public Texture2D GetTexture(string filename, bool useMipmaps) { Texture2D texture; if (!textureDict.TryGetValue(filename, out texture)) { TextureCreationParameters texParams = useMipmaps || game.UseAlternativeReflection ? textureCreationParamsMipmaps : textureCreationParamsNoMipmaps; try { texture = Texture2D.FromFile(graphicsDevice, filename, texParams); } catch (Exception) { return(null); } textureDict[filename] = texture; textureDictInv[texture] = filename; } if (texture != null) { int refs; if (!textureRefs.TryGetValue(texture, out refs)) { refs = 0; } textureRefs[texture] = refs + 1; } return(texture); }
public Texture2D FromFile(GraphicsDevice gd, string filename) { if (!textures.ContainsKey(filename)) { TextureCreationParameters tcp = TextureCreationParameters.Default; tcp.Format = SurfaceFormat.Color; tcp.ColorKey = Constants.Instance.ColorTextureTransparent; textures[filename] = Texture2D.FromFile(gd, filename, tcp); } return(textures[filename]); }
public static TWTexture FromImageFile(IXNAGame game, IGameFile imageFile, TextureCreationParameters parameters) { TWTexture tex = new TWTexture(); try { tex.xnaTexture = Texture2D.FromFile(game.GraphicsDevice, imageFile.GetFullFilename(), parameters); } catch { System.Diagnostics.Debug.WriteLine("Couldn't load texture at path '" + imageFile.GetFullFilename() + "' in TWTexture."); tex.xnaTexture = null; } return(tex); }
//Event for the button public override void Effect() { //Freeze the game Game1.state = State.FREEZE; //Create an instance of the new tilesheet form Forms.NewTileSheetForm frmTileSheet = new Forms.NewTileSheetForm(); frmTileSheet.ShowDialog(); //Get the tileset if the ok button has been clicked if (frmTileSheet.DialogResult == System.Windows.Forms.DialogResult.OK) { Game1.tileHeight = frmTileSheet.tileHeight; Game1.tileWidth = frmTileSheet.tileWidth; Game1.tileSheetFileName = frmTileSheet.sheetFileName; base.prevClicked = false; //Import the tile sheet as a texture try { //Make magenta the transparent color TextureCreationParameters tcp = TextureCreationParameters.Default; tcp.ColorKey = Microsoft.Xna.Framework.Graphics.Color.Magenta; tcp.Format = SurfaceFormat.Rgba32; //Load the texture Game1.tileSheet = Texture2D.FromFile(Game1.graphics.GraphicsDevice, Game1.tileSheetFileName, tcp); Game1.map.LoadTileSet(Game1.tileSheet); } catch { System.Windows.Forms.MessageBox.Show("There was an error loading the texture."); } } else { //Reset the button click property base.prevClicked = false; } //Unfreeze the game Game1.state = State.PLAY; base.Effect(); }
/// <summary> /// Add A Texture To The Texture Manager /// </summary> /// <param name="AssetName">The AssetName To Add</param> /// <param name="FullPath">The Path Of Texture To Matche With The AssetName</param> /// <param name="TCP">Texture Parameters</param> /// <param name="graphicsDevice">XNA GraphicsDevice Referenec</param> public static void Add(string AssetName, string FullPath, TextureCreationParameters TCP, GraphicsDevice graphicsDevice) { bool textureerreur = false; bool errload = true; try { DicoTexture texture = new DicoTexture(); texture.texture = Texture2D.FromFile(graphicsDevice, FullPath, TCP); errload = false; texture.FullPath = FullPath; if (!IsTextureExist(texture)) { dico.Add(AssetName, texture); } else { textureerreur = true; throw new System.Exception(); } } catch { if (textureerreur) { throw new Exception("Error This Texture Allready Exist"); } else { if (errload) { throw new Exception("Error This Asset filename Doesn't Exist"); } else { throw new Exception("Error This Asset Allready Exist"); } } } }
public void LoadTexture() { TextureCreationParameters parameters = new TextureCreationParameters( 0, 0, 0, 0, SurfaceFormat.Unknown, TextureUsage.None, Color.White, FilterOptions.Triangle, FilterOptions.Linear); //TextureCreationParameters parameters = new TextureCreationParameters( // 0, 0, 0, 1, SurfaceFormat.Unknown, TextureUsage.None, Color.White, FilterOptions.Triangle, FilterOptions.Linear ); try { if (Filename.StartsWith("file:///")) { string path; path = Filename.Substring(("file:///").Length); path = path.Replace("%20", " "); path = path.Replace("%28", "("); path = path.Replace("%29", ")"); Texture = Texture2D.FromFile(game.GraphicsDevice, path, parameters); } else { string path; path = Filename; path = path.Replace("%20", " "); Texture = Texture2D.FromFile(game.GraphicsDevice, game.EngineFiles.RootDirectory + "\\Content\\" + path, parameters); } } catch { } finally { } //Texture.Save( "c:/temp.dds", ImageFileFormat.Dds ); //Texture.GenerateMipMaps( TextureFilter.Linear ); }
public static TWTexture FromImageFile(IXNAGame game, IGameFile imageFile) { TextureCreationParameters parameters = new TextureCreationParameters(0, 0, 0, 0, SurfaceFormat.Unknown, TextureUsage.None, Color.TransparentBlack, FilterOptions.Linear, FilterOptions.Box); return(FromImageFile(game, imageFile, parameters)); }