private void RenderTexture(BFRES.Mesh m = null, BRTI tex = null, FTEX ftex = null)
        {
            Texture     = tex;
            FTEXTexture = ftex;
            mesh        = m;
            mat         = mesh.material;

            foreach (BFRES.MatTexture te in mat.textures)
            {
                if (tex != null)
                {
                    if (te.Name == tex.Text)
                    {
                        Mattex = te;
                        comboBox1.SelectedIndex = te.wrapModeS;
                        comboBox2.SelectedIndex = te.wrapModeT;
                    }
                }
                if (ftex != null)
                {
                    if (te.Name == ftex.Text)
                    {
                        Mattex = te;
                        comboBox1.SelectedIndex = te.wrapModeS;
                        comboBox2.SelectedIndex = te.wrapModeT;
                    }
                }
            }
        }
예제 #2
0
        private void RenderTextureAlpha(BRTI tex)
        {
            if (!_loadedA || glControl2 == null)
            {
                return;
            }

            if (Rendering.OpenTKSharedResources.SetupStatus != Rendering.OpenTKSharedResources.SharedResourceStatus.Initialized)
            {
                return;
            }

            glControl2.MakeCurrent();
            GL.Viewport(glControl2.ClientRectangle);

            if (listView1.SelectedItems == null)
            {
                glControl2.SwapBuffers();
                return;
            }

            int width  = tex.Width;
            int height = tex.Height;

            int texture = tex.display;

            Rendering.ScreenDrawing.DrawTexturedQuad(texture, width, height, screenVao, false, false, false, true);

            glControl2.SwapBuffers();
        }
예제 #3
0
        private void RenderTextureColor(BRTI tex)
        {
            if (!_loadedC || glControl1 == null)
            {
                return;
            }

            glControl1.MakeCurrent();
            GL.Viewport(glControl1.ClientRectangle);

            if (listView1.SelectedItems == null)
            {
                glControl1.SwapBuffers();
                return;
            }

            int width  = tex.Width;
            int height = tex.Height;

            int texture = tex.display;

            Rendering.ScreenDrawing.DrawTexturedQuad(texture, width, height, true, true, true, false);

            glControl1.SwapBuffers();
        }
예제 #4
0
        private void exportTextureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (textureListBox.SelectedItem == null)
            {
                return;
            }
            using (var sfd = new SaveFileDialog())
            {
                BRTI tex = (BRTI)(textureListBox.SelectedItem);
                sfd.Filter = "Direct Draw Surface (.png)|*.png|" +
                             "All files(*.*)|*.*";

                sfd.FileName = tex.Text;

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    // use png instead
                    if (sfd.FileName.EndsWith(".png"))
                    {
                        tex.ExportAsImage(tex.texture, tex.display, sfd.FileName + ".png");
                    }
                    if (sfd.FileName.EndsWith(".dds"))
                    {
                    }
                }
            }
        }
예제 #5
0
        private void textureListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (textureListBox.SelectedIndex >= 0)
            {
                BRTI b = ((BRTI)textureListBox.SelectedItem);


                label1.Text = "Width: " + b.texture.width;
                label2.Text = "Height: " + b.texture.height;

                uint Format   = b.format >> 8;
                byte DataType = (byte)(b.format & 0xFF);

                Formats.BNTXImageFormat f = (Formats.BNTXImageFormat)Format;
                Formats.BNTXImageTypes  t = (Formats.BNTXImageTypes)DataType;

                label3.Text = f.ToString() + " " + t.ToString();
            }
            else
            {
                label1.Text = "Width: " + "";
                label2.Text = "Height: " + "";
            }
            glControl1.Invalidate();
        }
예제 #6
0
        private void textureListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (textureListBox.SelectedIndex >= 0)
            {
                SelectedTexture = ((BRTI)textureListBox.SelectedItem);


                label1.Text = "Width: " + SelectedTexture.texture.width;
                label2.Text = "Height: " + SelectedTexture.texture.height;

                uint Format   = SelectedTexture.format >> 8;
                byte DataType = (byte)(SelectedTexture.format & 0xFF);

                Formats.BNTXImageFormat f = (Formats.BNTXImageFormat)Format;
                Formats.BNTXImageTypes  t = (Formats.BNTXImageTypes)DataType;

                label3.Text = f.ToString() + " " + t.ToString();

                // Render the selected texture.
                if (BNTX.glTexByName.ContainsKey(SelectedTexture.Text))
                {
                    textureToRender = BNTX.glTexByName[SelectedTexture.Text];
                }
            }
            else
            {
                label1.Text = "Width: " + "";
                label2.Text = "Height: " + "";
            }
            glControl1.Invalidate();
        }
예제 #7
0
        public void RefreshGlTexturesByName()
        {
            glTexByName.Clear();

            foreach (BRTI tex in Nodes)
            {
                Texture2D tex2d = BRTI.CreateTexture2D(tex.texture);
                tex.texture.display = tex2d;
                tex.display         = tex.texture.display;

                glTexByName.Add(tex.Text, tex2d);
            }
        }
예제 #8
0
        public void ReadBNTX(FileData f)
        {
            textures.Clear();

            BFRES b = new BFRES();

            temp = f.pos();

            f.skip(8); //Magic
            int Version        = f.readInt();
            int ByteOrderMark  = f.readShort();
            int FormatRevision = f.readShort();

            Text = f.readString(f.readInt() + temp, -1);
            f.skip(2);
            int strOffset   = f.readShort();
            int relocOffset = f.readInt();
            int FileSize    = f.readInt();

            f.skip(4); //NX Magic
            int TexturesCount   = f.readInt();
            int InfoPtrsOffset  = f.readInt();
            int DataBlockOffset = f.readInt();
            int DictOffset      = f.readInt();
            int strDictSize     = f.readInt();

            Text = Text + ".bntx";

            BNTXFile = f.getSection(temp, FileSize);

            for (int i = 0; i < TexturesCount; i++)
            {
                f.seek(InfoPtrsOffset + temp + i * 8);
                BRTIOffset = f.readInt();


                f.seek(BRTIOffset + temp);

                //  textures.Add(new BRTI(f));
                BRTI texture = new BRTI(f);

                if (!textured.ContainsKey(texture.Text))
                {
                    textured.Add(texture.Text, texture);
                }

                textures.Add(texture);
            }
            Nodes.AddRange(textures.ToArray());
        }
예제 #9
0
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                string TexName = listView1.SelectedItems[0].Text;
                if (BNTX.textured.ContainsKey(TexName))
                {
                    BRTI tex = BNTX.textured[TexName];

                    RenderTextureColor(tex);
                    RenderTextureAlpha(tex);
                }
            }
        }
예제 #10
0
        public void ReadBNTX(FileData f)
        {
            ImageKey         = "UVPattern";
            SelectedImageKey = "UVPattern";

            textures.Clear();
            textured.Clear();

            temp = f.pos();

            f.skip(8); //Magic
            int Version        = f.readInt();
            int ByteOrderMark  = f.readShort();
            int FormatRevision = f.readShort();

            Text = f.readString(f.readInt() + temp, -1);
            f.skip(2);
            int strOffset   = f.readShort();
            int relocOffset = f.readInt();
            int FileSize    = f.readInt();

            f.skip(4); //NX Magic
            int TexturesCount   = f.readInt();
            int InfoPtrsOffset  = f.readInt();
            int DataBlockOffset = f.readInt();
            int DictOffset      = f.readInt();
            int strDictSize     = f.readInt();

            for (int i = 0; i < TexturesCount; i++)
            {
                f.seek(InfoPtrsOffset + temp + i * 8);
                BRTIOffset = f.readInt();


                f.seek(BRTIOffset + temp);

                //  textures.Add(new BRTI(f));
                BRTI texture = new BRTI(f);

                textured.Add(texture.Text, texture);
                textures.Add(texture);
            }
            Nodes.AddRange(textures.ToArray());
        }
예제 #11
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;
                    t.texture.data = newTexture.data;

                    GL.DeleteTexture(t.texture.display);

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

                    if (newTexture == null)
                    {
                        return;
                    }

                    FillForm();
                }
            }
        }
 public void LoadTexture(BFRES.Mesh m = null, BRTI tex = null, FTEX ftex = null)
 {
     RenderTexture(m, tex, ftex);
 }
예제 #13
0
 private void OpenTextureEditor(BRTI tex)
 {
 }
예제 #14
0
        public void ReadFTEX(Texture tex)
        {
            ImageKey         = "texture";
            SelectedImageKey = "texture";

            reserve = tex.Data;

            texture.width  = (int)tex.Width;
            texture.height = (int)tex.Height;
            format         = (int)tex.Format;
            int swizzle = (int)tex.Swizzle;
            int pitch   = (int)tex.Pitch;

            texture.data = GTX.swizzleBC(tex.Data, texture.width, texture.height, format, (int)tex.TileMode, pitch, swizzle);
            Text         = tex.Name;

            //Setup variables for treenode data

            width  = texture.width;
            height = texture.height;


            switch (format)
            {
            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC1_UNORM):
                texture.type = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC1_SRGB):
                texture.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt1Ext;
                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC2_UNORM):
                texture.type = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC2_SRGB):
                texture.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext;
                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC3_UNORM):
                texture.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC3_SRGB):
                texture.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext;
                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC4_UNORM):
                texture.type = PixelInternalFormat.CompressedRedRgtc1;
                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC4_SNORM):
                texture.type = PixelInternalFormat.CompressedSignedRedRgtc1;
                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC5_UNORM):
                texture.type = PixelInternalFormat.CompressedRgRgtc2;
                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC5_SNORM):
                //OpenTK doesn't load BC5 SNORM textures right so I'll use the same decompress method bntx has
                byte[] fixBC5 = BRTI.DecompressBC5(texture.data, texture.width, texture.height, true);
                texture.data  = fixBC5;
                texture.type  = PixelInternalFormat.Rgba;
                texture.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;

                break;

            case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM):
                texture.type  = PixelInternalFormat.Rgba;
                texture.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
                break;
            }
            texture.display = loadImage(texture);
            display         = texture.display;
        }
예제 #15
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
            {
                BRTI b = ((BRTI)listBox1.SelectedItem);

                label1.Text = "Width: " + b.texture.width;
                label2.Text = "Height: " + b.texture.height;

                switch (b.format >> 8)
                {
                case (uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC1:
                {
                    label3.Text = "Format: BC1/DXT1";
                }
                break;

                case (uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC2:
                {
                    label3.Text = "Format: BC2/DXT2";
                }
                break;

                case (uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC3:
                {
                    label3.Text = "Format: BC3/DXT5";
                }
                break;

                case (uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC4:
                {
                    label3.Text = "Format: BC4/ATI1";
                }
                break;

                case (uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC5:
                {
                    label3.Text = "Format: BC5/ATI2";
                }
                break;

                case (uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC6:
                {
                    label3.Text = "Format: BC6";
                }
                break;

                case (uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC7:
                {
                    label3.Text = "Format: BC7";
                }
                break;

                default:
                    label3.Text = "Format: Unsupported format";
                    break;
                }
            }
            else
            {
                label1.Text = "Width: " + "";
                label2.Text = "Height: " + "";
            }
            glControl1.Invalidate();
        }