Ejemplo n.º 1
0
        /// <summary>
        /// load a volume from the given raw data file and generates an OpenGL 3D texture from it
        /// </summary>
        /// <returns></returns>
        public static Texture Load()
        {
            var bytes = new byte[XDIM * YDIM * ZDIM];

            // read the volume data file
            using (var file = new System.IO.FileStream(volume_file, System.IO.FileMode.Open))
            {
                file.Read(bytes, 0, bytes.Length);
            }

            // generate OpenGL texture
            var dataProvider = new ArrayDataProvider <byte>(bytes);
            var storage      = new TexImage3D(TexImage3D.Target.Texture3D, GL.GL_RED, 1, 0, XDIM, YDIM, ZDIM, GL.GL_RED, GL.GL_UNSIGNED_BYTE, dataProvider);
            var texture      = new Texture(
                TextureTarget.Texture3D, storage, new MipmapBuilder(),
                new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP),
                new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP),
                new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP),
                new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR_MIPMAP_LINEAR),
                new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR),
                new TexParameteri(TexParameter.PropertyName.TextrueBaseLevel, 0),
                new TexParameteri(TexParameter.PropertyName.TextureMaxLevel, 4));

            texture.Initialize();

            return(texture);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// load a volume from the given raw data file and generates an OpenGL 3D texture from it
        /// </summary>
        /// <returns></returns>
        public static Texture Load(Bitmap image)
        {
            var bytes = new byte[length * length * length];

            if (image.Width != length || image.Height != length)
            {
                image = (Bitmap)image.GetThumbnailImage(length, length, null, IntPtr.Zero);
            }

            image.RotateFlip(RotateFlipType.Rotate180FlipX);
            FillByteArray(bytes, image);

            // generate OpenGL texture
            var dataProvider = new ArrayDataProvider <byte>(bytes);
            var storage      = new TexImage3D(TexImage3D.Target.Texture3D, GL.GL_RED, length, length, length, GL.GL_RED, GL.GL_UNSIGNED_BYTE, dataProvider);
            var texture      = new Texture(storage, new MipmapBuilder(),
                                           new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP),
                                           new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP),
                                           new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP),
                                           new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR_MIPMAP_LINEAR),
                                           new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR),
                                           new TexParameteri(TexParameter.PropertyName.TextrueBaseLevel, 0),
                                           new TexParameteri(TexParameter.PropertyName.TextureMaxLevel, 4));

            texture.Initialize();

            return(texture);
        }