Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2004-10-24 14:42:31 +0400
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2004-10-24 14:42:31 +0400
commit6424bf6eb02345cc4e8db0951edba97993dce301 (patch)
treeb4da6c1e54ee8be5a76ac115db6dc5cd5ba3bfe1 /source/gameengine
parent070d01dd68e76180807111f9e5680d3b2a1f68df (diff)
Fix makeScreenshot for blenderplayer
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/GamePlayer/common/GPC_Canvas.cpp119
-rw-r--r--source/gameengine/GamePlayer/common/GPC_Canvas.h5
2 files changed, 120 insertions, 4 deletions
diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.cpp b/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
index 61f2603e1b2..7648e6a5245 100644
--- a/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
+++ b/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
@@ -38,6 +38,8 @@
#include <windows.h>
#endif
+#include "png.h"
+
#include "RAS_IPolygonMaterial.h"
#include "GPC_Canvas.h"
@@ -372,3 +374,120 @@ SetOrthoProjection(
::glMatrixMode(GL_TEXTURE);
::glLoadIdentity();
}
+
+ void
+GPC_Canvas::
+MakeScreenShot(
+ const char* filename
+){
+ png_structp png_ptr;
+ png_infop info_ptr;
+ unsigned char *pixels = 0;
+ png_bytepp row_pointers = 0;
+ int i, bytesperpixel = 3, color_type = PNG_COLOR_TYPE_RGB;
+ FILE *fp = 0;
+
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (!png_ptr)
+ {
+ std::cout << "Cannot png_create_write_struct." << std::endl;
+ return;
+ }
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ std::cout << "Cannot png_create_info_struct." << std::endl;
+ return;
+ }
+
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ delete [] pixels;
+ delete [] row_pointers;
+ // printf("Aborting\n");
+ if (fp) {
+ fflush(fp);
+ fclose(fp);
+ }
+ return;
+ }
+
+ // copy image data
+
+ pixels = new unsigned char[GetWidth() * GetHeight() * bytesperpixel * sizeof(unsigned char)];
+ if (!pixels) {
+ std::cout << "Cannot allocate pixels array" << std::endl;
+ return;
+ }
+
+ glReadPixels(0, 0, GetWidth(), GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, pixels);
+
+ fp = fopen(filename, "wb");
+ if (!fp)
+ {
+ std::cout << "Couldn't open " << filename << " for writing." << std::endl;
+ longjmp(png_jmpbuf(png_ptr), 1);
+ }
+
+ png_init_io(png_ptr, fp);
+
+ /*
+ png_set_filter(png_ptr, 0,
+ PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
+ PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
+ PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
+ PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
+ PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
+ PNG_ALL_FILTERS);
+
+ png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
+ */
+
+ // png image settings
+ png_set_IHDR(png_ptr,
+ info_ptr,
+ GetWidth(),
+ GetHeight(),
+ 8,
+ color_type,
+ PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
+
+ // write the file header information
+ png_write_info(png_ptr, info_ptr);
+
+ // allocate memory for an array of row-pointers
+ row_pointers = new (png_bytep) [(GetHeight() * sizeof(png_bytep))];
+ if (!row_pointers)
+ {
+ std::cout << "Cannot allocate row-pointers array" << std::endl;
+ longjmp(png_jmpbuf(png_ptr), 1);
+ }
+
+ // set the individual row-pointers to point at the correct offsets
+ for (i = 0; i < GetHeight(); i++) {
+ row_pointers[GetHeight()-1-i] = (png_bytep)
+ ((unsigned char *)pixels + (i * GetWidth()) * bytesperpixel * sizeof(unsigned char));
+ }
+
+ // write out the entire image data in one call
+ png_write_image(png_ptr, row_pointers);
+
+ // write the additional chunks to the PNG file (not really needed)
+ png_write_end(png_ptr, info_ptr);
+
+ // clean up
+ delete [] (pixels);
+ delete [] (row_pointers);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+ if (fp)
+ {
+ fflush(fp);
+ fclose(fp);
+ }
+}
+
diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.h b/source/gameengine/GamePlayer/common/GPC_Canvas.h
index d406871d970..42e2d882e9a 100644
--- a/source/gameengine/GamePlayer/common/GPC_Canvas.h
+++ b/source/gameengine/GamePlayer/common/GPC_Canvas.h
@@ -170,10 +170,7 @@ public:
// not yet
}
- void MakeScreenShot(const char* filename)
- {
- // not yet
- }
+ virtual void MakeScreenShot(const char* filename);
void ClearBuffer(int type);