From 7056d29c0fd58ee61b31db64a23f1cb40c91799f Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sat, 3 Aug 2013 16:56:18 +0700 Subject: [PATCH] Fix screen shot capture. --- GLideN64.cpp | 2 +- OpenGL.cpp | 22 ++++++++++------------ OpenGL.h | 1 + VI.cpp | 5 +++++ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/GLideN64.cpp b/GLideN64.cpp index 65dff885..78ca2141 100644 --- a/GLideN64.cpp +++ b/GLideN64.cpp @@ -79,7 +79,7 @@ EXPORT void CALL CaptureScreen ( char * Directory ) WaitForSingleObject( RSP.threadFinished, INFINITE ); } #else - OGL_SaveScreenshot(); + OGL.captureScreen = true; #endif } diff --git a/OpenGL.cpp b/OpenGL.cpp index 1e8c9d4c..d508a938 100644 --- a/OpenGL.cpp +++ b/OpenGL.cpp @@ -532,6 +532,7 @@ bool OGL_Start() gSP.changed = gDP.changed = 0xFFFFFFFF; OGL_UpdateScale(); + OGL.captureScreen = false; return TRUE; } @@ -1171,9 +1172,11 @@ void OGL_SaveScreenshot() char *pixelData = (char*)malloc( OGL.width * OGL.height * 3 ); + GLint oldMode; + glGetIntegerv( GL_READ_BUFFER, &oldMode ); glReadBuffer( GL_FRONT ); glReadPixels( 0, OGL.heightOffset, OGL.width, OGL.height, GL_BGR_EXT, GL_UNSIGNED_BYTE, pixelData ); - glReadBuffer( GL_BACK ); + glReadBuffer( oldMode ); infoHeader.biSize = sizeof( BITMAPINFOHEADER ); infoHeader.biWidth = OGL.width; @@ -1208,14 +1211,14 @@ void OGL_SaveScreenshot() hBitmapFile = CreateFile( filename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL ); } while (hBitmapFile == INVALID_HANDLE_VALUE); - + DWORD written; WriteFile( hBitmapFile, &fileHeader, sizeof( BITMAPFILEHEADER ), &written, NULL ); - WriteFile( hBitmapFile, &infoHeader, sizeof( BITMAPINFOHEADER ), &written, NULL ); - WriteFile( hBitmapFile, pixelData, infoHeader.biSizeImage, &written, NULL ); + WriteFile( hBitmapFile, &infoHeader, sizeof( BITMAPINFOHEADER ), &written, NULL ); + WriteFile( hBitmapFile, pixelData, infoHeader.biSizeImage, &written, NULL ); - CloseHandle( hBitmapFile ); + CloseHandle( hBitmapFile ); free( pixelData ); #else // !__LINUX__ #endif // __LINUX__ @@ -1227,16 +1230,11 @@ void OGL_ReadScreen( void **dest, long *width, long *height ) *height = OGL.height; *dest = malloc( OGL.height * OGL.width * 3 ); - if (*dest == 0) + if (*dest == NULL) return; - GLint oldMode; - glGetIntegerv( GL_READ_BUFFER, &oldMode ); glReadBuffer( GL_FRONT ); -// glReadBuffer( GL_BACK ); - glReadPixels( 0, 0, OGL.width, OGL.height, - GL_BGR, GL_UNSIGNED_BYTE, *dest ); - glReadBuffer( oldMode ); + glReadPixels( 0, OGL.heightOffset, OGL.width, OGL.height, GL_BGR_EXT, GL_UNSIGNED_BYTE, *dest ); } #ifdef __LINUX__ diff --git a/OpenGL.h b/OpenGL.h index c6dc602e..0a1f6d11 100644 --- a/OpenGL.h +++ b/OpenGL.h @@ -89,6 +89,7 @@ struct GLInfo fbFBO, fbFBOEXT } framebuffer_mode; + bool captureScreen; }; extern GLInfo OGL; diff --git a/VI.cpp b/VI.cpp index f409c56a..024eb8b0 100644 --- a/VI.cpp +++ b/VI.cpp @@ -37,6 +37,11 @@ void VI_UpdateScreen() { glFinish(); + if (OGL.captureScreen) { + OGL_SaveScreenshot(); + OGL.captureScreen = false; + } + if (OGL.frameBufferTextures) { //FrameBuffer *current = FrameBuffer_FindBuffer( *REG.VI_ORIGIN );