public void Read(sFile file) { BinaryReader br = new BinaryReader(File.OpenRead(file.path)); string ext = new String(br.ReadChars(4)); br.Close(); if (ext == "BTX0") { sBTX0 btx = BTX0.Read(file.path, file.id, pluginHost); Bitmap[] tex = new Bitmap[btx.texture.texInfo.num_objs]; for (int i = 0; i < btx.texture.texInfo.num_objs; i++) { string fileOut = pluginHost.Get_TempFolder() + Path.DirectorySeparatorChar + file.name + '_' + btx.texture.texInfo.names[i] + ".png"; if (File.Exists(fileOut)) { fileOut = pluginHost.Get_TempFolder() + Path.DirectorySeparatorChar + Path.GetRandomFileName() + '_' + btx.texture.texInfo.names[i] + ".png"; } tex[i] = BTX0.GetTexture(pluginHost, btx, i); tex[i].Save(fileOut); } pluginHost.Set_Object(tex); } }
private int LoadTextures(int num_tex, int num_pal) { int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); Bitmap bmp = BTX0.GetTexture(pluginHost, tex, num_tex, num_pal); System.Drawing.Imaging.BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb); 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.TextureMagFilter, (float)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)TextureWrapMode.Repeat); return(id); }