Esempio n. 1
0
        public static Texture2D CreateTexture2D(NutTexture nutTexture, int surfaceIndex = 0)
        {
            bool compressedFormatWithMipMaps = nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRgbaS3tcDxt1Ext ||
                                               nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRgbaS3tcDxt3Ext ||
                                               nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRgbaS3tcDxt5Ext ||
                                               nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRedRgtc1 ||
                                               nutTexture.pixelInternalFormat == PixelInternalFormat.CompressedRgRgtc2;

            if (compressedFormatWithMipMaps)
            {
                if (nutTexture.surfaces[0].mipmaps.Count > 1 && nutTexture.isDds)
                {
                    // Reading mip maps past the first level is only supported for DDS currently.
                    return(new Texture2D(nutTexture.Width, nutTexture.Height, nutTexture.surfaces[surfaceIndex].mipmaps, true,
                                         (InternalFormat)nutTexture.pixelInternalFormat));
                }
                else
                {
                    // Only load the first level and generate the rest.
                    return(new Texture2D(nutTexture.Width, nutTexture.Height,
                                         nutTexture.surfaces[surfaceIndex].mipmaps, false,
                                         (InternalFormat)nutTexture.pixelInternalFormat));
                }
            }
            else
            {
                Texture2D texture = new Texture2D(nutTexture.Width, nutTexture.Height);
                texture.Bind();
                AutoGenerateMipMaps(nutTexture);
                return(texture);
            }
        }
Esempio n. 2
0
        private void ExportPNG(string filename, NutTexture tex)
        {
            if (tex.surfaces[0].mipmaps.Count > 1)
            {
                MessageBox.Show("Note: Textures exported as PNG do not preserve mipmaps.");
            }

            switch (tex.pixelFormat)
            {
            case OpenTK.Graphics.OpenGL.PixelFormat.Rgba:
                Pixel.fromRGBA(new FileData(tex.surfaces[0].mipmaps[0]), tex.Width, tex.Height).Save(filename);
                break;

            case OpenTK.Graphics.OpenGL.PixelFormat.AbgrExt:
                Pixel.fromABGR(new FileData(tex.surfaces[0].mipmaps[0]), tex.Width, tex.Height).Save(filename);
                break;

            case OpenTK.Graphics.OpenGL.PixelFormat.Bgra:
                Pixel.fromBGRA(new FileData(tex.surfaces[0].mipmaps[0]), tex.Width, tex.Height).Save(filename);
                break;

            default:
                RenderTextureToPng(tex, filename, true, true, true, true);
                break;
            }
        }
Esempio n. 3
0
        public static int CreateGlTexture(NutTexture t, bool isDds = false)
        {
            int texID = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, texID);

            bool compressedFormatWithMipMaps = t.type == PixelInternalFormat.CompressedRgbaS3tcDxt1Ext ||
                                               t.type == PixelInternalFormat.CompressedRgbaS3tcDxt3Ext ||
                                               t.type == PixelInternalFormat.CompressedRgbaS3tcDxt5Ext ||
                                               t.type == PixelInternalFormat.CompressedRedRgtc1 ||
                                               t.type == PixelInternalFormat.CompressedRgRgtc2;

            if (compressedFormatWithMipMaps)
            {
                // Always load the first level.
                GL.CompressedTexImage2D <byte>(TextureTarget.Texture2D, 0, t.type, t.Width, t.Height, 0, t.Size, t.surfaces[0].mipmaps[0]);

                // Reading mip maps past the first level is only supported for DDS currently.
                if (t.surfaces[0].mipmaps.Count > 1 && isDds)
                {
                    LoadMipMapsCompressed(t);
                }
                else
                {
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                }
            }
            else
            {
                AutoGenerateMipMaps(t);
            }

            return(texID);
        }
Esempio n. 4
0
        private void textureListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (textureListBox.SelectedIndex >= 0)
            {
                NutTexture tex = ((NutTexture)textureListBox.SelectedItem);
                textureIdTB.Text = tex.ToString();
                formatLabel.Text = "Format: " + (tex.type == PixelInternalFormat.Rgba ? "" + tex.utype : "" + tex.type);
                widthLabel.Text  = "Width: " + tex.Width;
                heightLabel.Text = "Height:" + tex.Height;

                // Get number of mip maps for current texture.
                mipLevelTrackBar.Maximum = (tex.surfaces[0].mipmaps.Count) - 1;
                maxMipLevelLabel.Text    = "Total:" + tex.surfaces[0].mipmaps.Count + "";
            }
            else
            {
                textureIdTB.Text = "";
                formatLabel.Text = "Format:";
                widthLabel.Text  = "Width:";
                heightLabel.Text = "Height:";
            }

            glControl1.Invalidate();
            glControl1.Update();
            RenderTexture();
        }
Esempio n. 5
0
        private void importBack(string filename)
        {
            if (dontModify)
            {
                return;
            }

            NutTexture tex = textureFromFile[filename];

            try
            {
                DDS        dds  = new DDS(new FileData(filename));
                NutTexture ntex = dds.toNUT_Texture();

                tex.Height  = ntex.Height;
                tex.Width   = ntex.Width;
                tex.type    = ntex.type;
                tex.mipmaps = ntex.mipmaps;
                tex.utype   = ntex.utype;

                GL.DeleteTexture(NUT.draw[tex.HASHID]);
                NUT.draw.Remove(tex.HASHID);
                NUT.draw.Add(tex.HASHID, NUT.loadImage(tex));

                FillForm();
                textureListBox.SelectedItem = tex;
                glControl1.Invalidate();
            }
            catch
            {
                Console.WriteLine("Could not be open for editing");
            }
        }
Esempio n. 6
0
 private void SetGeneralAndDimensionsText(NutTexture tex)
 {
     textureIdTB.Text = tex.ToString();
     formatLabel.Text = "Format: " + (tex.pixelInternalFormat == PixelInternalFormat.Rgba ? "" + tex.pixelFormat : "" + tex.pixelInternalFormat);
     widthLabel.Text  = "Width: " + tex.Width;
     heightLabel.Text = "Height:" + tex.Height;
 }
Esempio n. 7
0
        private void ExportDDS(string filename, NutTexture tex)
        {
            DDS dds = new DDS();

            dds.FromNutTexture(tex);
            dds.Save(filename);
        }
Esempio n. 8
0
        public static void RegenerateMipmapsFromTexture2D(NutTexture tex)
        {
            if (!TextureFormatTools.IsCompressed(tex.pixelInternalFormat))
            {
                return;
            }

            Rendering.OpenTKSharedResources.dummyResourceWindow.MakeCurrent();

            // Create an OpenGL texture with generated mipmaps.
            Texture2D texture2D = new Texture2D();

            texture2D.LoadImageData(tex.Width, tex.Height, tex.surfaces[0].mipmaps[0],
                                    tex.surfaces[0].mipmaps.Count, (InternalFormat)tex.pixelInternalFormat);

            texture2D.Bind();

            for (int i = 0; i < tex.surfaces[0].mipmaps.Count; i++)
            {
                // Get the image size for the current mip level of the bound texture.
                int imageSize;
                GL.GetTexLevelParameter(TextureTarget.Texture2D, i,
                                        GetTextureParameter.TextureCompressedImageSize, out imageSize);

                byte[] mipLevelData = new byte[imageSize];

                // Replace the Nut texture with the OpenGL texture's data.
                GL.GetCompressedTexImage(TextureTarget.Texture2D, i, mipLevelData);
                tex.surfaces[0].mipmaps[i] = mipLevelData;
            }
        }
Esempio n. 9
0
        private void importBack(string filename)
        {
            if (dontModify)
            {
                return;
            }

            NutTexture tex = textureFromFile[filename];

            try
            {
                DDS        dds  = new DDS(new FileData(filename));
                NutTexture ntex = dds.ToNutTexture();

                tex.Height = ntex.Height;
                tex.Width  = ntex.Width;
                tex.pixelInternalFormat = ntex.pixelInternalFormat;
                tex.surfaces            = ntex.surfaces;
                tex.pixelFormat         = ntex.pixelFormat;

                //GL.DeleteTexture(NUT.glTexByHashId[tex.HASHID]);
                currentNut.glTexByHashId.Remove(tex.HashId);
                currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));

                FillForm();
                textureListBox.SelectedItem = tex;
                glControl1.Invalidate();
            }
            catch
            {
                Console.WriteLine("Could not be open for editing");
            }
        }
Esempio n. 10
0
 private NUT ReplaceTexture(NutTexture tex, int width, int height, NUT nut)
 {
     if (tex.Width == width && tex.Height == height)
     {
         tex.HASHID = 0x280052B7;
         if (nut != null && nut.Nodes.Count > 0)
         {
             tex.HASHID = ((NutTexture)nut.Nodes[0]).HASHID;
             nut.Destroy();
         }
         if (nut == null)
         {
             nut = new NUT();
         }
         nut.Nodes.Clear();
         nut.glTexByHashId.Clear();
         nut.Nodes.Add(tex);
         nut.glTexByHashId.Add(tex.HASHID, NUT.CreateGlTexture(tex));
     }
     else
     {
         MessageBox.Show("Dimensions must be " + width + "x" + height);
     }
     return(nut);
 }
Esempio n. 11
0
        public static Texture2D CreateTexture2D(NutTexture nutTexture, int surfaceIndex = 0)
        {
            bool compressedFormatWithMipMaps = TextureFormatTools.IsCompressed(nutTexture.pixelInternalFormat);

            List <byte[]> mipmaps = nutTexture.surfaces[surfaceIndex].mipmaps;

            if (compressedFormatWithMipMaps)
            {
                // HACK: Skip loading mipmaps for non square textures for now.
                // The existing mipmaps don't display properly for some reason.
                if (nutTexture.surfaces[0].mipmaps.Count > 1 && nutTexture.isDds && (nutTexture.Width == nutTexture.Height))
                {
                    // Reading mipmaps past the first level is only supported for DDS currently.
                    Texture2D texture = new Texture2D();
                    texture.LoadImageData(nutTexture.Width, nutTexture.Height, nutTexture.surfaces[surfaceIndex].mipmaps,
                                          (InternalFormat)nutTexture.pixelInternalFormat);
                    return(texture);
                }
                else
                {
                    // Only load the first level and generate the rest.
                    Texture2D texture = new Texture2D();
                    texture.LoadImageData(nutTexture.Width, nutTexture.Height, mipmaps[0], (InternalFormat)nutTexture.pixelInternalFormat);
                    return(texture);
                }
            }
            else
            {
                // Uncompressed.
                Texture2D texture = new Texture2D();
                texture.LoadImageData(nutTexture.Width, nutTexture.Height, mipmaps[0],
                                      new TextureFormatUncompressed(nutTexture.pixelInternalFormat, nutTexture.pixelFormat, nutTexture.pixelType));
                return(texture);
            }
        }
Esempio n. 12
0
        private void exportTextureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (NUT == null || textureListBox.SelectedItem == null)
            {
                return;
            }
            using (var sfd = new SaveFileDialog())
            {
                NutTexture tex = (NutTexture)(textureListBox.SelectedItem);

                sfd.FileName = tex.ToString() + ".dds";
                sfd.Filter   = "Supported Formats|*.dds;*.png|" +
                               "DirectDraw Surface (.dds)|*.dds|" +
                               "Portable Network Graphics (.png)|*.png|" +
                               "All files(*.*)|*.*";

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    string extension = Path.GetExtension(sfd.FileName).ToLowerInvariant();

                    if (extension == ".dds")
                    {
                        ExportDDS(sfd.FileName, tex);
                    }
                    else if (extension == ".png")
                    {
                        ExportPNG(sfd.FileName, tex);
                    }
                }
            }
        }
Esempio n. 13
0
        public static TextureCubeMap CreateTextureCubeMap(NutTexture t)
        {
            TextureCubeMap texture = new TextureCubeMap(Properties.Resources._10102000);

            texture.Bind();

            // Necessary to access mipmaps past the base level.
            texture.MinFilter = TextureMinFilter.LinearMipmapLinear;

            // The number of mip maps needs to be specified first.
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureBaseLevel, 0);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMaxLevel, t.surfaces[0].mipmaps.Count);
            GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap);

            for (int i = 0; i < t.surfaces.Count; i++)
            {
                GL.CompressedTexImage2D <byte>(TextureTarget.TextureCubeMapPositiveX + i, 0, (InternalFormat)t.pixelInternalFormat, t.Width, t.Height, 0, t.ImageSize, t.surfaces[i].mipmaps[0]);

                // Initialize the data for each level.
                for (int j = 1; j < t.surfaces[i].mipmaps.Count; j++)
                {
                    GL.CompressedTexImage2D <byte>(TextureTarget.TextureCubeMapPositiveX + i, j, (InternalFormat)t.pixelInternalFormat,
                                                   t.Width / (int)Math.Pow(2, j), t.Height / (int)Math.Pow(2, j), 0, t.ImageSize, t.surfaces[i].mipmaps[j]);
                }
            }

            return(texture);
        }
        private void RenderTexture(bool justRenderAlpha = false)
        {
            if (OpenTKSharedResources.SetupStatus != OpenTKSharedResources.SharedResourceStatus.Initialized)
            {
                return;
            }

            if (!tabControl1.SelectedTab.Text.Equals("Textures"))
            {
                return;
            }

            if (!OpenTKSharedResources.shaders["Texture"].ProgramCreatedSuccessfully)
            {
                return;
            }

            // Get the selected NUT texture.
            NutTexture nutTexture     = null;
            int        displayTexture = 0;

            if (currentMaterialList[currentMatIndex].entries.ContainsKey("NU_materialHash") && texturesListView.SelectedIndices.Count > 0)
            {
                int hash = currentMaterialList[currentMatIndex].textures[texturesListView.SelectedIndices[0]].hash;

                // Display dummy textures from resources.
                if (Enum.IsDefined(typeof(NUD.DummyTextures), hash))
                {
                    displayTexture = RenderTools.dummyTextures[(NUD.DummyTextures)hash].Id;
                }
                else
                {
                    foreach (NUT n in Runtime.TextureContainers)
                    {
                        if (n.glTexByHashId.ContainsKey(hash))
                        {
                            n.getTextureByID(hash, out nutTexture);
                            displayTexture = n.glTexByHashId[hash].Id;
                            break;
                        }
                    }
                }
            }

            if (justRenderAlpha)
            {
                texAlphaGlControl.MakeCurrent();
                GL.Viewport(texAlphaGlControl.ClientRectangle);
                ScreenDrawing.DrawTexturedQuad(displayTexture, 1, 1, false, false, false, true);
                texAlphaGlControl.SwapBuffers();
            }
            else
            {
                texRgbGlControl.MakeCurrent();
                GL.Viewport(texRgbGlControl.ClientRectangle);
                ScreenDrawing.DrawTexturedQuad(displayTexture, 1, 1);
                texRgbGlControl.SwapBuffers();
            }
        }
Esempio n. 15
0
 private void SetMipMapText(NutTexture tex)
 {
     // Display the total mip maps.
     mipmapGroupBox.Text      = "Mipmaps";
     mipLevelLabel.Text       = "Mip Level";
     mipLevelTrackBar.Maximum = tex.surfaces[0].mipmaps.Count - 1;
     minMipLevelLabel.Text    = "1";
     maxMipLevelLabel.Text    = "Total:" + tex.surfaces[0].mipmaps.Count + "";
 }
Esempio n. 16
0
 private void SetCubeMapText(NutTexture tex)
 {
     // Display the current face instead of mip map information.
     mipmapGroupBox.Text = "Cube Map Faces";
     SetCurrentCubeMapFaceLabel(mipLevelTrackBar.Value);
     mipLevelTrackBar.Maximum = tex.surfaces.Count - 1;
     minMipLevelLabel.Text    = "";
     maxMipLevelLabel.Text    = "";
 }
Esempio n. 17
0
        private void RenderTexture(bool justRenderAlpha = false)
        {
            if (!tabControl1.SelectedTab.Text.Equals("Textures"))
            {
                return;
            }

            // Get the selected NUT texture.
            NutTexture nutTexture     = null;
            int        displayTexture = 0;

            if (currentMaterialList[currentMatIndex].entries.ContainsKey("NU_materialHash") && texturesListView.SelectedIndices.Count > 0)
            {
                int hash = currentMaterialList[currentMatIndex].textures[texturesListView.SelectedIndices[0]].hash;

                // Display dummy textures from resources.
                if (Enum.IsDefined(typeof(NUD.DummyTextures), hash))
                {
                    displayTexture = RenderTools.dummyTextures[(NUD.DummyTextures)hash];
                }
                else
                {
                    foreach (NUT n in Runtime.TextureContainers)
                    {
                        if (n.glTexByHashId.ContainsKey(hash))
                        {
                            n.getTextureByID(hash, out nutTexture);
                            displayTexture = n.glTexByHashId[hash];
                            break;
                        }
                    }
                }
            }

            if (justRenderAlpha)
            {
                texAlphaGlControl.MakeCurrent();
                GL.Viewport(texAlphaGlControl.ClientRectangle);
                RenderTools.DrawTexturedQuad(displayTexture, 1, 1, false, false, false, true);
                texAlphaGlControl.SwapBuffers();
            }
            else
            {
                texRgbGlControl.MakeCurrent();
                GL.Viewport(texRgbGlControl.ClientRectangle);
                RenderTools.DrawTexturedQuad(displayTexture, 1, 1);
                Bitmap image = FramebufferTools.ReadFrameBufferPixels(0, FramebufferTarget.Framebuffer, texRgbGlControl.Width, texRgbGlControl.Height);
                image.Save(MainForm.executableDir + "\\image.png");
                texRgbGlControl.SwapBuffers();
            }

            if (!Runtime.shaders["Texture"].HasCheckedCompilation)
            {
                Runtime.shaders["Texture"].DisplayProgramStatus("Texture");
            }
        }
Esempio n. 18
0
        private void RenderTexture(bool justRenderAlpha = false)
        {
            if (!tabControl1.SelectedTab.Text.Equals("Textures"))
            {
                return;
            }

            // Get the selected NUT texture.
            NutTexture nutTexture     = null;
            int        displayTexture = 0;

            if (currentMaterialList[currentMatIndex].entries.ContainsKey("NU_materialHash") && texturesListView.SelectedIndices.Count > 0)
            {
                int hash = currentMaterialList[currentMatIndex].textures[texturesListView.SelectedIndices[0]].hash;

                // Display dummy textures from resources.
                if (Enum.IsDefined(typeof(NUD.DummyTextures), hash))
                {
                    displayTexture = RenderTools.dummyTextures[(NUD.DummyTextures)hash];
                }
                else
                {
                    foreach (NUT n in Runtime.TextureContainers)
                    {
                        if (n.draw.ContainsKey(hash))
                        {
                            n.getTextureByID(hash, out nutTexture);
                            displayTexture = n.draw[hash];
                            break;
                        }
                    }
                }
            }

            if (justRenderAlpha)
            {
                texAlphaGlControl.MakeCurrent();
                GL.Viewport(texAlphaGlControl.ClientRectangle);
                RenderTools.DrawTexturedQuad(displayTexture, 1, 1, false, false, false, true);
                //RenderTools.DrawNudMaterialSphere(currentMaterialList[currentMatIndex]);
                texAlphaGlControl.SwapBuffers();
            }
            else
            {
                texRgbGlControl.MakeCurrent();
                GL.Viewport(texRgbGlControl.ClientRectangle);
                RenderTools.DrawTexturedQuad(displayTexture, 1, 1);
                //RenderTools.DrawNudMaterialSphere(materials[0]);
                texRgbGlControl.SwapBuffers();
            }

            if (!Runtime.shaders["Texture"].HasCheckedCompilation)
            {
                Runtime.shaders["Texture"].DisplayCompilationWarnings("Texture");
            }
        }
Esempio n. 19
0
 private static void AutoGenerateMipMaps(NutTexture t)
 {
     for (int i = 0; i < t.surfaces.Count; ++i)
     {
         // Only load the first level and generate the other mip maps.
         GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, t.surfaces[i].mipmaps.Count);
         GL.TexImage2D <byte>(TextureTarget.Texture2D, 0, t.pixelInternalFormat, t.Width, t.Height, 0, t.pixelFormat, t.pixelType, t.surfaces[i].mipmaps[0]);
         GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
     }
 }
Esempio n. 20
0
 private void RemoveToolStripMenuItem1_Click_1(object sender, EventArgs e)
 {
     if (textureListBox.SelectedIndex >= 0 && currentNut != null)
     {
         NutTexture tex = ((NutTexture)textureListBox.SelectedItem);
         currentNut.glTexByHashId.Remove(tex.HashId);
         currentNut.Nodes.Remove(tex);
         FillForm();
     }
 }
Esempio n. 21
0
 private void RemoveToolStripMenuItem1_Click_1(object sender, EventArgs e)
 {
     if (textureListBox.SelectedIndex >= 0 && NUT != null)
     {
         NutTexture tex = ((NutTexture)textureListBox.SelectedItem);
         GL.DeleteTexture(NUT.glTexByHashId[tex.HASHID]);
         NUT.glTexByHashId.Remove(tex.HASHID);
         NUT.Nodes.Remove(tex);
         FillForm();
     }
 }
Esempio n. 22
0
        public static int loadImage(NutTexture t, bool DDS = false)
        {
            int texID = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, texID);

            if (t.type == PixelInternalFormat.CompressedRgbaS3tcDxt1Ext ||
                t.type == PixelInternalFormat.CompressedRgbaS3tcDxt3Ext ||
                t.type == PixelInternalFormat.CompressedRgbaS3tcDxt5Ext ||
                t.type == PixelInternalFormat.CompressedRedRgtc1 ||
                t.type == PixelInternalFormat.CompressedRgRgtc2)
            {
                GL.CompressedTexImage2D <byte>(TextureTarget.Texture2D, 0, t.type,
                                               t.Width, t.Height, 0, t.Size, t.mipmaps[0]);

                if (t.mipmaps.Count > 1 && DDS)
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, t.mipmaps.Count);
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

                    for (int i = 0; i < t.mipmaps.Count; i++)
                    {
                        GL.CompressedTexImage2D <byte>(TextureTarget.Texture2D, i, t.type,
                                                       t.Width / (int)Math.Pow(2, i), t.Height / (int)Math.Pow(2, i), 0, t.mipmaps[i].Length, t.mipmaps[i]);
                    }
                }
                else
                {
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                }

                //Debug.WriteLine(GL.GetError());
            }
            else
            {
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, t.mipmaps.Count);
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

                GL.TexImage2D <byte>(TextureTarget.Texture2D, 0, t.type, t.Width, t.Height, 0,
                                     t.utype, t.PixelType, t.mipmaps[0]);

                /* for (int i = 0; i < t.mipmaps.Count; i++)
                 *   GL.TexImage2D<byte>(TextureTarget.Texture2D, i, t.type, t.width, t.height, 0,
                 *   t.utype, t.PixelType, t.mipmaps[i]);*/

                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
            }

            //GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            return(texID);
        }
Esempio n. 23
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                NutTexture texture = (NutTexture)(textureListBox.SelectedItem);

                if (texture.type == PixelInternalFormat.Rgba)
                {
                    ofd.Filter = "Portable Networks Graphic (.png)|*.png|" +
                                 "All files(*.*)|*.*";
                }
                else
                {
                    ofd.Filter = "Direct Draw Surface (.dds)|*.dds|" +
                                 "All files(*.*)|*.*";
                }

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Edited = true;
                    NutTexture newTexture = null;
                    if (ofd.FileName.EndsWith(".dds") && NUT != null)
                    {
                        DDS dds = new DDS(new FileData(ofd.FileName));
                        newTexture = dds.toNUT_Texture();
                    }

                    if (ofd.FileName.EndsWith(".png") && NUT != null)
                    {
                        newTexture = fromPNG(ofd.FileName, 1);
                    }

                    texture.Height  = newTexture.Height;
                    texture.Width   = newTexture.Width;
                    texture.type    = newTexture.type;
                    texture.mipmaps = newTexture.mipmaps;
                    texture.utype   = newTexture.utype;

                    if (newTexture == null)
                    {
                        return;
                    }

                    GL.DeleteTexture(NUT.draw[texture.HASHID]);
                    NUT.draw.Remove(texture.HASHID);
                    NUT.draw.Add(texture.HASHID, NUT.loadImage(texture));

                    FillForm();
                }
            }
        }
Esempio n. 24
0
        public bool getTextureByID(int hash, out NutTexture suc)
        {
            suc = null;
            foreach (NutTexture t in Nodes)
            {
                if (t.HashId == hash)
                {
                    suc = t;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 25
0
        private void SetMipMapText(NutTexture tex)
        {
            // Display the total mip maps.
            mipmapGroupBox.Text = "Mipmaps";
            mipLevelLabel.Text  = "Mip Level";

            mipLevelTrackBar.Maximum = tex.surfaces[0].mipmaps.Count - 1;
            int newMipLevel = Math.Min(currentMipLevel, mipLevelTrackBar.Maximum);

            mipLevelTrackBar.Value = newMipLevel;

            minMipLevelLabel.Text = "1";
            maxMipLevelLabel.Text = "Total:" + tex.surfaces[0].mipmaps.Count + "";
        }
Esempio n. 26
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentNut == null || textureListBox.SelectedItem == null)
            {
                return;
            }
            using (var ofd = new OpenFileDialog())
            {
                NutTexture texture = (NutTexture)(textureListBox.SelectedItem);

                ofd.Filter = "Supported Formats|*.dds;*.png|" +
                             "DirectDraw Surface (.dds)|*.dds|" +
                             "Portable Network Graphics (.png)|*.png|" +
                             "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    NutTexture newTexture = null;
                    string     extension  = Path.GetExtension(ofd.FileName).ToLowerInvariant();
                    if (extension == ".dds")
                    {
                        DDS dds = new DDS(new FileData(ofd.FileName));
                        newTexture = dds.ToNutTexture();
                    }
                    else if (extension == ".png")
                    {
                        newTexture = fromPNG(ofd.FileName, 1);
                    }
                    else
                    {
                        return;
                    }

                    texture.Height = newTexture.Height;
                    texture.Width  = newTexture.Width;
                    texture.pixelInternalFormat = newTexture.pixelInternalFormat;
                    texture.surfaces            = newTexture.surfaces;
                    texture.pixelFormat         = newTexture.pixelFormat;

                    Edited = true;

                    //GL.DeleteTexture(NUT.glTexByHashId[texture.HASHID]);
                    currentNut.glTexByHashId.Remove(texture.HashId);
                    currentNut.glTexByHashId.Add(texture.HashId, NUT.CreateTexture2D(texture));

                    FillForm();
                }
            }
        }
Esempio n. 27
0
        private void RenderTextureToPng(NutTexture nutTexture, string outputPath, bool r = true, bool g = true, bool b = true, bool a = false)
        {
            if (OpenTKSharedResources.SetupStatus != OpenTKSharedResources.SharedResourceStatus.Initialized || glControl1 == null)
            {
                return;
            }

            // Load the OpenGL texture and export the image data.
            Texture2D texture = (Texture2D)currentNut.glTexByHashId[nutTexture.HashId];

            using (Bitmap image = Rendering.TextureToBitmap.RenderBitmap(texture, r, g, b, a))
            {
                image.Save(outputPath);
            }
        }
Esempio n. 28
0
        private static void LoadMipMapsCompressed(NutTexture t)
        {
            for (int i = 0; i < t.surfaces.Count; ++i)
            {
                // Generate the mip maps.
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, t.surfaces[i].mipmaps.Count);
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

                // Initialize the data for each level.
                for (int j = 0; j < t.surfaces[i].mipmaps.Count; ++j)
                {
                    GL.CompressedTexImage2D <byte>(TextureTarget.Texture2D, j, t.type,
                                                   t.Width / (int)Math.Pow(2, j), t.Height / (int)Math.Pow(2, j), 0, t.surfaces[i].mipmaps[j].Length, t.surfaces[i].mipmaps[j]);
                }
            }
        }
Esempio n. 29
0
 public static TextureCubeMap CreateTextureCubeMap(NutTexture t)
 {
     if (TextureFormatTools.IsCompressed(t.pixelInternalFormat))
     {
         // Compressed cubemap with mipmaps.
         return(new TextureCubeMap(t.Width, (InternalFormat)t.pixelInternalFormat,
                                   t.surfaces[0].mipmaps, t.surfaces[1].mipmaps, t.surfaces[2].mipmaps,
                                   t.surfaces[3].mipmaps, t.surfaces[4].mipmaps, t.surfaces[5].mipmaps));
     }
     else
     {
         // Uncompressed cube map with no mipmaps.
         return(new TextureCubeMap(t.Width, new TextureFormatUncompressed(t.pixelInternalFormat, t.pixelFormat, t.pixelType),
                                   t.surfaces[0].mipmaps[0], t.surfaces[1].mipmaps[0], t.surfaces[2].mipmaps[0],
                                   t.surfaces[3].mipmaps[0], t.surfaces[4].mipmaps[0], t.surfaces[5].mipmaps[0]));
     }
 }
Esempio n. 30
0
        private void mipLevelTrackBar_Scroll(object sender, EventArgs e)
        {
            NutTexture tex = ((NutTexture)textureListBox.SelectedItem);

            if (tex.surfaces.Count == 6)
            {
                // Create a new texture for the selected surface at the first mip level.
                currentMipLevel = 0;
                SetCurrentCubeMapFaceLabel(mipLevelTrackBar.Value);
                textureToRender = NUT.CreateTexture2D(tex, mipLevelTrackBar.Value);
            }
            else
            {
                // Regular texture.
                currentMipLevel = mipLevelTrackBar.Value;
            }

            glControl1.Invalidate();
        }