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.cpp
Go to the documentation of this file.
1 #include "in_kb.h"
2 #include "vs_globals.h"
3 #include "vsimage.h"
4 #ifndef __APPLE__
5 #include <GL/glut.h>
6 #else
7 #include <GLUT/glut.h>
8 #endif
9 
10 using namespace VSFileSystem;
11 
12 void Screenshot( const KBData&, KBSTATE state )
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 }
40