Ejemplo n.º 1
0
        public static Bitmap TextureRgba(BRTI.BRTI_Texture t, SFGraphics.GLObjects.Textures.Texture renderTex)
        {
            Bitmap bitmap = new Bitmap(t.width, t.height);

            System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, t.width, t.height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            renderTex.Bind();
            GL.GetTexImage(TextureTarget.Texture2D, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0);

            bitmap.UnlockBits(bitmapData);

            return(bitmap);
        }
Ejemplo n.º 2
0
        private void replaceTextureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                BRTI t = (BRTI)(textureListBox.SelectedItem);

                ofd.Filter = "Portable Network Graphic (.png)|*.png;|" +
                             "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Edited = true;
                    BRTI.BRTI_Texture newTexture = null;
                    if (Path.GetExtension(ofd.FileName).ToLower().Equals(".png"))
                    {
                        newTexture = FromPng(ofd.FileName, 1);
                    }
                    if (Path.GetExtension(ofd.FileName).ToLower().Equals(".dds"))
                    {
                        Dds dds = new Dds(new FileData(ofd.FileName));
                        newTexture = dds.ToBrtiTexture();
                    }

                    t.texture.height = newTexture.height;
                    t.texture.width  = newTexture.width;
                    t.texture.pixelInternalFormat = newTexture.pixelInternalFormat;
                    t.texture.mipmaps             = newTexture.mipmaps;
                    t.texture.pixelFormat         = newTexture.pixelFormat;
                    newTexture.mipmaps.Add(t.texture.mipmaps[0]);

                    bntx.glTexByName.Add(ofd.FileName, BRTI.CreateTexture2D(t.texture));

                    if (newTexture == null)
                    {
                        return;
                    }

                    FillForm();
                }
            }
        }
Ejemplo n.º 3
0
        public static BRTI.BRTI_Texture FromPng(string filename, int mipcount)
        {
            Bitmap bmp = new Bitmap(filename);

            BRTI.BRTI_Texture tex = new BRTI.BRTI_Texture();

            tex.mipmaps.Add(FromPng(bmp));
            for (int i = 0; i < mipcount; i++)
            {
                if (bmp.Width / (int)Math.Pow(2, i) < 4 || bmp.Height / (int)Math.Pow(2, i) < 4)
                {
                    break;
                }
                tex.mipmaps.Add(FromPng(Pixel.ResizeImage(bmp, bmp.Width / (int)Math.Pow(2, i), bmp.Height / (int)Math.Pow(2, i))));
                tex.mipmaps[0] = tex.mipmaps[0];
            }
            tex.width  = bmp.Width;
            tex.height = bmp.Height;
            tex.pixelInternalFormat = PixelInternalFormat.Rgba;
            tex.pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;

            return(tex);
        }
Ejemplo n.º 4
0
        //For bfres / bntx
        public BRTI.BRTI_Texture ToBrtiTexture()
        {
            // TODO: Check these casts.
            BRTI.BRTI_Texture tex = new BRTI.BRTI_Texture();
            tex.height = (int)header.height;
            tex.width  = (int)header.width;
            float size = 1;
            int   mips = (int)header.mipmapCount;

            /*if (mips > header.mipmapCount)
             * {
             *  mips = header.mipmapCount;
             *  MessageBox.Show("Possible texture error: Only one mipmap");
             * }*/

            switch (header.ddspf.fourCc)
            {
            case 0x0:
                size = 4f;
                tex.pixelInternalFormat = PixelInternalFormat.SrgbAlpha;
                tex.pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
                break;

            case 0x31545844:
                size = 1 / 2f;
                tex.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                break;

            case 0x35545844:
                size = 1f;
                tex.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                break;

            case 0x32495441:
                size = 1 / 2f;
                tex.pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1;
                break;

            case 0x31495441:
                size = 1f;
                tex.pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2;
                break;

            default:
                MessageBox.Show("Unsupported DDS format - 0x" + header.ddspf.fourCc.ToString("x"));
                break;
            }

            // now for mipmap data...
            FileData d = new FileData(bdata);
            int      off = 0, w = (int)header.width, h = (int)header.height;

            if (header.mipmapCount == 0)
            {
                header.mipmapCount = 1;
            }
            for (int i = 0; i < header.mipmapCount; i++)
            {
                int s = (int)((w * h) * size);
                if (s < 0x8)
                {
                    s = 0x8;
                }
                //Console.WriteLine(off.ToString("x") + " " + s.ToString("x"));
                w /= 2;
                h /= 2;
                tex.mipmaps.Add(d.GetSection(off, s));
                off += s;
            }
            Console.WriteLine(off.ToString("x"));

            return(tex);
        }