private static void Update(TextureArray2dGL texArray, IEnumerable <NamedStream> resources) { var count = resources.Count(); if (2 > count) { return; } var bitmaps = from res in resources select new Bitmap(res.Stream); var first = bitmaps.First(); var levels = MathHelper.MipMapLevels(first.Width, first.Height); var internalFormat = TextureLoaderDrawing.SelectInternalPixelFormat(first.PixelFormat); texArray.SetFormat(first.Width, first.Height, count, levels, (SizedInternalFormat)internalFormat); var slice = 0; foreach (var bitmap in bitmaps) { var buffer = bitmap.ToBuffer(); var pixelFormat = TextureLoaderDrawing.SelectPixelFormat(bitmap.PixelFormat); texArray.Load(buffer, slice, pixelFormat, PixelType.UnsignedByte); ++slice; } texArray.Filter = TextureFilterMode.Mipmap; texArray.WrapFunction = TextureWrapFunction.ClampToEdge; }
/// <summary> /// Saves a rectangular area of the current frame buffer into a Bitmap /// </summary> /// <param name="x">start position in x-direction</param> /// <param name="y">start position in y-direction</param> /// <param name="width">size in x-direction</param> /// <param name="height">size in y-direction</param> /// <param name="rotateFlip">If <code>true</code> image will be rotated and flipped, which is correct, /// but this is a time-consuming operation and should be switched off for fast screen capturing. /// <code>true</code> by default.</param> /// <returns>Bitmap</returns> public static Bitmap ToBitmap(int x, int y, int width, int height, bool rotateFlip = true) { var format = System.Drawing.Imaging.PixelFormat.Format24bppRgb; var bmp = new Bitmap(width, height); BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, format); GL.ReadPixels(x, y, width, height, TextureLoaderDrawing.SelectPixelFormat(format), PixelType.UnsignedByte, data.Scan0); bmp.UnlockBits(data); if (rotateFlip) { bmp.RotateFlip(); } return(bmp); }