View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update | 
|---|---|---|---|---|---|
| 0003255 | The Dark Mod | Graphics | public | 19.10.2012 10:34 | 28.04.2014 20:08 | 
| Reporter | grayman | Assigned To | taaaki | ||
| Priority | normal | Severity | normal | Reproducibility | always | 
| Status | resolved | Resolution | fixed | ||
| Product Version | TDM 1.08 | ||||
| Summary | 0003255: Savegame images are written wrong at high resolutions | ||||
| Description | At high screen resolutions, the savegame images are skewed to the right. See this thread: http://forums.thedarkmod.com/topic/14198-108-savegame-pics-skewed/page__view__findpost__p__298023 | ||||
| Tags | No tags attached. | ||||
| Attached Files |  3255.patch (1,702 bytes)   
 Index: renderer/RenderSystem.cpp
===================================================================
--- renderer/RenderSystem.cpp	(revision 5859)
+++ renderer/RenderSystem.cpp	(working copy)
@@ -965,19 +965,30 @@ void idRenderSystemLocal::CaptureRenderToFile( const char *fileName, bool fixAlp
 
 	qglReadBuffer( GL_BACK );
 
-	// include extra space for OpenGL padding to word boundaries
-	int	c = ( rc->width + 3 ) * rc->height;
-	byte *data = (byte *)R_StaticAlloc( c * 3 );
+	// calculate pitch of buffer that will be returned by qglReadPixels()
+	int alignment;
+	glGetIntegerv(GL_PACK_ALIGNMENT, &alignment);
+
+	int pitch = rc->width * 4 + alignment - 1;
+	pitch = pitch - pitch % alignment;
+
+	byte *data = (byte *)R_StaticAlloc( pitch * rc->height );
 	
-	qglReadPixels( rc->x, rc->y, rc->width, rc->height, GL_RGB, GL_UNSIGNED_BYTE, data ); 
+	// GL_RGBA/GL_UNSIGNED_BYTE seems to be the safest option
+	qglReadPixels( rc->x, rc->y, rc->width, rc->height, GL_RGBA, GL_UNSIGNED_BYTE, data );
 
-	byte *data2 = (byte *)R_StaticAlloc( c * 4 );
+	byte *data2 = (byte *)R_StaticAlloc( rc->width * rc->height * 4 );
 
-	for ( int i = 0 ; i < c ; i++ ) {
-		data2[ i * 4 ] = data[ i * 3 ];
-		data2[ i * 4 + 1 ] = data[ i * 3 + 1 ];
-		data2[ i * 4 + 2 ] = data[ i * 3 + 2 ];
-		data2[ i * 4 + 3 ] = 0xff;
+	for ( int y = 0 ; y < rc->height ; y++ ) {
+		for ( int x = 0 ; x < rc->width ; x++ ) {
+			int idx = y * pitch + x * 4;
+			int idx2 = (y * rc->width + x) * 4;
+
+			data2[ idx2 + 0 ] = data[ idx + 0 ];
+			data2[ idx2 + 1 ] = data[ idx + 1 ];
+			data2[ idx2 + 2 ] = data[ idx + 2 ];
+			data2[ idx2 + 3 ] = 0xff;
+		}
 	}
 
 	R_WriteTGA( fileName, data2, rc->width, rc->height, true );
 | ||||
| This is a trivial bug in idRenderSystemLocal::CaptureRenderToFile(). This function does not properly handle pitch of buffer returned from glReadPixels(). I'll try and prepare a patch for it. | |
| I've prepared a patch. Unfortunately calculating proper pitch was not enough. On my graphics card (ATI Radeon HD 5700, Catalyst 12.10) artifacts appeared (white line on 3255.png). Changing pixel format from GL_RGB to GL_RGBA fixed the problem. GL_RGBA should work universally. | |
| Since this issue isn't in the list of things targeted for a fix in 2.00, I posted a question on the 2.00 test thread about whether to add it or have it wait for 2.01. Awaiting comments. Thanks for looking at this. | |
| Zbyl's patch applied in src revision 5912. Tested on both Windows and Linux and it appears to work for 16:9 setups. Thanks Zbyl :) | |
| Going to assume that this has been resolved for everyone. | |
| Date Modified | Username | Field | Change | 
|---|---|---|---|
| 19.10.2012 10:34 | grayman | New Issue | |
| 23.07.2013 20:30 | grayman | Relationship added | has duplicate 0003460 | 
| 17.08.2013 15:15 | Zbyl | Note Added: 0006034 | |
| 18.08.2013 15:40 | Zbyl | File Added: 3255.patch | |
| 18.08.2013 15:49 | Zbyl | File Added: 3255.png | |
| 18.08.2013 15:50 | Zbyl | Note Added: 0006046 | |
| 18.08.2013 16:38 | grayman | Note Added: 0006049 | |
| 01.12.2013 17:05 | taaaki | Note Added: 0006303 | |
| 01.12.2013 17:05 | taaaki | Assigned To | => taaaki | 
| 01.12.2013 17:05 | taaaki | Status | new => feedback | 
| 28.04.2014 20:08 | taaaki | Note Added: 0006571 | |
| 28.04.2014 20:08 | taaaki | Status | feedback => resolved | 
| 28.04.2014 20:08 | taaaki | Resolution | open => fixed | 

