Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Johnny Depp is my idol

All ways to take a screenshot from OpenGl front/backbuffer?

This topic is 5244 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need in my project a way to take shot from screen with opengl32. I imagine that taking a shot from buffer shown in screen (frontbuffer?) is impossible at least at reasonable speeds. So which functions and params I could use to take screenshot from screen? I''d like to get many ways so that I could experiment with them. Thanks in advance.

Share this post

Link to post
Share on other sites
Do a search on the OpenGL forum - search for "screenshot". This has been discusses many times, I''m sure you''ll find some useful info there.

Share this post

Link to post
Share on other sites
Try the code below
void Engine::CaptureScreen()
static int captures=0;
char filename[20];

sprintf( filename, "Data/screen%.2d.bmp", captures );


char *image = new char[Width*Height*3];
FILE *file = fopen( filename, "wb");

if( image!=NULL )
if( file!=NULL )
glReadPixels( 0, 0, Width, Height, GL_BGR_EXT, GL_UNSIGNED_BYTE, image );

memset( &bf, 0, sizeof( bf ) );
memset( &bi, 0, sizeof( bi ) );

bf.bfType = ''MB'';
bf.bfSize = sizeof(bf)+sizeof(bi)+Width*Height*3;
bf.bfOffBits = sizeof(bf)+sizeof(bi);
bi.biSize = sizeof(bi);
bi.biWidth = Width;
bi.biHeight = Height;
bi.biPlanes = 1;
bi.biBitCount = 24;
bi.biSizeImage = Width*Height*3;

fwrite( &bf, sizeof(bf), 1, file );
fwrite( &bi, sizeof(bi), 1, file );
fwrite( image, sizeof(unsigned char), Height*Width*3, file );

fclose( file );
delete[] image;

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!