public void Load() { Stream imageStreamSource = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); PngBitmapDecoder decoder = new PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); var bitmapSource = decoder.Frames[0]; var bitsPerPixel = bitmapSource.Format.BitsPerPixel; this.format = BppToPixelFormat(bitsPerPixel); this.bitmap = BitmapFromSource(bitmapSource); this.HeightInPixels = bitmapSource.PixelHeight; this.WidthInPixels = bitmapSource.PixelWidth; this.Loaded = true; }
public void SetTexturePixels(ulong texture, byte[] pixels, int pitch, PixelFormat format) { // Convert from the graphics API independent pixel format to the OpenGL specific one. OpenGL.PixelFormat openglformat = 0; switch (format) { case PixelFormat.RGBA: openglformat = OpenGL.PixelFormat.Rgba; break; case PixelFormat.BGRA: openglformat = OpenGL.PixelFormat.Bgra; break; } Gl.BindTexture(TextureTarget.Texture2d, (uint)texture); // Upload the new pixel data to VRAM. Gl.TexImage2D(TextureTarget.Texture2d, 0, InternalFormat.Rgba8, pitch, (pixels.Length >> 2) / pitch, 0, openglformat, PixelType.UnsignedByte, pixels); }
public void SubImage(IntPtr Pixels, int X, int Y, int Z, int W, int H, int D, GLPixelFormat PFormat = GLPixelFormat.Rgba, PixelType PType = PixelType.UnsignedByte, int Level = 0) { if (Z == 0 && D == 0) { #if DEBUG if (IsCubeMap) { throw new Exception("Invalid Z/D parameter for cubemap"); } #endif Gl.TextureSubImage2D(ID, Level, X, Y, W, H, PFormat, PType, Pixels); } else { Gl.TextureSubImage3D(ID, Level, X, Y, Z, W, H, D, PFormat, PType, Pixels); } if (MipLevels > 1) { GenerateMipmap(); } }