Пример #1
0
        public static TextureInformation GetTextureInformation(string filename)
        {
            FileStream FS = null;

            try
            {
                FS = File.OpenRead(filename);
            }
            finally
            {
                if (FS != null)
                {
                    FS.Close();
                }
            }
            TextureInformation TexInfo = new TextureInformation();

            TexInfo.Depth        = Il.ilGetInteger(Il.IL_IMAGE_DEPTH);
            TexInfo.Format       = SurfaceFormat.Color; //TODO: Set properly.
            TexInfo.Height       = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
            TexInfo.imageFormat  = ILimageformat2XNAimageformat(Il.ilGetInteger(Il.IL_IMAGE_FORMAT));
            TexInfo.resourcetype = ResourceType.Texture2D; //TODO: Find out how to detect and set properly.
            TexInfo.Width        = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
            return(TexInfo);
        }
 public void Setup()
 {
     a = new TextureInformation();
     a.Depth = 32;
     a.Format = SurfaceFormat.Bgr444;
     a.Height = 500;
     a.MipLevels = 3;
     a.Width = 400;
 }
 /// <summary>
 /// Loads the model.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="BatchInformations">The batch informations.</param>
 /// <param name="TextureInformations">The texture informations.</param>
 protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
 {
     skinnedModel = factory.GetAnimatedModel(Name);
     ModelBuilderHelper.Extract(factory, out BatchInformations, out TextureInformations, skinnedModel.Model,_diffuseName,_bumpName,_specularName,_glowName,isInternal);
     BoundingSphere sphere = new BoundingSphere();
     foreach (var item in skinnedModel.Model.Meshes)
     {
         sphere = BoundingSphere.CreateMerged(sphere, item.BoundingSphere);
     }
     modelRadius = sphere.Radius;                     
 }
Пример #4
0
        public static Texture FromFile(GraphicsDevice graphicsDevice, string filename, TextureCreationParameters creationParameters)
        {
            TextureInformation texinfo = GetTextureInformation(filename);

            if (creationParameters.Width == 0)
            {
                creationParameters.Width = texinfo.Width;
            }
            if (creationParameters.Height == 0)
            {
                creationParameters.Height = texinfo.Height;
            }
            if (creationParameters.Depth == 0)
            {
                creationParameters.Depth = texinfo.Depth;
            }
            if (texinfo.ResourceType == ResourceType.Texture2D)
            {
                int ImgID;
                Il.ilGenImages(1, out ImgID);
                Il.ilBindImage(ImgID);
                Il.ilLoadImage(filename);
                int       width  = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
                int       height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
                int       depth  = Il.ilGetInteger(Il.IL_IMAGE_DEPTH);
                int       size   = Il.ilGetInteger(Il.IL_IMAGE_SIZE_OF_DATA);
                Texture2D tex    = new Texture2D(graphicsDevice, creationParameters.Width, creationParameters.Height, creationParameters.Depth, TextureUsage.None, SurfaceFormat.Rgb32);

                Gl.glBindTexture(Gl.GL_TEXTURE_2D, tex.textureId);
                Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Il.ilGetInteger(Il.IL_IMAGE_BYTES_PER_PIXEL), creationParameters.Width, creationParameters.Height, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, Il.ilGetData());

                Il.ilBindImage(0);
                return(tex);
            }
            else if (texinfo.ResourceType == ResourceType.Texture3D)
            {
                throw new NotImplementedException();
            }
            else if (texinfo.ResourceType == ResourceType.Texture3DVolume)
            {
                throw new NotImplementedException();
            }                                                                                                       //FIXME: Should we handle this here too?
            else if (texinfo.ResourceType == ResourceType.TextureCube)
            {
                throw new NotImplementedException();
            }
            else
            {
                return(null);
            }
        }
        public void ConstructorTest()
        {
            a = new TextureInformation();
            Assert.AreEqual(a.Depth, 0, "#1");
            Assert.AreEqual(a.Format, (SurfaceFormat)0, "#2");
            Assert.AreEqual(a.Height, 0, "#3");
            Assert.AreEqual(a.ImageFormat, ImageFileFormat.Bmp, "#4");
            Assert.AreEqual(a.MipLevels, 0, "#5");
            Assert.AreEqual(a.ResourceType, (ResourceType)0, "#6");
            Assert.AreEqual(a.Width, 0, "#7");


            a = new TextureInformation(15, 26, 37, 115, SurfaceFormat.Rgba1010102);
            Assert.AreEqual(a.Depth, 37, "#8");
            Assert.AreEqual(a.Format, SurfaceFormat.Rgba1010102, "#9");
            Assert.AreEqual(a.Height, 26, "#10");
            Assert.AreEqual(a.ImageFormat, ImageFileFormat.Jpg, "#11");
            Assert.AreEqual(a.MipLevels, 115, "#12");
            Assert.AreEqual(a.ResourceType, ResourceType.Texture2D, "#13");
            Assert.AreEqual(a.Width, 15, "#14");
        }
 public void EqualsTest()
 {
     TextureInformation b = new TextureInformation();
     Assert.IsFalse(b == a, "#1");
     Assert.IsTrue(b != a, "#2");
     Assert.IsFalse(b.Equals(null), "#3");
     Assert.IsTrue(b.Equals(b), "#4");
     int val = 0;
     Assert.IsFalse(b.Equals(val));
 }
Пример #7
0
 public static TextureInformation GetTextureInformation(string filename) {
     FileStream FS = null;
     try
     {
         FS = File.OpenRead(filename);
     }
     finally
     {
         if (FS != null) FS.Close();
     }
     TextureInformation TexInfo = new TextureInformation();
     TexInfo.Depth = Il.ilGetInteger(Il.IL_IMAGE_DEPTH);
     TexInfo.Format = SurfaceFormat.Color; //TODO: Set properly.
     TexInfo.Height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
     TexInfo.imageFormat = ILimageformat2XNAimageformat(Il.ilGetInteger(Il.IL_IMAGE_FORMAT));
     TexInfo.resourcetype = ResourceType.Texture2D; //TODO: Find out how to detect and set properly.
     TexInfo.Width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
     return TexInfo;
 }