public static Texture LoadFromFile(string path, TextureFilteringMode filteringMode = TextureFilteringMode.Nearest) { Bitmap bitmap = new Bitmap(path); Texture texture = new Texture() { Width = bitmap.Width, Height = bitmap.Height, Path = path, Filtering = filteringMode }; bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); bitmap.UnlockBits(data); texture.glTexture = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, texture.glTexture); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)filteringMode); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)filteringMode); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); GL.BindTexture(TextureTarget.Texture2D, 0); return(texture); }
public static Spritesheet Load(string file, int width, int height, TextureFilteringMode mode) { if (System.IO.File.Exists(file)) { using (var bmp = new Bitmap(file)) return Load(bmp, width, height, mode); } return null; }
public static Spritesheet Load(Bitmap TextureBitmap, int width, int height, TextureFilteringMode mode) { var ret = new Spritesheet(); ret.Texture = Texture2D.Load(TextureBitmap, mode); ret.TileWidth = width; ret.TileHeight = height; ret.Rows = TextureBitmap.Width / width; ret.Columns = TextureBitmap.Height / height; ret.RowSize = TextureBitmap.Width; ret.ColumnSize = TextureBitmap.Height; return ret; }
public static AnimatedTexture Load(string path, int width, int height, TextureFilteringMode mode) { var sheet = Spritesheet.Load(path, width, height, mode); if (sheet != null) { var anim = new AnimatedTexture(); anim.Width = width; anim.Height = height; anim.Sheet = sheet; return anim; } return null; }
public static Texture2D Load(BitmapData TextureData, TextureFilteringMode mode) { int id = 0; GL.GenTextures(1, out id); GL.BindTexture(TextureTarget.Texture2D, id); GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvMode.Modulate); switch (mode) { case TextureFilteringMode.Nearest: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.NearestMipmapNearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Nearest); break; default: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.LinearMipmapLinear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Linear); break; } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, (float)1.0f); GL.TexImage2D( TextureTarget.Texture2D, 0, // level PixelInternalFormat.Four, TextureData.Width, TextureData.Height, 0, // border OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, TextureData.Scan0 ); var Texture = new Texture2D(); Texture.Width = TextureData.Width; Texture.Height = TextureData.Height; Texture.ID = id; if (Texture.ID == 0) return null; return Texture; }
public static Texture2D Load(string path, TextureFilteringMode mode) { int id; Console.WriteLine("Attemtping to load texture at '" + path + "'"); if (System.IO.File.Exists(path)) { Texture2D Texture = new Texture2D(); using (Bitmap TextureBitmap = new Bitmap(path)) Texture = Load(TextureBitmap, mode); return Texture; } return null; }
public static Texture2D Load(Bitmap TextureBitmap, TextureFilteringMode mode) { int id; Texture2D Texture;// = new Texture2D(); BitmapData TextureData = TextureBitmap.LockBits( new Rectangle(0, 0, TextureBitmap.Width, TextureBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); Texture = Load(TextureData, mode); TextureBitmap.UnlockBits(TextureData); return Texture; }
public abstract void PushTextureFilteringMode(TextureFilteringMode mode);
/// <summary> /// Loads a font from a bitmap file. /// </summary> /// <param name="path">The path of the bitmap</param> /// <param name="charactersHorizontal">Specifies how many characters wide the bitmap is horizontally</param> /// <param name="charactersVertical">Specifies how many characters wide the bitmap is vertically</param> /// <returns></returns> public static Font Load(string path, int charactersHorizontal, int charactersVertical, TextureFilteringMode textureFiltering = TextureFilteringMode.Nearest) { Font font = new Font() { Bitmap = Texture.LoadFromFile(path, textureFiltering), SizeInCharacters = new Vector2(charactersHorizontal, charactersVertical) }; return(font); }