Exemplo n.º 1
0
        public Texture(string path, string type)
        {
            var asset = AssetLoader.UseElement(path + type);

            //checks if the texture has already been loaded
            if (asset != null)
            {
                Texture tex = (Texture)asset;

                id        = tex.id;
                this.type = type;
                this.path = path;

                Console.WriteLine("Loading from hastable " + path + type);
            }
            else
            {
                this.path = path;
                this.type = type;

                GL.ActiveTexture(TextureUnit.Texture0);
                GL.GenTextures(1, out id);
                GL.BindTexture(TextureTarget.Texture2D, id);


                ImageStreamLoader loader = new ImageStreamLoader();
                using (Stream stream = File.Open(path, FileMode.Open))
                {
                    var image = loader.Load(stream, ColorComponents.RedGreenBlueAlpha);

                    GL.TexImage2D(TextureTarget.Texture2D, 0,
                                  PixelInternalFormat.Rgba
                                  , image.Width, image.Height, 0,
                                  PixelFormat.Rgba, PixelType.UnsignedByte, image.Data);
                }


                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                                (int)TextureMinFilter.LinearMipmapLinear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                                (int)TextureMinFilter.Linear);



                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);


                GL.BindTexture(TextureTarget.Texture2D, 0);

                Console.WriteLine("Loading into hashable " + path + type);

                AssetLoader.AddElement(path + type, this);
            }
        }
Exemplo n.º 2
0
        // Loads BMP using StbSharp. This allows us to load BMP files containing BITMAPV4HEADER and BITMAPV5HEADER
        // structures, which FreeImage does not support.
        TextureContent LoadImage(string filename)
        {
            var output = new Texture2DContent {
                Identity = new ContentIdentity(filename)
            };

            ImageResult result;

            using (var stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var imageLoader = new ImageStreamLoader();
                result = imageLoader.Load(stream, ColorComponents.RedGreenBlueAlpha);
            }

            var face = new PixelBitmapContent <Color>(result.Width, result.Height);

            face.SetPixelData(result.Data);
            output.Faces[0].Add(face);

            return(output);
        }