@@ -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
812831mxImage *GlWindow::readBmpFromBuffer (const byte * buffer, size_t size)
0 commit comments