Exemplo n.º 1
0
 protected void LoadTexture(string filename)
 {
     if(String.IsNullOrEmpty(filename)){
         throw new ArgumentException(filename);
     }
     if(texture_info.ContainsKey(filename)){
         Texture t = texture_info[filename];
         TextureIndex = t.TextureIndex;
         TextureHeightPx = t.TextureHeightPx;
         TextureWidthPx = t.TextureWidthPx;
     }
     else{
         if(max_textures == -1){
             GL.GetInteger(GetPName.MaxTextureImageUnits,out max_textures);
         }
         int num = next_texture++;
         if(num == max_textures){ //todo: eventually fix this
             throw new NotSupportedException("This machine only supports " + num + " texture units, and this GL code isn't smart enough to switch them out yet, sorry.");
         }
         GL.ActiveTexture(TextureUnit.Texture0 + num);
         int id = GL.GenTexture(); //todo: eventually i'll want to support more than 16 or 32 textures. At that time I'll need to store this ID somewhere.
         GL.BindTexture(TextureTarget.Texture2D,id); //maybe a list of Scenes which are lists of textures needed, and then i'll bind all those and make sure to track their texture units.
         Bitmap bmp = new Bitmap(filename);
         BitmapData bmp_data = bmp.LockBits(new Rectangle(0,0,bmp.Width,bmp.Height),ImageLockMode.ReadOnly,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         GL.TexImage2D(TextureTarget.Texture2D,0,PixelInternalFormat.Rgba,bmp_data.Width,bmp_data.Height,0,OpenTK.Graphics.OpenGL.PixelFormat.Bgra,PixelType.UnsignedByte,bmp_data.Scan0);
         bmp.UnlockBits(bmp_data);
         GL.TexParameter(TextureTarget.Texture2D,TextureParameterName.TextureMinFilter,(int)TextureMinFilter.Nearest);
         GL.TexParameter(TextureTarget.Texture2D,TextureParameterName.TextureMagFilter,(int)TextureMagFilter.Nearest);
         TextureIndex = num;
         TextureHeightPx = bmp.Height;
         TextureWidthPx = bmp.Width;
         Texture t = new Texture(); //this one goes into the dictionary as an easy way to store the index/height/width of this filename.
         t.TextureIndex = num;
         t.TextureHeightPx = bmp.Height;
         t.TextureWidthPx = bmp.Width;
         texture_info.Add(filename,t);
     }
 }
Exemplo n.º 2
0
 public static Texture Create(string filename)
 {
     Texture t = new Texture();
     t.Sprite = new List<SpriteType>();
     t.LoadTexture(filename);
     return t;
 }