Opengl4.0 can be rendered off-screen, that is, to create a Frame cache object (FBO), after binding a frame cache object, all operations on the OP--ENGL will be executed against this frame cache object. In the recent project, you are doing a camera function-reading OpenGL rendered pixels and depositing them into BMP bitmaps. The project uses a combination of Opengl1.0 and Opengl4.3 methods, and the use of the two is relatively independent. When you run a program using the old OpenGL method,Glreadbuffer (Gl_front);//Specifies the cache to readglreadpixels (0, 0, width, height, gl_bgra_ext, Gl_unsigned_byte, (UNSIGNED char*) imageData);can be read into pixels and saved. However, once the Opengl4.3 was used for off-screen rendering, it was found that Glreadbuffer () and Glreadpixels () could no longer be read to pixels, so I did glgeterror () detection for each part using Opengl4.3 code, I found that the part of the code that used Opengl4.3 did not invoke the error, so I couldn't find out where the problem was. Finally, I think it will be OpenGL binding problem, finally found that Opengl4.3 using off-screen rendering after the frame cache is not unbound, that is:Glbindframebuffer (Gl_framebuffer, gl_none);so I checked the www.khronos.org/aboutGlbindframebufferdefinition of:while a Non-zero framebuffer object name was bound, all rendering to the framebuffer (with gldrawarrays and
gldrawelements)
andreading from the framebuffer ( withGlreadpixels, glcopyteximage2d, orglcopytexsubimage2d) Use the images attached to theapplication-created Framebuffer Object rather than the default window-system-provided framebuffer.Application created Framebuffer objects (i.e. those with a Non-zero name) differ from the default Window-system-provid Ed FramebufferIn a few important ways. First, they has modifiable attachment points for a color buffer, a depth buffer, and a stencil buffer to whichframebuffer attachable images may be attached and detached. Second, the size and format of the attached images is controlled entirely within the GL and is not affected by Window-system events, such as pixel format selection, window resizes, and Display Modechanges. Third, when rendering to or reading from a application created Framebuffer object, the pixel ownership test always Succee DS(i.e. they own all their pixels).Fourth, there is no visible color buffer bitplanes, only a single "off-screen" color image attachment, soThere is no sense of front and buffers or swapping.Finally, there is no multisample buffer, so the value of the IMPLEMENTATION-DEPendent State VariablesGL_SAMPLES andGL_SAMPLE_BUFFERSis both zero for application created Framebuffer objects.that is, when you use Glbindframebuffer () for off-screen rendering, OpenGL rendering and reading are through attached texture-to-frameCacheoperation, no longer operates on the default frame cache provided by the Windows system, so we see images that appear on the screenDon'tis a visible color cache bit face (visible color buffer bitplane), but is a "off-screen" color texture ("off-screen"Color image attachment), so the dual cache does not work (even if you call Swapbuffer (), the pixels are not rendered to the front and back caches), so Glreadbuffer (Gl_front), also can not read out pixels. This bug has been around for nearly two weeks, and here mark, to be blunt or not understanding OpenGL, OpenGL's use of personal senseSleep ratiomore obscure and need to be studied well. We hope to help you. The format has been poorly tuned. All right..
Glbindframebuffer () off-screen rendering + dual cache + read OpenGL pixel Glreadpixels ()