What is the fastest way of taking a screenshot in OpenGL?

Started by
3 comments, last by DarkCybo1 18 years, 8 months ago
GLuint GetPixelBuffer(int x, int y, int w, int h) { unsigned char* pixels = new unsigned char[w * h * 4]; glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); delete [] pixels; return texture; } That's my current method, but it's slow as heck and returns the texture upside down.
Hey babe.
Advertisement
glCopyTexImage2D() is the fastest copy way to do it. No mipmaps though.

If you want it to be fast, use ARB_framebuffer_object extension and do a render to texture (Setup with teximage2D, then attach texture to a framebuffer object with TextureFramebuffer(), bind back the default frame buffer object, and render with texture).
If you ever need to save the screeshot to a file, I think you will need the first one. If you don't, I recommend the anony poster's method.


gluBuild2DMipmaps is a very slow function GSIS_GENERATE_MIPMAP is about 10x quicker
but yeah as the AP saiz FBO is the fastest way
Thanks for the help.
Hey babe.

This topic is closed to new replies.

Advertisement