private static ITexture CreaterCheckerTex() { var black = Color4.Black; var white = Color4.White; var data = new Color4[2, 2]; data[0, 0] = black; data[0, 1] = white; data[1, 0] = white; data[1, 1] = black; var tex = new Texture2dGL(); tex.LoadPixels(data, 4, true); tex.Filter = TextureFilterMode.Nearest; return(tex); }
public ITexture2D GetIBLTexture(string path) { FreeImageAPI.FREE_IMAGE_FORMAT type = FreeImageAPI.FreeImage.GetFileType(path, 0); FreeImageAPI.FIBITMAP bitmap = FreeImageAPI.FreeImage.Load(type, path, FreeImageAPI.FREE_IMAGE_LOAD_FLAGS.DEFAULT); //FreeImageAPI.FIBITMAP convert = FreeImageAPI.FreeImage.ToneMapping(bitmap, FreeImageAPI.FREE_IMAGE_TMO.FITMO_DRAGO03, 0, 0); FreeImageAPI.FIBITMAP convert = FreeImageAPI.FreeImage.ToneMapping(bitmap, FreeImageAPI.FREE_IMAGE_TMO.FITMO_REINHARD05, 0, 0); if (bitmap.IsNull) { return(null); } uint width = FreeImageAPI.FreeImage.GetWidth(convert); uint height = FreeImageAPI.FreeImage.GetHeight(convert); int channelNo = 3; byte[] imgData = new byte[width * height * channelNo]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int idx = i * (int)width + j; FreeImageAPI.RGBQUAD color = new FreeImageAPI.RGBQUAD(); int byteIdx = idx * channelNo; byteIdx -= 1; bool pSuccess = FreeImageAPI.FreeImage.GetPixelColor(convert, (uint)j, (uint)i, out color); Color nColor = color.Color; imgData[byteIdx + 1] = color.rgbRed; imgData[byteIdx + 2] = color.rgbGreen; imgData[byteIdx + 3] = color.rgbBlue; if (!pSuccess) { return(null); } } } Texture2dGL text = Texture2dGL.Create((int)width, (int)height); IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(imgData, 0); text.LoadPixels(ptr, (int)width, (int)height, OpenTK.Graphics.OpenGL4.PixelInternalFormat.Rgb8, OpenTK.Graphics.OpenGL4.PixelFormat.Rgb, OpenTK.Graphics.OpenGL4.PixelType.UnsignedByte); return(text); }
private ITexture getTextureFromResource(Bitmap bitmap) { var texture = new Texture2dGL() { Filter = TextureFilterMode.Mipmap }; texture.Activate(); //todo: 16bit channels using (Bitmap bmp = new Bitmap(bitmap)) { bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), SysDraw.ImageLockMode.ReadOnly, bmp.PixelFormat); var internalFormat = SelectInternalPixelFormat(bmp.PixelFormat); var inputPixelFormat = SelectPixelFormat(bmp.PixelFormat); texture.LoadPixels(bmpData.Scan0, bmpData.Width, bmpData.Height, internalFormat, inputPixelFormat, PixelType.UnsignedByte); bmp.UnlockBits(bmpData); } texture.Deactivate(); return(texture); }