Exemple #1
0
        public int RegisterTexture2(TagFileName tfn)
        {
            int  tex_index     = DEFAULT_TEXTURE;
            bool bTextureFound = false;

            //TODO:  use hash table?
            for (tex_index = 0; ((tex_index < MaxElements) && (tex_index < m_LookupCount)); tex_index++)
            {
                if (m_LookupTable[tex_index].name == tfn.RelativePath)
                {
                    bTextureFound = true;
                    break;
                }
            }

            if (bTextureFound == false)
            {
                try
                {
                    H2BitmTag.H2Bitmap bmp = new H2BitmTag.H2Bitmap();
                    if (!bmp.LoadTagBuffer(tfn))
                    {
                        throw new Exception("Could not load bitmap: " + tfn.RelativePath);
                    }
                    bmp.LoadTagData();

                    m_LookupTable[m_LookupCount] = new TEXTURE_LOOKUP_ELEMENT();

                    //TODO: create array of textures
                    m_LookupTable[m_LookupCount].TextureList = new TextureWithFormat[bmp.m_header.Bitmaps.Count];
                    Trace.WriteLine("Loading texture: " + tfn.RelativePath);
                    for (int t = 0; t < bmp.m_header.Bitmaps.Count; t++)
                    {
                        m_LookupTable[m_LookupCount].TextureList[t] = new TextureWithFormat();

                        MemoryStream stream = new MemoryStream();
                        BinaryWriter bw     = new BinaryWriter(stream);
                        // Write the DDS header
                        H2BitmTag.DDSWriter d = new H2BitmTag.DDSWriter();
                        d.WriteHeader(ref bw, ref bmp.m_images[t]);
                        // Now copy the binary data to the stream
                        bw.Write(bmp.m_images[t].DDSData);
                        stream.Seek(0, SeekOrigin.Begin);

                        m_LookupTable[m_LookupCount].TextureList[t].texture = TextureLoader.FromStream(MdxRender.Dev, stream);
                    }

                    tex_index = m_LookupCount;
                    m_LookupCount++;
                }
                catch (Exception e)
                {
                    Trace.WriteLine("TextureManager Exception: " + e.Message);
                }
            }

            return(tex_index);
        }
Exemple #2
0
        public TextureManager()
        {
            //load default pink texture
            for (int i = 0; i < 18; i++)
            {
                m_LookupTable[i]                = new TEXTURE_LOOKUP_ELEMENT();
                m_LookupTable[i].TextureList    = new TextureWithFormat[1];
                m_LookupTable[i].TextureList[0] = new TextureWithFormat();
            }

            // Load the default texture from the embedded resource
            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.default.dds"));
            m_LookupCount++;

            //load the "direction textures"
            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.nx.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.ny.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.nz.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.px.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.py.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.pz.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.nav_arrow.dds"));
            NavArrowIndex = m_LookupCount;
            m_LookupCount++;

            #region Billboard Textures
            //It is important to load these textures in the same order as the BillboardModel
            //enumeration so they match up properly
            BillboardBaseIndex = m_LookupCount;
            //public enum BillboardModel{CTF_Flag,CTF_Vehicle,Oddball,Race_Track, Race_Vehicle, Vegas_Bank, Teleport_From, Teleport_To, KOH};

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.ctf.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.ctf_vehicle.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.oddball.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.race.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.race_vehicle.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.vegas_bank.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.teleporter_enter.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.teleporter_exit.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.koh.dds"));
            m_LookupCount++;

            m_LookupTable[m_LookupCount].TextureList[0].texture = TextureLoader.FromStream(
                MdxRender.Dev, Assembly.GetExecutingAssembly().GetManifestResourceStream("Core.Render.Resources.sound_scenery.dds"));
            m_LookupCount++;
            #endregion
        }
Exemple #3
0
        public int RegisterTexture3(string texture_name, ref byte[] ColorMaps, ref ushort[] LightMapIndex, ref ushort[] ColorMapIndex, ref H2BitmTag.H2Bitmap bmp)
        {
            int  tex_index     = DEFAULT_TEXTURE;
            bool bTextureFound = false;

            //TODO:  use hash table?
            for (tex_index = 0; ((tex_index < MaxElements) && (tex_index < m_LookupCount)); tex_index++)
            {
                if (m_LookupTable[tex_index].name == texture_name)
                {
                    bTextureFound = true;
                    break;
                }
            }

            if (bTextureFound == false)
            {
                //try
                //{

                m_LookupTable[m_LookupCount] = new TEXTURE_LOOKUP_ELEMENT();

                //TODO: create array of textures
                m_LookupTable[m_LookupCount].TextureList = new TextureWithFormat[LightMapIndex.Length];
                byte[] header = new byte[0x80]
                {
                    0x44, 0x44, 0x53, 0x20, 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
                    0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
                    0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
                    0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x10, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                };

                for (int t = 0; t < LightMapIndex.Length; t++)
                {
                    if (LightMapIndex[t] != 0xffff)
                    {
                        int          ColorsOffset = ColorMapIndex[t] * 0x400;
                        MemoryStream stream       = new MemoryStream();
                        BinaryWriter bw           = new BinaryWriter(stream);
                        //if (LightMapIndex[t] != 0xffff)
                        //{
                        byte[] tmpBuf = new byte[bmp.m_images[LightMapIndex[t]].DDSData.Length * 4];
                        // Write the DDS header
                        PutUInt(ref header, 12, (uint)bmp.m_images[LightMapIndex[t]].height);
                        PutUInt(ref header, 16, (uint)bmp.m_images[LightMapIndex[t]].width);

                        bw.Seek(0, SeekOrigin.Begin);
                        bw.Write(header);

                        for (int cpo = 0; cpo < bmp.m_images[LightMapIndex[t]].DDSData.Length - 4; cpo++)
                        {
                            //SwapInt(ref ColorMaps,(uint)cpo);
                            byte index = bmp.m_images[LightMapIndex[t]].DDSData[cpo];

                            tmpBuf[4 * cpo]     = ColorMaps[ColorsOffset + index * 4];
                            tmpBuf[4 * cpo + 1] = ColorMaps[ColorsOffset + index * 4 + 1];
                            tmpBuf[4 * cpo + 2] = ColorMaps[ColorsOffset + index * 4 + 2];
                            tmpBuf[4 * cpo + 3] = ColorMaps[ColorsOffset + index * 4 + 3];
                        }                                  //ColorMaps.CopyTo(tmpBuf,);
                        bw.Write(tmpBuf, 0, tmpBuf.Length);
                        stream.Seek(0, SeekOrigin.Begin);

                        m_LookupTable[m_LookupCount].TextureList[t]         = new TextureWithFormat();
                        m_LookupTable[m_LookupCount].TextureList[t].texture = TextureLoader.FromStream(MdxRender.Dev, stream);
                    }
                }

                tex_index = m_LookupCount;
                m_LookupCount++;
            }
            //catch(Exception e)
            //{
            //	Trace.WriteLine("TextureManager Exception: " + e.Message);
            //}
            //}
            return(tex_index);
        }
Exemple #4
0
        public int RegisterTexture(TagFileName tfn)
        {
            int  tex_index     = DEFAULT_TEXTURE;
            bool bTextureFound = false;

            //TODO:  use hash table?
            for (tex_index = 0; ((tex_index < MaxElements) && (tex_index < m_LookupCount)); tex_index++)
            {
                if (m_LookupTable[tex_index].name == tfn.RelativePath)
                {
                    bTextureFound = true;
                    break;
                }
            }

            if (bTextureFound == false)
            {
                try
                {
                    if (tfn.Exists == false)
                    {
                        Trace.WriteLine("Could not locate texture: " + tfn.RelativePath);
                    }
                    else
                    {
                        H1BitmTag.Bitmap bmp = new H1BitmTag.Bitmap();
                        //H2BitmTag.H2Bitmap bmp = new H2BitmTag.H2Bitmap();

                        if (!bmp.LoadTagBuffer(tfn))
                        {
                            throw new Exception("Could not load bitmap: " + tfn.RelativePath);
                        }
                        bmp.LoadTagData();

                        m_LookupTable[m_LookupCount]      = new TEXTURE_LOOKUP_ELEMENT();
                        m_LookupTable[m_LookupCount].name = tfn.RelativePath;

                        //TODO: create array of textures
                        m_LookupTable[m_LookupCount].TextureList = new TextureWithFormat[bmp.m_header.Bitmaps.Count];
                        Trace.WriteLine("Loading texture: " + tfn.RelativePath);
                        for (int t = 0; t < bmp.m_header.Bitmaps.Count; t++)
                        {
                            m_LookupTable[m_LookupCount].TextureList[t] = new TextureWithFormat();

                            MemoryStream stream = new MemoryStream();
                            BinaryWriter bw     = new BinaryWriter(stream);
                            // Write the DDS header
                            H1BitmTag.DDSWriter d = new H1BitmTag.DDSWriter();
                            d.GenerateAndWriteHeader(ref bw, ref bmp.m_images[t], false);
                            // Now copy the binary data to the stream
                            bw.Write(bmp.m_images[t].DDSData);

//              if(tfn.RelativePath == @"levels\test\bloodgulch\bitmaps\mp lights small strips red.bitmap")
//              {
//                //write data out to dds file
//                FileStream fs = new FileStream(@"c:\temp\test.dds", FileMode.Create);
//                byte[] tmp = new byte[stream.Length];
//                stream.Seek(0, SeekOrigin.Begin);
//                stream.Read(tmp, 0, (int)stream.Length);
//                fs.Write(tmp, 0, (int)stream.Length);
//                fs.Close();
//              }

                            stream.Seek(0, SeekOrigin.Begin);
                            m_LookupTable[m_LookupCount].TextureList[t].texture           = TextureLoader.FromStream(MdxRender.Dev, stream);
                            m_LookupTable[m_LookupCount].TextureList[t].Width             = bmp.m_images[t].width;
                            m_LookupTable[m_LookupCount].TextureList[t].Height            = bmp.m_images[t].height;
                            m_LookupTable[m_LookupCount].TextureList[t].Format            = bmp.m_images[t].format;
                            m_LookupTable[m_LookupCount].TextureList[t].TextureDataLength = bmp.m_images[t].size;
                        }

                        tex_index = m_LookupCount;
                        m_LookupCount++;
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine("TextureManager Exception: " + e.Message);
                }
            }

            return(tex_index);
        }