Drawing with openTK, save to file, show on screen

只愿长相守 提交于 2020-12-15 05:24:40

问题


I am drawing multiple images over earh map, I am using perspective correct texturing link on each image.

I want to store rendered image in to file (sorce file is 1280x760, the rendered images is around 160x90 in most cases rotated). Currently I am doing this with GL.ReadPixels

int width = 1920;
int height = 1080;
using (Bitmap bitmap = new Bitmap(width, height))
{
    System.Drawing.Imaging.BitmapData bits = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
    GL.ReadPixels(0, (0, width, height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bits.Scan0);
    bitmap.UnlockBits(bits);
    bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
    bitmap.Save("output.png", System.Drawing.Imaging.ImageFormat.Png);
}

The problem occurs when I move the map, rendered images are not visible anymore on the screen and it looks like that in this case GL.ReadPixels returns empty pixels.

How to get rendered image even if this is not currently rendered on screen?

Extra question, if I use framebuffer the result is the same but using the frame buffer I never see image on the screen, it looks like framebuffer is not drawn on the screen, but GL.ReadPixels can get image out. Which lines of code are needed to draw framebuffer also on the screen?

Any idea?

来源:https://stackoverflow.com/questions/65250801/drawing-with-opentk-save-to-file-show-on-screen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!