In this code, the InitGL and UpdateGL used to initialize program and VAO data, as well as the DrawElements section, are the same as what I wrote in GLWpfControl's OnRender(). Here, I want to achieve off screen rendering by binding my own framebuffer to OffScreenRender(), but this framebuffer does not work, when I read by ReadPixels from this buffer, all data in pixels is 0. I want to save the content rendered in GLWpfControl to an image through off screen rendering. What should I do?
There could be a lot of reasons why this code isn't working. Most likely it has nothing to do with GLWpfControl and more to do with correct OpenGL usage.
Some common issues are:
The framebuffer is not complete.
Nothing is being drawn to the framebuffer (check that you draw commands actually draws something to the framebuffer).
GL.ReadPixels has some weird stuff going on with pixel packing settings that can mess things up.
You can also try just clearing the framebuffer to a solid color and see if you can read that color back, if you can't it's probably got to do with reading the pixels.
I wrote a piece of code in a GLWpfControl ,Like below, but it doesn't work:
In this code, the InitGL and UpdateGL used to initialize program and VAO data, as well as the DrawElements section, are the same as what I wrote in GLWpfControl's OnRender(). Here, I want to achieve off screen rendering by binding my own framebuffer to OffScreenRender(), but this framebuffer does not work, when I read by ReadPixels from this buffer, all data in pixels is 0. I want to save the content rendered in GLWpfControl to an image through off screen rendering. What should I do?