mirror of
https://github.com/blawar/GLideN64.git
synced 2024-06-25 22:09:35 +00:00
Implement SaveScreenshot()
This commit is contained in:
parent
5ba23b5c3e
commit
86d9f790cf
35
GLideNUI/ScreenShot.cpp
Normal file
35
GLideNUI/ScreenShot.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QImage>
|
||||
#include <QImageWriter>
|
||||
#include "GLideNUI.h"
|
||||
|
||||
#include "../Config.h"
|
||||
|
||||
EXPORT void CALL SaveScreenshot(const char * _folder, const char * _name, int _width, int _height, const unsigned char * _data)
|
||||
{
|
||||
const char * png = "png";
|
||||
const char * jpg = "jpg";
|
||||
const char * fileExt = config.texture.screenShotFormat == 0 ? png : jpg;
|
||||
QString romName(_name);
|
||||
romName = romName.replace(' ', '_');
|
||||
romName = romName.replace(':', ';');
|
||||
QString folderName(_folder);
|
||||
QDir folder;
|
||||
if (!folder.exists(folderName) && !folder.mkpath(folderName))
|
||||
return;
|
||||
|
||||
QString fileName;
|
||||
int i;
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
fileName = fileName.sprintf("%lsGLideN64_%ls_%03i.%s", folderName.data(), romName.data(), i, fileExt);
|
||||
QFile f(fileName);
|
||||
if (!f.exists())
|
||||
break;
|
||||
}
|
||||
if (i == 1000)
|
||||
return;
|
||||
QImage image(_data, _width, _height, QImage::Format_RGB888);
|
||||
QImageWriter writer(fileName, fileExt);
|
||||
writer.write(image.mirrored());
|
||||
}
|
|
@ -37,6 +37,7 @@ void loadSettings()
|
|||
config.texture.maxAnisotropy = settings.value("maxAnisotropy", 0).toInt();
|
||||
config.texture.forceBilinear = settings.value("forceBilinear", 0).toInt();
|
||||
config.texture.maxBytes = settings.value("maxBytes", 500 * gc_uMegabyte).toInt();
|
||||
config.texture.screenShotFormat = settings.value("screenShotFormat", 0).toInt();
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup("generalEmulation");
|
||||
|
@ -120,6 +121,7 @@ void writeSettings()
|
|||
settings.setValue("maxAnisotropy", config.texture.maxAnisotropy);
|
||||
settings.setValue("forceBilinear", config.texture.forceBilinear);
|
||||
settings.setValue("maxBytes", config.texture.maxBytes);
|
||||
settings.setValue("screenShotFormat", config.texture.screenShotFormat);
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup("generalEmulation");
|
||||
|
|
|
@ -15,6 +15,7 @@ extern "C" {
|
|||
|
||||
EXPORT int CALL RunConfig();
|
||||
EXPORT void CALL LoadConfig();
|
||||
EXPORT void CALL SaveScreenshot(const char * _folder, const char * _name, int _width, int _height, const unsigned char * _data);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ SOURCES += \
|
|||
ConfigDialog.cpp \
|
||||
GLideNUI.cpp \
|
||||
FullscreenResolutions_windows.cpp \
|
||||
Settings.cpp
|
||||
Settings.cpp \
|
||||
ScreenShot.cpp
|
||||
|
||||
HEADERS += \
|
||||
ConfigDialog.h \
|
||||
|
|
|
@ -134,6 +134,7 @@
|
|||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GLideNUI.cpp" />
|
||||
<ClCompile Include="ScreenShot.cpp" />
|
||||
<ClCompile Include="Settings.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -65,6 +65,9 @@
|
|||
<ClCompile Include="Settings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ScreenShot.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="ConfigDialog.h">
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "../RSP.h"
|
||||
#include "../Textures.h"
|
||||
#include "../OpenGL.h"
|
||||
#include "../GLideNUI/glidenui.h"
|
||||
#include "../GLideNUI/GLideNUI.h"
|
||||
|
||||
Config config;
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "../GLideN64.h"
|
||||
#include "../Config.h"
|
||||
#include "../OpenGL.h"
|
||||
#include "../RSP.h"
|
||||
#include "../GLideNUI/GLideNUI.h"
|
||||
|
||||
class OGLVideoWindows : public OGLVideo
|
||||
{
|
||||
|
@ -112,57 +114,14 @@ void OGLVideoWindows::_swapBuffers()
|
|||
|
||||
void OGLVideoWindows::_saveScreenshot()
|
||||
{
|
||||
BITMAPFILEHEADER fileHeader;
|
||||
BITMAPINFOHEADER infoHeader;
|
||||
HANDLE hBitmapFile;
|
||||
|
||||
char *pixelData = (char*)malloc(m_screenWidth * m_screenHeight * 3);
|
||||
|
||||
unsigned char *pixelData = (unsigned char*)malloc(m_screenWidth * m_screenHeight * 3);
|
||||
GLint oldMode;
|
||||
glGetIntegerv( GL_READ_BUFFER, &oldMode );
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glReadBuffer( GL_FRONT );
|
||||
glReadPixels(0, m_heightOffset, m_screenWidth, m_screenHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, pixelData);
|
||||
glReadPixels(0, m_heightOffset, m_screenWidth, m_screenHeight, GL_RGB, GL_UNSIGNED_BYTE, pixelData);
|
||||
glReadBuffer( oldMode );
|
||||
|
||||
infoHeader.biSize = sizeof( BITMAPINFOHEADER );
|
||||
infoHeader.biWidth = m_screenWidth;
|
||||
infoHeader.biHeight = m_screenHeight;
|
||||
infoHeader.biPlanes = 1;
|
||||
infoHeader.biBitCount = 24;
|
||||
infoHeader.biCompression = BI_RGB;
|
||||
infoHeader.biSizeImage = m_screenWidth * m_screenHeight * 3;
|
||||
infoHeader.biXPelsPerMeter = 0;
|
||||
infoHeader.biYPelsPerMeter = 0;
|
||||
infoHeader.biClrUsed = 0;
|
||||
infoHeader.biClrImportant = 0;
|
||||
|
||||
fileHeader.bfType = 19778;
|
||||
fileHeader.bfSize = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER ) + infoHeader.biSizeImage;
|
||||
fileHeader.bfReserved1 = fileHeader.bfReserved2 = 0;
|
||||
fileHeader.bfOffBits = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER );
|
||||
|
||||
char filename[256];
|
||||
|
||||
CreateDirectory( m_strScreenDirectory, NULL );
|
||||
|
||||
int i = 0;
|
||||
do {
|
||||
sprintf(filename, "%sscreen%02i.bmp", m_strScreenDirectory, i++);
|
||||
|
||||
if (i > 99)
|
||||
return;
|
||||
|
||||
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 );
|
||||
|
||||
CloseHandle( hBitmapFile );
|
||||
SaveScreenshot(m_strScreenDirectory, RSP.romname, m_screenWidth, m_screenHeight, pixelData);
|
||||
free( pixelData );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user