Skip to content

Commit 4aa886c

Browse files
committed
utils: pxmv: screenshot feature code refactoring
1 parent 2cb1f2c commit 4aa886c

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

utils/pxmv/GlWindow.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,21 +797,21 @@ void GlWindow :: dumpViewport( const char *filename )
797797
if (!image)
798798
return;
799799

800-
byte *glPixelData = (byte*)Mem_Alloc(w * h * 4);
801-
if (!glPixelData)
800+
byte *framebufferData = static_cast<byte*>(Mem_Alloc(w * h * 4));
801+
if (!framebufferData)
802802
{
803803
Image_Free(image);
804804
return;
805805
}
806806

807807
image->flags |= IMAGE_HAS_8BIT_ALPHA;
808-
glReadBuffer( GL_FRONT );
809-
glReadPixels( 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, glPixelData);
808+
glReadBuffer(GL_FRONT);
809+
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, framebufferData);
810810

811811
byte *imagePixel = image->buffer;
812812
for (int y = h - 1; y > 0; y--)
813813
{
814-
byte *in = glPixelData + (y * w * 4);
814+
byte *in = framebufferData + (y * w * 4);
815815
byte *rowend = in + (w * 4);
816816
for (; in < rowend; in+=4)
817817
{
@@ -823,7 +823,7 @@ void GlWindow :: dumpViewport( const char *filename )
823823
}
824824

825825
if (!COM_SaveImage(filename, image))
826-
mxMessageBox( this, "Error writing screenshot.", APP_TITLE_STR, MX_MB_OK|MX_MB_ERROR );
826+
mxMessageBox( this, "Failed to save screenshot file. Try to change file name.", APP_TITLE_STR, MX_MB_OK|MX_MB_ERROR );
827827

828828
Image_Free(image);
829829
}

utils/pxmv/mdlviewer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,14 @@ MDLViewer::handleEvent (mxEvent *event)
590590

591591
case IDC_OPTIONS_MAKESCREENSHOT:
592592
{
593-
std::time_t currTime = std::time(nullptr);
594-
char screenshotName[std::size("pxmv_yyyy-mm-dd_hh-mm-ss.png")];
595-
std::strftime(screenshotName, sizeof(screenshotName), "pxmv_%F_%H-%M-%S.png", std::gmtime(&currTime));
596-
char *ptr = (char *)mxGetSaveFileName( this, screenshotName, "Any supported format (*.bmp; *.tga; *.dds; *.png)");
597-
if( ptr )
593+
std::array<char, 128> nameBuffer;
594+
std::time_t currentTime = std::time(nullptr);
595+
std::strftime(nameBuffer.data(), nameBuffer.size(), "pxmv_%F_%H-%M-%S.png", std::gmtime(&currentTime));
596+
const char *fileName = (char *)mxGetSaveFileName( this, nameBuffer.data(), "Any supported format (*.bmp; *.tga; *.dds; *.png)");
597+
598+
if (fileName)
598599
{
599-
d_GlWindow->dumpViewport( ptr );
600+
d_GlWindow->dumpViewport(fileName);
600601
}
601602
}
602603
break;

0 commit comments

Comments
 (0)