Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
screenshot.h File Reference

Go to the source code of this file.

Functions

void Screenshot (const KBData &, KBSTATE)
 

Function Documentation

void Screenshot ( const KBData ,
KBSTATE   
)

Definition at line 12 of file screenshot.cpp.

References VSFileSystem::VSFile::Close(), f, g_game, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), PngImage, PRESS, VSFileSystem::TextureFile, XMLSupport::tostring(), game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by GameUniverse::StartDraw().

13 {
14  if (state == PRESS) {
15  GLint xywh[4] = {0, 0, 0, 0};
16  xywh[2] = g_game.x_resolution;
17  xywh[3] = g_game.y_resolution;
18  glGetIntegerv( GL_VIEWPORT, xywh );
19  unsigned char *tmp = (unsigned char*) malloc( xywh[2]*xywh[3]*4*sizeof (unsigned char) );
20  //memset(tmp,0x7f,xywh[2]*xywh[3]*4*sizeof(char));
21  glPixelStorei( GL_PACK_ALIGNMENT, 1 );
22  glPixelStorei( GL_PACK_ROW_LENGTH, xywh[2] );
23  glFinish();
24  glReadPixels( 0, 0, xywh[2], xywh[3], GL_RGB, GL_UNSIGNED_BYTE, tmp );
25  glPixelStorei( GL_PACK_ROW_LENGTH, 0 );
26  ::VSImage image;
28  static int count = 0;
29  std::string filename = "Screenshot"+XMLSupport::tostring( count )+".png";
30  for (;;) {
31  if (f.OpenReadOnly( filename, TextureFile ) <= VSFileSystem::Ok) {
32  f.Close();
33  filename = "Screenshot"+XMLSupport::tostring( ++count )+".png";
34  } else {break; }}
35  char *tmpchar = strdup( filename.c_str() );
36  image.WriteImage( tmpchar, tmp, PngImage, xywh[2], xywh[3], false, 8, TextureFile, true );
37  free( tmpchar );
38  }
39 }