Beispiel #1
0
 /// <summary>
 /// Loads a texture from file.
 /// </summary>
 /// <param name="filename">The name of the file to use.</param>
 /// <returns>The loaded texture, or null if it does not exist.</returns>
 public Texture LoadTexture(string filename, int twidth = 0)
 {
     try
     {
         filename = FileHandler.CleanFileName(filename);
         if (!TheClient.Files.Exists("textures/" + filename + ".png"))
         {
             SysConsole.Output(OutputType.ERROR, "Cannot load texture, file '" +
                               TextStyle.Color_Standout + "textures/" + filename + ".png" + TextStyle.Color_Error +
                               "' does not exist.");
             return(null);
         }
         Bitmap bmp = new Bitmap(TheClient.Files.ReadToStream("textures/" + filename + ".png"));
         if (!AcceptableWidths.Contains(bmp.Width) || !AcceptableWidths.Contains(bmp.Height))
         {
             SysConsole.Output(OutputType.ERROR, "Cannot load texture, file '" +
                               TextStyle.Color_Standout + "textures/" + filename + ".png" + TextStyle.Color_Error +
                               "' is invalid: unreasonable width or height.");
             return(null);
         }
         Bitmap  bmp2    = twidth <= 0 ? bmp : new Bitmap(bmp, new Size(twidth, twidth));
         Texture texture = new Texture();
         texture.Engine = this;
         texture.Name   = filename;
         GL.GenTextures(1, out texture.Original_InternalID);
         texture.Internal_Texture = texture.Original_InternalID;
         texture.Bind();
         LockBitmapToTexture(bmp2, true);
         texture.Width  = bmp2.Width;
         texture.Height = bmp2.Height;
         if (bmp2 != bmp)
         {
             bmp2.Dispose();
         }
         bmp.Dispose();
         texture.LoadedProperly = true;
         return(texture);
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.ERROR, "Failed to load texture from filename '" +
                           TextStyle.Color_Standout + "textures/" + filename + ".png" + TextStyle.Color_Error + "': " + ex.ToString());
         return(null);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Creates a Texture object for a specific color.
        /// </summary>
        /// <param name="c">The color to use.</param>
        /// <param name="name">The name of the texture.</param>
        /// <returns>The generated texture.</returns>
        public Texture GenerateForColor(Color c, string name)
        {
            Texture texture = new Texture();

            texture.Engine = this;
            texture.Name   = name;
            GL.GenTextures(1, out texture.Original_InternalID);
            texture.Internal_Texture = texture.Original_InternalID;
            texture.Bind();
            texture.Width  = 2;
            texture.Height = 2;
            Bitmap bmp = new Bitmap(2, 2);

            bmp.SetPixel(0, 0, c);
            bmp.SetPixel(0, 1, c);
            bmp.SetPixel(1, 0, c);
            bmp.SetPixel(1, 1, c);
            LockBitmapToTexture(bmp, false);
            bmp.Dispose();
            texture.LoadedProperly = true;
            return(texture);
        }
Beispiel #3
0
 /// <summary>
 /// Loads a texture from file.
 /// </summary>
 /// <param name="filename">The name of the file to use.</param>
 /// <returns>The loaded texture, or null if it does not exist.</returns>
 public Texture LoadTexture(string filename, int twidth = 0)
 {
     try
     {
         filename = FileHandler.CleanFileName(filename);
         if (!TheClient.Files.Exists("textures/" + filename + ".png"))
         {
             SysConsole.Output(OutputType.ERROR, "Cannot load texture, file '" +
                 TextStyle.Color_Standout + "textures/" + filename + ".png" + TextStyle.Color_Error +
                 "' does not exist.");
             return null;
         }
         Bitmap bmp = new Bitmap(TheClient.Files.ReadToStream("textures/" + filename + ".png"));
         if (!AcceptableWidths.Contains(bmp.Width) || !AcceptableWidths.Contains(bmp.Height))
         {
             SysConsole.Output(OutputType.ERROR, "Cannot load texture, file '" +
                 TextStyle.Color_Standout + "textures/" + filename + ".png" + TextStyle.Color_Error +
                 "' is invalid: unreasonable width or height.");
             return null;
         }
         Bitmap bmp2 = twidth <= 0 ? bmp : new Bitmap(bmp, new Size(twidth, twidth));
         Texture texture = new Texture();
         texture.Engine = this;
         texture.Name = filename;
         GL.GenTextures(1, out texture.Original_InternalID);
         texture.Internal_Texture = texture.Original_InternalID;
         texture.Bind();
         LockBitmapToTexture(bmp2, true);
         texture.Width = bmp2.Width;
         texture.Height = bmp2.Height;
         if (bmp2 != bmp)
         {
             bmp2.Dispose();
         }
         bmp.Dispose();
         texture.LoadedProperly = true;
         return texture;
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.ERROR, "Failed to load texture from filename '" +
             TextStyle.Color_Standout + "textures/" + filename + ".png" + TextStyle.Color_Error + "': " + ex.ToString());
         return null;
     }
 }
Beispiel #4
0
 /// <summary>
 /// Creates a Texture object for a specific color.
 /// </summary>
 /// <param name="c">The color to use.</param>
 /// <param name="name">The name of the texture.</param>
 /// <returns>The generated texture.</returns>
 public Texture GenerateForColor(Color c, string name)
 {
     Texture texture = new Texture();
     texture.Engine = this;
     texture.Name = name;
     GL.GenTextures(1, out texture.Original_InternalID);
     texture.Internal_Texture = texture.Original_InternalID;
     texture.Bind();
     texture.Width = 2;
     texture.Height = 2;
     Bitmap bmp = new Bitmap(2, 2);
     bmp.SetPixel(0, 0, c);
     bmp.SetPixel(0, 1, c);
     bmp.SetPixel(1, 0, c);
     bmp.SetPixel(1, 1, c);
     LockBitmapToTexture(bmp, false);
     bmp.Dispose();
     texture.LoadedProperly = true;
     return texture;
 }