I need to make a “PrintScreen” function im my application.
The thing is that i need it to be done by opengl (not windows printscreen or api functions). In addition, later I will need to save a depth buffer as well.
After drawing some objects on the screen, I want to copy the screen and save it to a file. The easiest way by glReadPixels seems not working. So, I am trying now to use glCopyTexImage2D.
The thing is that I am stuck with obtaing a pointer to a raw texture data.
GLint m_viewport[4];
glGetIntegerv( GL_VIEWPORT, m_viewport );
GLuint texture;
glGenTextures( 1, &texture );
glBindTexture(GL_TEXTURE_2D, texture);
glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,m_viewport[0],
m_viewport[1], m_viewport[2], m_viewport[3],0);
// now when framebuffer is copied, i need to link a
//pointer to a raw texture data:
BYTE *raw_img = ...;
// save using, for example libpng
free(raw_img);
Any suggestions on how to do it?
I wonder is it after all a correct way to do?