From: Sam Moore Date: Thu, 17 Apr 2014 06:05:34 +0000 (+0800) Subject: Fix Screen::ScreenShot X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=4f0feb025e48aaaa0ffe0226c5135e116d1cb986;p=ipdf%2Fcode.git Fix Screen::ScreenShot Something to do with the OpenGL buffers meant that the rendered BMP wasn't in the buffer before the glReadPixels call. I have no idea why the screenshot worked for the rectangles and not for a texture, but oh well. --- diff --git a/src/main.h b/src/main.h index 6763042..7cfa22c 100644 --- a/src/main.h +++ b/src/main.h @@ -16,8 +16,9 @@ inline void OverlayBMP(Document & doc, const char * input, const char * output, //view.Render(); scr.RenderBMP(input); scr.Present(); - sleep(5); + sleep(1); scr.ScreenShot(output); + sleep(1); } inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f)) diff --git a/src/screen.cpp b/src/screen.cpp index 683da4a..5f32f0d 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -129,13 +129,17 @@ void Screen::ScreenShot(const char * filename) const int w = ViewportWidth(); int h = ViewportHeight(); - unsigned char * pixels = new unsigned char[w*h*3]; + unsigned char * pixels = new unsigned char[w*h*4]; if (pixels == NULL) - Fatal("Failed to allocate %d x %d x 4 = %d pixel array", w, h, w*h*3); + Fatal("Failed to allocate %d x %d x 4 = %d pixel array", w, h, w*h*4); + + + glReadBuffer(GL_FRONT); + glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0,0,w, h, GL_BGRA, GL_UNSIGNED_BYTE, pixels); - SDL_Surface * surf = SDL_CreateRGBSurfaceFrom(pixels, w, h, 8*3, w*3, 0,0,0,0); + SDL_Surface * surf = SDL_CreateRGBSurfaceFrom(pixels, w, h, 8*4, w*4, 0,0,0,0); if (surf == NULL) Fatal("Failed to create SDL_Surface from pixel data - %s", SDL_GetError());