Browse Source

Merge pull request #326 from panchagil/render_to_png

[bug] render_to_png wrong data size

Former-commit-id: cd9f19f65d54ff3d0978f6ff2cda08531c34b7d6
Daniele Panozzo 8 years ago
parent
commit
64f232efc1
1 changed files with 2 additions and 2 deletions
  1. 2 2
      include/igl/png/render_to_png.cpp

+ 2 - 2
include/igl/png/render_to_png.cpp

@@ -17,7 +17,7 @@ IGL_INLINE bool igl::png::render_to_png(
   const bool alpha,
   const bool fast)
 {
-  unsigned char * data = new unsigned char[width*height];
+  unsigned char * data = new unsigned char[4*width*height];
   glReadPixels(
     0,
     0,
@@ -35,7 +35,7 @@ IGL_INLINE bool igl::png::render_to_png(
       data[4*(i+j*width)+3] = 255;
     }
   }
-  bool ret = stbi_write_png(png_file.c_str(), width, height, 4, data, width*sizeof(unsigned char));
+  bool ret = stbi_write_png(png_file.c_str(), width, height, 4, data, 4*width*sizeof(unsigned char));
   delete [] data;
   return ret;
 }