コード例 #1
0
ファイル: renderUtil.cs プロジェクト: an87li/gameEngine
        public static Texture getEmbeddedTexture(string resourceName)
        {
            Assembly[] asses = AppDomain.CurrentDomain.GetAssemblies();
            foreach (Assembly ass in asses)
            {
                string[] resources = ass.GetManifestResourceNames();
                foreach (string s in resources)
                {
                    if (s == resourceName)
                    {
                        Stream stream = ass.GetManifestResourceStream(resourceName);
                        if (stream == null)
                        {
                            System.Console.WriteLine("Cannot find embedded resource {0}", resourceName);
                            return(null);
                        }

                        Texture t = new Texture();
                        t.loadFromStream(stream);
                        return(t);
                    }
                }
            }

            Warn.print("Failed to find embedded texture {0}", resourceName);
            return(null);
        }
コード例 #2
0
ファイル: renderUtil.cs プロジェクト: bholcomb/gameEngine
        public static Texture getEmbeddedTexture(string resourceName)
        {
            Stream stream = Embedded.getStream(resourceName);

            if (stream != null)
            {
                Texture t = new Texture();
                t.loadFromStream(stream);
                return(t);
            }

            Warn.print("Failed to find embedded texture {0}", resourceName);
            return(null);
        }
コード例 #3
0
        protected Texture getTexture(string filepath)
        {
            Texture t = null;

            if (filepath[0] == '*') //this is an embedded texture
            {
                string textureIndexStr = filepath.TrimStart('*');
                int    index           = Convert.ToInt32(textureIndexStr);
                if (index >= myScene.TextureCount)
                {
                    Warn.print("texture index({0}) is out of range({1})", index, myScene.TextureCount);
                    return(null);
                }

                EmbeddedTexture texData = myScene.Textures[index];
                if (texData != null)
                {
                    if (texData.IsCompressed)
                    {
                        byte[] bytes = texData.CompressedData;
                        switch (texData.CompressedFormatHint)
                        {
                        case "png": //fallthrough
                        case "jpg":
                            t = new Texture();
                            Stream stream = new MemoryStream(texData.CompressedData, false);
                            t.loadFromStream(stream);
                            break;

                        case "dds":
                            Warn.print("DDS files not supported yet");
                            break;

                        default:
                            Warn.print("Unkown compressed file format {0}", texData.CompressedFormatHint);
                            break;
                        }
                    }
                    else
                    {
                        byte[] bytes = new byte[texData.Width * texData.Height * 4];
                        for (int i = 0; i < texData.Height; i++)
                        {
                            for (int j = 0; i < texData.Width; i++)
                            {
                                bytes[j + (i * texData.Width) + 0] = texData.NonCompressedData[j + (i * texData.Width)].R;
                                bytes[j + (i * texData.Width) + 1] = texData.NonCompressedData[j + (i * texData.Width)].G;
                                bytes[j + (i * texData.Width) + 2] = texData.NonCompressedData[j + (i * texData.Width)].B;
                                bytes[j + (i * texData.Width) + 3] = texData.NonCompressedData[j + (i * texData.Width)].A;
                            }
                        }

                        Texture.PixelData pData = new Texture.PixelData();
                        pData.data        = bytes;
                        pData.dataType    = PixelType.Byte;
                        pData.pixelFormat = PixelFormat.Rgba;
                        t = new Texture(texData.Width, texData.Height, PixelInternalFormat.Rgba8, pData, true);
                    }
                }
            }
            else //just a path name
            {
                string            textureName = filepath.TrimStart('/');
                TextureDescriptor td          = new TextureDescriptor(Path.Combine(myRootPath, textureName), true);
                t = myResourceManager.getResource(td) as Texture;

                if (t == null)
                {
                    Warn.print("Failed to load texture {0}", filepath);
                }
            }

            return(t);
        }