Beispiel #1
0
		internal static int RegisterTexture(string FileName, World.ColorRGB TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight)
		{
			if (FileName == null)
			{
				//Need to find out why the object parser sometimes decides to pass a null filename, but this works around it
				return -1;
			}
			
			int i = FindTexture(FileName, TransparentColor, TransparentColorUsed, LoadMode, WrapModeX, WrapModeY, ClipLeft, ClipTop, ClipWidth, ClipHeight);
			if (i >= 0)
			{
				return i;
			}
			else
			{
				i = GetFreeTexture();
				Textures[i] = new Texture
				{
					Queried = false,
					Loaded = false,
					FileName = FileName,
					TransparentColor = TransparentColor,
					TransparentColorUsed = TransparentColorUsed,
					LoadMode = LoadMode,
					WrapModeX = WrapModeX,
					WrapModeY = WrapModeY,
					ClipLeft = ClipLeft,
					ClipTop = ClipTop,
					ClipWidth = ClipWidth,
					ClipHeight = ClipHeight,
					DontAllowUnload = DontAllowUnload,
					LoadImmediately = false,
					OpenGlTextureIndex = 0
				};
				bool alpha = false;
				switch (System.IO.Path.GetExtension(Textures[i].FileName).ToLowerInvariant())
				{
					case ".gif":
					case ".png":
						alpha = true;
						Textures[i].LoadImmediately = true;
						break;
				}
				if (alpha)
				{
					Textures[i].Transparency = TextureTransparencyMode.Alpha;
				}
				else if (TransparentColorUsed != 0)
				{
					Textures[i].Transparency = TextureTransparencyMode.TransparentColor;
				}
				else
				{
					Textures[i].Transparency = TextureTransparencyMode.None;
				}
				Textures[i].IsRGBA = Textures[i].Transparency != TextureTransparencyMode.None | LoadMode != TextureLoadMode.Normal;
				return i;
			}
		}
Beispiel #2
0
		// find texture
		private static int FindTexture(string FileName, World.ColorRGB TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight)
		{
			for (int i = 1; i < Textures.Length; i++)
			{
				if (Textures[i] != null && Textures[i].FileName != null)
				{
					if (string.Compare(Textures[i].FileName, FileName, StringComparison.OrdinalIgnoreCase) == 0)
					{
						if (Textures[i].LoadMode == LoadMode & Textures[i].WrapModeX == WrapModeX & Textures[i].WrapModeY == WrapModeY)
						{
							if (Textures[i].ClipLeft == ClipLeft & Textures[i].ClipTop == ClipTop & Textures[i].ClipWidth == ClipWidth & Textures[i].ClipHeight == ClipHeight)
							{
								if (TransparentColorUsed == 0)
								{
									if (Textures[i].TransparentColorUsed == 0)
									{
										return i;
									}
								}
								else
								{
									if (Textures[i].TransparentColorUsed != 0)
									{
										if (Textures[i].TransparentColor.R == TransparentColor.R & Textures[i].TransparentColor.G == TransparentColor.G & Textures[i].TransparentColor.B == TransparentColor.B)
										{
											return i;
										}
									}
								}
							}
						}
					}
				}
			}
			return -1;
		}
Beispiel #3
0
 // find texture
 private static int FindTexture(string FileName, Color24 TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight)
 {
     for (int i = 1; i < Textures.Length; i++)
     {
         if (Textures[i] != null && Textures[i].FileName != null)
         {
             if (string.Compare(Textures[i].FileName, FileName, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 if (Textures[i].LoadMode == LoadMode & Textures[i].WrapModeX == WrapModeX & Textures[i].WrapModeY == WrapModeY)
                 {
                     if (Textures[i].ClipLeft == ClipLeft & Textures[i].ClipTop == ClipTop & Textures[i].ClipWidth == ClipWidth & Textures[i].ClipHeight == ClipHeight)
                     {
                         if (TransparentColorUsed == 0)
                         {
                             if (Textures[i].TransparentColorUsed == 0)
                             {
                                 return(i);
                             }
                         }
                         else
                         {
                             if (Textures[i].TransparentColorUsed != 0)
                             {
                                 if (Textures[i].TransparentColor.R == TransparentColor.R & Textures[i].TransparentColor.G == TransparentColor.G & Textures[i].TransparentColor.B == TransparentColor.B)
                                 {
                                     return(i);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(-1);
 }
Beispiel #4
0
        internal static int RegisterTexture(string FileName, Color24 TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight)
        {
            if (FileName == null)
            {
                //Need to find out why the object parser sometimes decides to pass a null filename, but this works around it
                return(-1);
            }

            int i = FindTexture(FileName, TransparentColor, TransparentColorUsed, LoadMode, WrapModeX, WrapModeY, ClipLeft, ClipTop, ClipWidth, ClipHeight);

            if (i >= 0)
            {
                return(i);
            }
            else
            {
                i           = GetFreeTexture();
                Textures[i] = new Texture
                {
                    Queried              = false,
                    Loaded               = false,
                    FileName             = FileName,
                    TransparentColor     = TransparentColor,
                    TransparentColorUsed = TransparentColorUsed,
                    LoadMode             = LoadMode,
                    WrapModeX            = WrapModeX,
                    WrapModeY            = WrapModeY,
                    ClipLeft             = ClipLeft,
                    ClipTop              = ClipTop,
                    ClipWidth            = ClipWidth,
                    ClipHeight           = ClipHeight,
                    DontAllowUnload      = DontAllowUnload,
                    LoadImmediately      = false,
                    OpenGlTextureIndex   = 0
                };
                bool alpha = false;
                switch (System.IO.Path.GetExtension(Textures[i].FileName).ToLowerInvariant())
                {
                case ".gif":
                case ".png":
                    alpha = true;
                    Textures[i].LoadImmediately = true;
                    break;
                }
                if (alpha)
                {
                    Textures[i].Transparency = TextureTransparencyMode.Alpha;
                }
                else if (TransparentColorUsed != 0)
                {
                    Textures[i].Transparency = TextureTransparencyMode.TransparentColor;
                }
                else
                {
                    Textures[i].Transparency = TextureTransparencyMode.None;
                }
                Textures[i].IsRGBA = Textures[i].Transparency != TextureTransparencyMode.None | LoadMode != TextureLoadMode.Normal;
                return(i);
            }
        }
Beispiel #5
0
		internal static int RegisterTexture(string FileName, World.ColorRGB TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight)
		{
			int i = FindTexture(FileName, TransparentColor, TransparentColorUsed, LoadMode, WrapModeX, WrapModeY, ClipLeft, ClipTop, ClipWidth, ClipHeight);
			if (i >= 0)
			{
				return i;
			}
			else
			{
				i = GetFreeTexture();
				Textures[i] = new Texture();
				Textures[i].Queried = false;
				Textures[i].Loaded = false;
				Textures[i].FileName = FileName;
				Textures[i].TransparentColor = TransparentColor;
				Textures[i].TransparentColorUsed = TransparentColorUsed;
				Textures[i].LoadMode = LoadMode;
				Textures[i].WrapModeX = WrapModeX;
				Textures[i].WrapModeY = WrapModeY;
				Textures[i].ClipLeft = ClipLeft;
				Textures[i].ClipTop = ClipTop;
				Textures[i].ClipWidth = ClipWidth;
				Textures[i].ClipHeight = ClipHeight;
				Textures[i].DontAllowUnload = DontAllowUnload;
				Textures[i].LoadImmediately = false;
				Textures[i].OpenGlTextureIndex = 0;
				bool alpha = false;
				switch (System.IO.Path.GetExtension(Textures[i].FileName).ToLowerInvariant())
				{
					case ".gif":
					case ".png":
						alpha = true;
						Textures[i].LoadImmediately = true;
						break;
				}
				if (alpha)
				{
					Textures[i].Transparency = TextureTransparencyMode.Alpha;
				}
				else if (TransparentColorUsed != 0)
				{
					Textures[i].Transparency = TextureTransparencyMode.TransparentColor;
				}
				else
				{
					Textures[i].Transparency = TextureTransparencyMode.None;
				}
				Textures[i].IsRGBA = Textures[i].Transparency != TextureTransparencyMode.None | LoadMode != TextureLoadMode.Normal;
				return i;
			}
		}
        internal static int RegisterTexture(string FileName, World.ColorRGB TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight)
        {
            if (FileName == null)
            {
                //Need to find out why the object parser sometimes decides to pass a null filename, but this works around it
                return(-1);
            }

            int i = FindTexture(FileName, TransparentColor, TransparentColorUsed, LoadMode, WrapModeX, WrapModeY, ClipLeft, ClipTop, ClipWidth, ClipHeight);

            if (i >= 0)
            {
                return(i);
            }
            else
            {
                i           = GetFreeTexture();
                Textures[i] = new Texture
                {
                    Queried              = false,
                    Loaded               = false,
                    FileName             = FileName,
                    TransparentColor     = TransparentColor,
                    TransparentColorUsed = TransparentColorUsed,
                    LoadMode             = LoadMode,
                    WrapModeX            = WrapModeX,
                    WrapModeY            = WrapModeY,
                    ClipLeft             = ClipLeft,
                    ClipTop              = ClipTop,
                    ClipWidth            = ClipWidth,
                    ClipHeight           = ClipHeight,
                    DontAllowUnload      = DontAllowUnload,
                    LoadImmediately      = false,
                    OpenGlTextureIndex   = 0
                };
                bool alpha = false;
                switch (System.IO.Path.GetExtension(Textures[i].FileName).ToLowerInvariant())
                {
                case ".gif":
                case ".png":
                    alpha = true;
                    Textures[i].LoadImmediately = true;
                    break;
                }
                if (alpha)
                {
                    Textures[i].Transparency = TextureTransparencyMode.Alpha;
                }
                else if (TransparentColorUsed != 0)
                {
                    Textures[i].Transparency = TextureTransparencyMode.TransparentColor;
                }
                else
                {
                    Textures[i].Transparency = TextureTransparencyMode.None;
                }
                Textures[i].IsRGBA = Textures[i].Transparency != TextureTransparencyMode.None | LoadMode != TextureLoadMode.Normal;
                //Check that our image is a valid power of two
                int tw, th;
                GetImageDimensions(FileName, out tw, out th);
                int w = Interface.RoundToPowerOfTwo(tw);
                int h = Interface.RoundToPowerOfTwo(th);
                if (w != tw)
                {
                    Interface.AddMessage(Interface.MessageType.Information, false, "The Texture: " + FileName + " has a width of " + tw + " . This is not a valid power of two.");
                }
                if (h != th)
                {
                    Interface.AddMessage(Interface.MessageType.Information, false, "The Texture: " + FileName + " has a height of " + th + " . This is not a valid power of two.");
                }
                return(i);
            }
        }
Beispiel #7
0
        internal static int RegisterTexture(string FileName, World.ColorRGB TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight)
        {
            int i = FindTexture(FileName, TransparentColor, TransparentColorUsed, LoadMode, WrapModeX, WrapModeY, ClipLeft, ClipTop, ClipWidth, ClipHeight);

            if (i >= 0)
            {
                return(i);
            }
            else
            {
                i                                = GetFreeTexture();
                Textures[i]                      = new Texture();
                Textures[i].Queried              = false;
                Textures[i].Loaded               = false;
                Textures[i].FileName             = FileName;
                Textures[i].TransparentColor     = TransparentColor;
                Textures[i].TransparentColorUsed = TransparentColorUsed;
                Textures[i].LoadMode             = LoadMode;
                Textures[i].WrapModeX            = WrapModeX;
                Textures[i].WrapModeY            = WrapModeY;
                Textures[i].ClipLeft             = ClipLeft;
                Textures[i].ClipTop              = ClipTop;
                Textures[i].ClipWidth            = ClipWidth;
                Textures[i].ClipHeight           = ClipHeight;
                Textures[i].DontAllowUnload      = DontAllowUnload;
                Textures[i].LoadImmediately      = false;
                Textures[i].OpenGlTextureIndex   = 0;
                bool alpha = false;
                switch (System.IO.Path.GetExtension(Textures[i].FileName).ToLowerInvariant())
                {
                case ".gif":
                case ".png":
                    alpha = true;
                    Textures[i].LoadImmediately = true;
                    break;
                }
                if (alpha)
                {
                    Textures[i].Transparency = TextureTransparencyMode.Alpha;
                }
                else if (TransparentColorUsed != 0)
                {
                    Textures[i].Transparency = TextureTransparencyMode.TransparentColor;
                }
                else
                {
                    Textures[i].Transparency = TextureTransparencyMode.None;
                }
                Textures[i].IsRGBA = Textures[i].Transparency != TextureTransparencyMode.None | LoadMode != TextureLoadMode.Normal;
                return(i);
            }
        }