Revision: 6659
http://playerstage.svn.sourceforge.net/playerstage/?rev=6659&view=rev
Author: rtv
Date: 2008-06-20 17:23:00 -0700 (Fri, 20 Jun 2008)
Log Message:
-----------
added rough screenshot capability
Modified Paths:
--------------
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/worlds/fasr.world
Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-20 23:40:51 UTC (rev 6658)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-21 00:23:00 UTC (rev 6659)
@@ -7,7 +7,9 @@
#include "stage_internal.hh"
#include "texture_manager.hh"
#include "replace.h"
+
#include <string>
+#include <png.h>
using namespace Stg;
@@ -592,8 +594,65 @@
glMatrixMode (GL_MODELVIEW);
}
+
+ if( 0 )
+ Screenshot();
}
+
+void StgCanvas::Screenshot()
+{
+ GLint viewport[4];
+ glGetIntegerv(GL_VIEWPORT,viewport);
+
+ int width = viewport[2] - viewport[0];
+ int height = viewport[3] - viewport[1];
+
+ int depth = 3; // RGB
+
+ uint8_t* pixels= new uint8_t[ width * height * depth ];
+
+ glFlush(); // make sure the drawing is done
+ // read the pixels from the screen
+ glReadPixels( viewport[0], viewport[1], width, height, GL_RGB,
GL_UNSIGNED_BYTE, pixels );
+
+ static uint32_t count = 0;
+ char filename[64];
+ snprintf( filename, 63, "stage-%d.png", count++ );
+
+ FILE *fp = fopen( filename, "wb" );
+ if( fp == NULL )
+ {
+ PRINT_ERR1( "Unable to open %s", filename );
+ }
+
+ // write png header information
+ png_structp pp = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
+ png_infop info = png_create_info_struct(pp);
+ png_init_io(pp, fp);
+ png_set_compression_level(pp, Z_DEFAULT_COMPRESSION);
+ png_set_IHDR( pp, info,
+ width, height, 8,
+ PNG_COLOR_TYPE_RGB,
+ PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
+ png_write_info(pp, info);
+
+ // write pixels in reverse row order
+ for( int y=height-1; y >= 0; y-- )
+ png_write_row( pp, pixels + 3*y*width );
+
+ png_write_end(pp, info);
+ png_destroy_write_struct(&pp, 0);
+ fclose(fp);
+
+ printf( "Saved %s\n", filename );
+
+ delete [] pixels;
+}
+
+
void StgCanvas::draw()
{
static bool loaded_texture = false;
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2008-06-20 23:40:51 UTC (rev 6658)
+++ code/stage/trunk/libstage/stage.hh 2008-06-21 00:23:00 UTC (rev 6659)
@@ -1953,6 +1953,8 @@
bool graphics;
StgWorldGui* world;
+ void Screenshot();
+
void FixViewport(int W,int H);
//robot_camera = true
virtual void renderFrame( bool robot_camera = false );
Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world 2008-06-20 23:40:51 UTC (rev 6658)
+++ code/stage/trunk/worlds/fasr.world 2008-06-21 00:23:00 UTC (rev 6659)
@@ -15,7 +15,7 @@
resolution 0.02
interval_sim 100 # simulation timestep in milliseconds
-interval_real 0 # real-time interval between simulation updates in
milliseconds
+interval_real 10 # real-time interval between simulation updates in
milliseconds
paused 1
# configure the GUI window
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit