Beispiel #1
0
        private void _loadBitmap(uint sideID)
        {
            // Import the image
            ImageImporter _importer = new ImageImporter();

            _images[sideID] = _importer.LoadImage(_textures[sideID]);

            // Dispose the importer
            _importer.Dispose();

            // Bind the impi]orted Image
            _images[sideID].Bind();

            // Generate bitmap from image
            Bitmap BitmapImage = _images[sideID].ToBitmap();

            // Must be Format32bppArgb file format, so convert it if it isn't in that format
            BitmapData bitmapData = BitmapImage.LockBits(new System.Drawing.Rectangle(0, 0, BitmapImage.Width, BitmapImage.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(_types[sideID], 0, PixelInternalFormat.Rgba8, BitmapImage.Width, BitmapImage.Height, 0, Core.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0);
            GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, TextureParameter.Linear);
            GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, TextureParameter.Linear);
            GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, TextureParameter.ClampToEdge);
            GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, TextureParameter.ClampToEdge);
            GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, TextureParameter.ClampToEdge);

            // Dispose bitmap (it will not longer be used)
            BitmapImage.UnlockBits(bitmapData);
            BitmapImage.Dispose();

            // Make sure the Image will not be modified from the outside
            _images[sideID].Unbind();
        }
Beispiel #2
0
        /// <summary>
        /// Load an image and use it as a cursor.
        /// </summary>
        /// <param name="image">The path to the image.</param>
        public void FromImage(string image)
        {
            ImageImporter importer = new ImageImporter();
            Image         img      = importer.LoadImage(image);

            importer.Dispose();

            img.Bind();
            _image.Width  = img.Width;
            _image.Height = img.Height;
            _image.Pixels = IL.CopyPixels(0, 0, 0, img.Width, img.Height, 1, DataFormat.BGRA, DataType.UnsignedByte);
            img.Unbind();

            img.Dispose();

            _cursor = GLFW.GLFW.CreateCursor(_image, HotX, HotY);
        }
Beispiel #3
0
        /// <summary>
        /// Load and create a new image.
        /// </summary>
        /// <param name="file">The image file.</param>
        /// <param name="offsetX">The X offset from which pixels will be read.</param>
        /// <param name="offsetY">The Y offset from which pixels will be read.</param>
        /// <param name="offsetZ">The Z offset from which pixels will be read.</param>
        /// <param name="width">The width of the loaded.</param>
        /// <param name="height">The height of the loaded.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="format">The format in which pixels will be read.</param>
        /// <param name="type">The type of data in which pixels will be read.</param>
        public Image(string file, int offsetX = 0, int offsetY = 0, int offsetZ = 0, int width = 0, int height = 0, int depth = 1, DataFormat format = DataFormat.BGRA, DataType type = DataType.UnsignedByte)
        {
            ImageImporter importer = new ImageImporter();

            _i = importer.LoadImage(file);

            // Dispose the importer
            importer.Dispose();

            // Populate fields
            _x = offsetX;
            _y = offsetY;
            _z = offsetZ;
            _d = depth;
            _f = format;
            _t = type;

            // Register this resource as a disposable resource
            ResourcesManager.AddDisposableResource(this);
        }