Skip to content

Commit d09cb4a

Browse files
committed
utils: pxmv: moved screenshots to imagelib
Also makes possible to do screenshots with alpha-channel
1 parent 51269b8 commit d09cb4a

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

utils/pxmv/GlWindow.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -792,21 +792,40 @@ void GlWindow :: dumpViewport( const char *filename )
792792
int w = w2();
793793
int h = h2();
794794

795-
mxImage *image = (mxImage *)Mem_Alloc(sizeof(mxImage));
796-
new (image) mxImage();
795+
rgbdata_t *image = Image_Alloc( w, h, false );
797796

798-
if (image && image->create( w, h, 24 ))
799-
{
800-
glReadBuffer( GL_FRONT );
801-
glReadPixels( 0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, image->data );
797+
if (!image)
798+
return;
802799

803-
image->flip_vertical();
800+
byte *glPixelData = (byte*)Mem_Alloc(w * h * 4);
801+
if (!glPixelData)
802+
{
803+
Image_Free(image);
804+
return;
805+
}
804806

805-
if (!mxBmpWrite( filename, image ))
806-
mxMessageBox( this, "Error writing screenshot.", APP_TITLE_STR, MX_MB_OK|MX_MB_ERROR );
807+
image->flags |= IMAGE_HAS_8BIT_ALPHA;
808+
glReadBuffer( GL_FRONT );
809+
glReadPixels( 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, glPixelData);
807810

808-
Mem_Free(image);
811+
byte *imagePixel = image->buffer;
812+
for (int y = h - 1; y > 0; y--)
813+
{
814+
byte *in = glPixelData + (y * w * 4);
815+
byte *rowend = in + (w * 4);
816+
for (; in < rowend; in+=4)
817+
{
818+
*imagePixel++ = in[0];
819+
*imagePixel++ = in[1];
820+
*imagePixel++ = in[2];
821+
*imagePixel++ = in[3];
822+
}
809823
}
824+
825+
if (!COM_SaveImage(filename, image))
826+
mxMessageBox( this, "Error writing screenshot.", APP_TITLE_STR, MX_MB_OK|MX_MB_ERROR );
827+
828+
Image_Free(image);
810829
}
811830

812831
mxImage *GlWindow::readBmpFromBuffer(const byte * buffer, size_t size)

utils/pxmv/mdlviewer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,9 @@ MDLViewer::handleEvent (mxEvent *event)
589589

590590
case IDC_OPTIONS_MAKESCREENSHOT:
591591
{
592-
char *ptr = (char *)mxGetSaveFileName( this, "", "Windows Bitmap (*.bmp)" );
592+
char *ptr = (char *)mxGetSaveFileName( this, "", "Any supported format (*.bmp; *.tga; *.dds; *.png)", "test.png", "png");
593593
if( ptr )
594594
{
595-
if( !strstr( ptr, ".bmp" ))
596-
strcat( ptr, ".bmp" );
597595
d_GlWindow->dumpViewport( ptr );
598596
}
599597
}

0 commit comments

Comments
 (0)